Page 1 of 1
Formatting QEMU HDD image as FAT
Posted: Mon May 01, 2017 9:40 am
by codyd51
Hello,
I'm emulating my OS in QEMU and want to test my ATA driver. I created a virtual hard disk image with
Code: Select all
qemu-img create -f raw drive.img 2G
I would like to format this drive as FAT. Is there a utility to format a QEMU virtual drive as FAT, or am I expected to hand-write the MBR, boot record, etc. myself?
Thanks!
Re: Formatting QEMU HDD image as FAT
Posted: Mon May 01, 2017 10:15 am
by mallard
You can use GNU parted to create the MBR and partition table ("parted drive.img").
Formatting it using native Linux tools will require attaching the image as block device using "kpartx" ("kpartx -a -v drive.img") and then doing something like "mkfs.vfat /dev/mapper/loop0p1". Since this requires root access, I'd suggest making a (possibly compressed) copy of the "empty" image at this point to use as a starting point in future (especially if you're "creating" the image as part of your build system, using root access as part of a build is a bad idea). mtools can be used to copy data to/from a FAT filesystem in a disk image without root access, but unfortunately can't be used to create one.