OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 4:27 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: How to read the fat32 bootsector info from image file
PostPosted: Sun May 01, 2022 1:40 am 
Offline

Joined: Fri Nov 12, 2021 1:09 am
Posts: 12
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
Code:
mkfs.vfat -F 32 -v disk.img

and load it into qemu, but qemu then print
Code:
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:
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


Top
 Profile  
 
 Post subject: Re: How to read the fat32 bootsector info from image file
PostPosted: Sun May 01, 2022 8:50 am 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5099
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
Code:
mkfs.vfat -F 32 -v disk.img

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:
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.


Top
 Profile  
 
 Post subject: Re: How to read the fat32 bootsector info from image file
PostPosted: Sun May 01, 2022 5:17 pm 
Offline

Joined: Fri Nov 12, 2021 1:09 am
Posts: 12
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?


Top
 Profile  
 
 Post subject: Re: How to read the fat32 bootsector info from image file
PostPosted: Sun May 01, 2022 5:50 pm 
Offline
Member
Member

Joined: Sun Jun 23, 2019 5:36 pm
Posts: 618
Location: North Dakota, United States
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:
modprobe nbd
qemu-nbd -c /dev/nbd0 image_file

Then, interact with /dev/nbd0 like you would a normal disk. Once done:
Code:
qemu-nbd -d /dev/nbd0

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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: DotBot [Bot], SemrushBot [Bot] and 64 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group