Trouble mounting partition on HDD image (wrong fs type)

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
PatSanf
Member
Member
Posts: 25
Joined: Mon Oct 13, 2014 6:39 pm

Trouble mounting partition on HDD image (wrong fs type)

Post by PatSanf »

Hello friends!

I'm trying to create a HDD image that I can use with QEMU to test my OS on. I've been running my OS off of a CD image, but I'm wanting to emulate a system with a hard drive so I can work on page swapping. My goal is to create a HDD image, format it with a FAT32 file system, install GRUB, and my OS then boot it in QEMU. I've tried following the directions here and here with poor results. I also searched the forum and found this thread.

I'm having trouble mounting the partition in my image file. I keep getting an error that either says "you must specify the filesystem type" or "wrong fs type, bad option, bad superblock on /dev/loop1, missing codepage or helper program, or other error In some cases useful info is found in syslog - try dmesg | tail or so". I think I'm calculating the offset for the loopback device incorrectly. I'm trying to create a 500MB HDD image, then using losetup /dev/loop# -o 1048576 to setup the loopback. What's the proper way to calculate the offset? I'm thinking it's needing to be far enough into the drive image to allow room for the MBR and GRUB. I'm using 1024^2 = 1048576 to reserve 1MB of space as per the GRUB2 article on the wiki. Am I writing my partition table in the wrong place when I run mkdosfs? Any help with this problem would be greatly appreciated.

Here's exactly what I'm attempting, and the result. I tried mounting a few different ways to make sure it wasn't an obvious issue with the CLI syntax.

Code: Select all

patrick@debian:/media/sf_Operating_System_Stuff/POS Attempts/POS_C9/build/disk$ su
Password: 
root@debian:/media/sf_Operating_System_Stuff/POS Attempts/POS_C9/build/disk# dd if=/dev/zero of=hdd.img bs=512 count=1048576
1048576+0 records in
1048576+0 records out
536870912 bytes (537 MB) copied, 351.488 s, 1.5 MB/s
root@debian:/media/sf_Operating_System_Stuff/POS Attempts/POS_C9/build/disk# fdisk hdd.img
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0xd70af297.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-1048575, default 2048): 
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-1048575, default 1048575): 
Using default value 1048575

Command (m for help): a
Partition number (1-4): 1

Command (m for help): p

Disk hdd.img: 536 MB, 536870912 bytes
255 heads, 63 sectors/track, 65 cylinders, total 1048576 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xd70af297

  Device Boot      Start         End      Blocks   Id  System
hdd.img1   *        2048     1048575      523264   83  Linux

Command (m for help): w
The partition table has been altered!

Syncing disks.
root@debian:/media/sf_Operating_System_Stuff/POS Attempts/POS_C9/build/disk# losetup /dev/loop0 hdd.img
root@debian:/media/sf_Operating_System_Stuff/POS Attempts/POS_C9/build/disk# losetup /dev/loop1 hdd.img -o 1048576
root@debian:/media/sf_Operating_System_Stuff/POS Attempts/POS_C9/build/disk# mkdosfs -F 32 /dev/loop1
mkdosfs 3.0.13 (30 Jun 2012)
Loop device does not match a floppy size, using default hd params
root@debian:/media/sf_Operating_System_Stuff/POS Attempts/POS_C9/build/disk# ls
hdd.img  mnt_pnt
root@debian:/media/sf_Operating_System_Stuff/POS Attempts/POS_C9/build/disk# mount /dev/loop1 mnt_pnt
mount: you must specify the filesystem type
root@debian:/media/sf_Operating_System_Stuff/POS Attempts/POS_C9/build/disk# mount -t vfat /dev/loop1 mnt_pnt
mount: wrong fs type, bad option, bad superblock on /dev/loop1,
       missing codepage or helper program, or other error
       In some cases useful info is found in syslog - try
       dmesg | tail  or so

root@debian:/media/sf_Operating_System_Stuff/POS Attempts/POS_C9/build/disk# mount /dev/loop1 /media/sf_Operating_System_Stuff/POS\ Attempts/POS_C9/build/disk/mnt_pnt/
mount: you must specify the filesystem type
root@debian:/media/sf_Operating_System_Stuff/POS Attempts/POS_C9/build/disk# mount -t vfat /dev/loop1 /media/sf_Operating_System_Stuff/POS\ Attempts/POS_C9/build/disk/mnt_pnt/
mount: wrong fs type, bad option, bad superblock on /dev/loop1,
       missing codepage or helper program, or other error
       In some cases useful info is found in syslog - try
       dmesg | tail  or so

root@debian:/media/sf_Operating_System_Stuff/POS Attempts/POS_C9/build/disk# losetup -d /dev/loop0
root@debian:/media/sf_Operating_System_Stuff/POS Attempts/POS_C9/build/disk# losetup -d /dev/loop1
root@debian:/media/sf_Operating_System_Stuff/POS Attempts/POS_C9/build/disk# exit
exit
patrick@debian:/media/sf_Operating_System_Stuff/POS Attempts/POS_C9/build/disk$ 
On a further note, I'm also wondering how I'll go about actually putting my kernel binary on the HDD image. Where should I write that? Do I simply copy my binary file into the partition once it's mounted? I doubt it's that easy! Will I need to use dd to copy the binary to a specific location in the image? What should I know to avoid writing over my FAT32 tables?
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Trouble mounting partition on HDD image (wrong fs type)

