FAT 32 MBR Creation

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
User avatar
Schol-R-LEA
Member
Member
Posts: 1925
Joined: Fri Oct 27, 2006 9:42 am
Location: Athens, GA, USA

Re: FAT 32 MBR Creation

Post by Schol-R-LEA »

Octacone wrote:@Schol-R-LEA looks like you know a lot about old computers. It is always nice to learn some history along the way.
Thanks, although I should have done more fact-checking: my recollection to the contrary, the original IBM PC could have two full-height floppy drives. However, I am pretty sure that I was correct about it never booting from drive B:, though I am open to corrections.

Also, I once again forgot to specify which university abbreviated as 'SCSU' I was talking about; I meant Southern Connecticut State University, the CT State schools being the junior state university system to University of Connecticut's senior in the same way California State is to University of California.
Rev. First Speaker Schol-R-LEA;2 LCF ELF JAM POEE KoR KCO PPWMTF
Ordo OS Project
Lisp programmers tend to seem very odd to outsiders, just like anyone else who has had a religious experience they can't quite explain to others.
Octocontrabass
Member
Member
Posts: 5586
Joined: Mon Mar 25, 2013 7:01 pm

Re: FAT 32 MBR Creation

Post by Octocontrabass »

Octacone wrote:Mkdosfs doesn’t seem to care about fdisk partitioned virtual HDDs??
Utilities like mkdosfs expect to operate on a partition device when the disk is partitioned. You're telling mkdosfs to work directly with your entire disk image, which it isn't really prepared to handle.

Since you're using Linux, it's pretty easy to mount your disk image as separate partition devices. You can then use mkdosfs to format the individual partition devices, just like you would partitions on a physical disk.
User avatar
Octacone
Member
Member
Posts: 1138
Joined: Fri Aug 07, 2015 6:13 am

Re: FAT 32 MBR Creation

Post by Octacone »

@Octocontrabass
Okay so I started over. Created an empty HDD image with 2 partitions, 5 GB each, mounted EACH of them as a loopback device. Checked everything with a hex editor, everything seems to be okay. Now I have a problem, since both fdisk and this page Loopback_Device are outdated I cannot create a FAT 32 filesystem on them. Why, you ask? Because I don't know how many #blocks are there.
This line:

Code: Select all

mkdosfs -F32 /dev/loop0 #blocks
There is no way for me to figure that out and Wiki says I should. Any ideas on what that could be and how could I get that number? Google says one block = 1024 bytes but that doesn't make me know the value.

Edit: I figured out the formula:

Code: Select all

block_count = ((last_sector - first_sector) * 512) / 1024
OS: Basic OS
About: 32 Bit Monolithic Kernel Written in C++ and Assembly, Custom FAT 32 Bootloader
Octocontrabass
Member
Member
Posts: 5586
Joined: Mon Mar 25, 2013 7:01 pm

Re: FAT 32 MBR Creation

Post by Octocontrabass »

The wiki instructions expect you to do everything manually, which is quite stupid when automated solutions exist. That's why I directed you to this page describing how to automatically set up partition devices from a loop device.

If you mount your disk image following those instructions, you will see partition devices named similar to /dev/loop0p1 that can be treated exactly the same as any partition on a physical disk, including the format commands. You won't need to specify the number of blocks since the partition device will be the correct size.
User avatar
Octacone
Member
Member
Posts: 1138
Joined: Fri Aug 07, 2015 6:13 am

Re: FAT 32 MBR Creation

Post by Octacone »

Octocontrabass wrote:The wiki instructions expect you to do everything manually, which is quite stupid when automated solutions exist. That's why I directed you to this page describing how to automatically set up partition devices from a loop device.

If you mount your disk image following those instructions, you will see partition devices named similar to /dev/loop0p1 that can be treated exactly the same as any partition on a physical disk, including the format commands. You won't need to specify the number of blocks since the partition device will be the correct size.
I actually managed to mount both of them. I don't have any problems with that, anymore. Except they are not formatted correctly... again...
I will try to use your method and see if it works.

Edit:
Success!
I did everything as suggested and it worked. There are now two mounted and FAT 32 formatted partitions that I can access. Now I can finally start working on my bootloader without having to worry about this kind of stuff.
Is it normal for a hard drive with two partitions to contain 4 "FAT32 " signatures? Are those just FAT 32 specific backup tables?

For those who are interested here is my MBR:
HDD_MBR.png
and here is a table whose purpose I don't know. Is this a bios parameter block together with a file allocation table altogether forming a VBR? What are those 4 extra bytes after 55 AA (not in the picture, 52 52 61 41)?
https://i.imgur.com/PeHqMfR.png
OS: Basic OS
About: 32 Bit Monolithic Kernel Written in C++ and Assembly, Custom FAT 32 Bootloader
Octocontrabass
Member
Member
Posts: 5586
Joined: Mon Mar 25, 2013 7:01 pm

Re: FAT 32 MBR Creation

Post by Octocontrabass »

Now might be a good time to grab a copy of Microsoft's FAT filesystem specification and see if you can find the answers to your questions in it.

Here's a PDF copy of it.
Post Reply