Page 1 of 1
How to read the fat32 bootsector info from image file
Posted: Sun May 01, 2022 1:40 am
by michael
I'm now trying to read the disk boot sector info. I compiled my kernel into a floppy and load it into qemu using -fda a.img, and I also created another qcow image file called disk.img and load into qemu using -hda disk.img. When I try to get boot sector info from LBA 0x00 I could only get all 0 in that sector. After that I format the qcow image file into fat32 using
and load it into qemu, but qemu then print
Code: Select all
Booting from Hard Disk
This is not a bootable disk. Please insert a bootable floppy and press any key to try again
The parameters I add to qemu is this
Code: Select all
QemuParameter := -cpu Nehalem,+x2apic -m 512 \
-enable-kvm -D ./log.txt -s -S -fda a.img -smp cores=$(APUNUM) -hda disk.img
a.img is the image file contains a bootloader and kernel
I'm now wondering how could I read the fat32 boot sector info properly
Re: How to read the fat32 bootsector info from image file
Posted: Sun May 01, 2022 8:50 am
by Octocontrabass
michael wrote:I also created another qcow image file called disk.img and load into qemu using -hda disk.img. When I try to get boot sector info from LBA 0x00 I could only get all 0 in that sector.
You created a blank disk image. It does not have a boot sector because it is blank.
michael wrote:After that I format the qcow image file into fat32 using
The mkfs.vfat program doesn't understand qcow. You should use raw disk images instead. Also, hard disks are typically partitioned, but mkfs.vfat does not partition the disk.
michael wrote:but qemu then print
Code: Select all
Booting from Hard Disk
This is not a bootable disk. Please insert a bootable floppy and press any key to try again
This message is displayed when you boot from a disk that has been formatted using mkfs.vfat. By default, QEMU attempts to boot from the hard disk before the floppy disk. If you want to boot from the floppy disk instead, add "-boot order=a" to your QEMU command line.
Re: How to read the fat32 bootsector info from image file
Posted: Sun May 01, 2022 5:17 pm
by michael
Octocontrabass wrote:
The mkfs.vfat program doesn't understand qcow. You should use raw disk images instead. Also, hard disks are typically partitioned, but mkfs.vfat does not partition the disk.
I've just created a primary partition inside a raw image file, do you know how to format that partition into fat32?
Re: How to read the fat32 bootsector info from image file
Posted: Sun May 01, 2022 5:50 pm
by Ethin
There are a few ways of doing it (e.g. you could do it by booting a Linux OS and then partition/format it in there), but another good way (on Linux) is to use qemu-nbd:
Code: Select all
modprobe nbd
qemu-nbd -c /dev/nbd0 image_file
Then, interact with /dev/nbd0 like you would a normal disk. Once done:
This works over the network, too, but its faster on Linux. Don't forget to load the nbd module (or load it at boot). You could also create a loopback device pointing to your image file, but qemu-nbd is significantly easier. It also has the advantage that, by default, it creates 16 NBD devices for you, so you can have up to 16 disks mounted simultaneously. If you need more (or you want more than 16 partitions, the default maximum), you can specify the any or both of the nbds_max or max_part module parameters in the modprobe command.