Post by Combuster »

Device Boot Start End Blocks Id System
hdd.img1 * 2048 1048575 523264 83 Linux
This is guaranteed to make the partition unreadable on any DOS/Windows based machines. fdisk provides all the info you need to change it.
mkdosfs -F 32 /dev/loop1
The FAT size depends on the number of clusters alone. Forcing a size is always wrong, if you need FAT32 for smaller disks, change the sectors per cluster count instead.
In some cases useful info is found in syslog - try
dmesg | tail or so
What did it say?
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
PatSanf
Member
Member
Posts: 25
Joined: Mon Oct 13, 2014 6:39 pm

Re: Trouble mounting partition on HDD image (wrong fs type)

Post by PatSanf »

This is guaranteed to make the partition unreadable on any DOS/Windows based machines. fdisk provides all the info you need to change it.
I'm not sure what I should be looking for. When I run fdisk I am not being given the option to create the partition at 512. If the information is available in the man page then I must be missing it. Is this something to do with the way I'm using dd to write the image?
The FAT size depends on the number of clusters alone. Forcing a size is always wrong, if you need FAT32 for smaller disks, change the sectors per cluster count instead.
I don't need FAT32. I'm wanting to use it for a beginners file system. Should I just omit the -F option?
What did it say?
I'm perfectly capable of reading, but I've never seen this error before, do not understand what this is telling me, and am seeking clarification from another person.
Octocontrabass
Member
Member
Posts: 5590
Joined: Mon Mar 25, 2013 7:01 pm

Re: Trouble mounting partition on HDD image (wrong fs type)

Post by Octocontrabass »

PatSanf wrote:I don't need FAT32. I'm wanting to use it for a beginners file system. Should I just omit the -F option?
The type of FAT is determined by the number of clusters. If you want FAT32, you must set the other parameters so that the filesystem ends up with at least 65,525 clusters. Using -F to override this behavior causes mkdosfs to produce an invalid filesystem, so you should never use the -F option.
PatSanf
Member
Member
Posts: 25
Joined: Mon Oct 13, 2014 6:39 pm

Re: Trouble mounting partition on HDD image (wrong fs type)

Post by PatSanf »

Octocontrabass wrote:
PatSanf wrote:I don't need FAT32. I'm wanting to use it for a beginners file system. Should I just omit the -F option?
The type of FAT is determined by the number of clusters. If you want FAT32, you must set the other parameters so that the filesystem ends up with at least 65,525 clusters. Using -F to override this behavior causes mkdosfs to produce an invalid filesystem, so you should never use the -F option.
This is a very helpful response. Thank you for taking the time to answer my question. This is information that I did not know, and had not come across. Do you happen to know the formula for calculating the number of clusters? Is it the number of sectors? After reading this page I'm getting an idea of what a cluster is, and am wondering if I can just limit my clusters to a sector to avoid further headaches. Will using 512 byte sectors/clusters cause me problems down the road?
User avatar
eryjus
Member
Member
Posts: 286
Joined: Fri Oct 21, 2011 9:47 pm
Libera.chat IRC: eryjus
Location: Tustin, CA USA

Re: Trouble mounting partition on HDD image (wrong fs type)

Post by eryjus »

Octocontrabass wrote:Do you happen to know the formula for calculating the number of clusters?
here you go
Adam

The name is fitting: Century Hobby OS -- At this rate, it's gonna take me that long!
Read about my mistakes and missteps with this iteration: Journal

"Sometimes things just don't make sense until you figure them out." -- Phil Stahlheber
Octocontrabass
Member
Member
Posts: 5590
Joined: Mon Mar 25, 2013 7:01 pm

Re: Trouble mounting partition on HDD image (wrong fs type)

Post by Octocontrabass »

PatSanf wrote:Do you happen to know the formula for calculating the number of clusters?
The number of clusters is (approximately) the number of sectors divided by the number of sectors per cluster. You'll actually end up with fewer than that due to the space taken by the FATs, since the FATs do not count towards the number of clusters.
PatSanf wrote:Will using 512 byte sectors/clusters cause me problems down the road?
You're limited to just under 128GB of usable space, it will hurt performance on 512e drives, and it won't work at all on 4Kn drives.
Nable
Member
Member
Posts: 453
Joined: Tue Nov 08, 2011 11:35 am

Re: Trouble mounting partition on HDD image (wrong fs type)

Post by Nable »

eryjus wrote:here you go
I think that link to wiki would be better:

Code: Select all

if(total_clusters < 4085) {
   fat_type = 12;
} else {
   if(total_clusters < 65525) {
      fat_type = 16;
   } else {
      fat_type = 32;
   }
}
see http://wiki.osdev.org/FAT#Reading_the_Boot_Sector -> "The FAT type of this file system (12, 16, or 32):" for details
Post Reply