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$