FAT32 MBR and VBR

Discussions on more advanced topics such as monolithic vs micro-kernels, transactional memory models, and paging vs segmentation should go here. Use this forum to expand and improve the wiki!
Post Reply
mihe
Member
Member
Posts: 40
Joined: Sun Oct 21, 2018 1:37 pm

FAT32 MBR and VBR

Post by mihe »

Hello cloud of wisdom!,

I am bootsraping (for fun and to understand FAT32 format) my own disk image creation tools. Basically, create an empty file of 34MiB, create one partition from sector 2048 until end of image file, format it, and add some directories and files.

I am using as reference an example created using the commands below, and the documention on osdev, wikipedia, and the Microsoft specs documentation (two documents with different publishing date I found online):

Code: Select all

parted "$IMG_NAME" --script mklabel msdos
parted "$IMG_NAME" --script mkpart primary fat32 1MiB 100%
mformat -i hd34mbfat32.img@@1048576 -F ::
My questions are related to the Partition table on MBR (sector 0) and VBR (sector 2048 - 1MiB).

I see the tools above creates these entries the MBR, and VBR respectively:
00 00 01 10 0C 03 A0 1F 00 08 00 00 00 08 01 00 (33 MiB FAT32-LBA partition starting at LBA 2048. 67,584 Sectors)
80 00 01 00 0C 0F 3F 43 00 00 00 00 C0 0B 01 00 (bootable FAT32 partition allegedly starting at LBA 0. 68,544 Sectors)

* Why there is a partition entry on the VBR? I thought the MBR only contains the partition table.

* Why the MBR entry indicate non-bootable and then in the VBR the entry is bootable

* How the partition entry on the VBR has more sectors available than what is indicated on the MBR partition entry?


I have the impression I am missing something about how the partition tables work, but after carefully reviewing all documentation I am not able to guess it.

Thanks in advance!
Octocontrabass
Member
Member
Posts: 6245
Joined: Mon Mar 25, 2013 7:01 pm

Re: FAT32 MBR and VBR

Post by Octocontrabass »

mihe wrote: Tue Nov 18, 2025 9:55 am* Why there is a partition entry on the VBR? I thought the MBR only contains the partition table.
I can't think of any good reason. It's either a bug in mformat or a half-baked workaround in mformat for a bug somewhere else.
mihe wrote: Tue Nov 18, 2025 9:55 am* Why the MBR entry indicate non-bootable and then in the VBR the entry is bootable
You didn't tell parted to make the partition bootable, so it didn't. Presumably mformat always marks its nonsense partition as bootable.
mihe wrote: Tue Nov 18, 2025 9:55 am* How the partition entry on the VBR has more sectors available than what is indicated on the MBR partition entry?
This is a bug in mformat.

You may have better luck using dosfstools instead of mtools for creating the filesystem. Like so:

Code: Select all

mkfs.vfat -F 32 --offset 0x800 hd34mbfat32.img
Unfortunately dosfstools doesn't include any way to read or write files, since you're expected to use the host OS's filesystem driver for that part.
mihe
Member
Member
Posts: 40
Joined: Sun Oct 21, 2018 1:37 pm

Re: FAT32 MBR and VBR

Post by mihe »

Thanks Octocontrabass for the detailed response!.

I am going to switch the tools based on your recommendation and start over.

I will post an update with the differences to keep a written record, in case this helps someone else in the same situation.

Thanks!
kerravon
Member
Member
Posts: 372
Joined: Fri Nov 17, 2006 5:26 am

Re: FAT32 MBR and VBR

Post by kerravon »

Octocontrabass wrote: Tue Nov 18, 2025 12:24 pm Unfortunately dosfstools doesn't include any way to read or write files, since you're expected to use the host OS's filesystem driver for that part.
Robert has mcopy for that:

https://git.candlhat.org/?p=dosfstools.git;a=tree

And ... wow - I'm not being blocked by spamhaus anymore.
Post Reply