Page 1 of 1

FAT32 and MBR-Partitioned Disk Questions

Posted: Sun Jul 10, 2016 9:20 am
by ScropTheOSAdventurer
I have been working on having my FAT32 based bootloader support partitioned disks instead of just the partitionless FAT32 disk image I had been using prior. It proved to be problematic when I had trouble just finding a tool that could automatically create a partitioned disk image and manipulate it as necessary (flag partitions as bootable, manipulate a raw partition image, format a partition, etc.). I settled on guestfish, but I keep having problems with that too.

Their built-in partition formatting options at best let me use mkfs.vfat with FAT16 formatting (at least by looking at the hex editor), when I want to do FAT32. I then decided to run "mkfs.vfat -F 32 -h HIDDENSECTORS" on the raw partition image that I extracted from the disk image. I calculated HIDDENSECTORS by taking the number of sectors I specified for the disk image and subtracting "du -k $(PARTITIONIMG) --block-size=512" from it. However, it keeps overestimating the number of hidden sectors to the point that I have to manually fix it by hex editor.

Also, their part-set-bootable option, which is supposed to mark a partition as bootable, doesn't seem to work as advertised, forcing me to mark my FAT32 boot partition as bootable via hex editor.

I have found short-term solutions to all of these problems for the meantime, but I have two questions. First, is there any reason that you know of that my method of figuring out hidden sectors may overestimate the number of them? Second, does anyone have any suggestions for what tools to use for manipulating MBR disks?

Re: FAT32 and MBR-Partitioned Disk Questions

Posted: Sun Jul 10, 2016 5:13 pm
by Octocontrabass
It sounds like you're using Linux. Create a reasonably-sized file with dd, mount it as a loopback device, and manipulate the loopback device the same way you would a real disk. (You may need to use partprobe to update the /dev/loop#p# devices after partitioning.)

Re: FAT32 and MBR-Partitioned Disk Questions

Posted: Sun Jul 10, 2016 8:30 pm
by ScropTheOSAdventurer
Oh, yeah; that is what I was originally doing with my non-partitioned FAT disk, but it bothered me that I had to use sudo. Should have mentioned that earlier.

Re: FAT32 and MBR-Partitioned Disk Questions

Posted: Mon Jul 11, 2016 6:07 am
by Octocontrabass
In that case, create a reasonably-sized file with dd, partition and format it with parted, and add files to it using mcopy (from mtools).

Re: FAT32 and MBR-Partitioned Disk Questions

Posted: Mon Jul 11, 2016 6:33 am
by iansjack
ScropTheOSAdventurer wrote:it bothered me that I had to use sudo
Why did/does that bother you?

Re: FAT32 and MBR-Partitioned Disk Questions

Posted: Mon Jul 11, 2016 8:30 am
by ScropTheOSAdventurer
How did I forget about mcopy? My memory is like a goldfish's.

The reason I dislike using sudo is because it seems so unnecessary. I shouldn't have to get root access just to manipulate a disk image.

Thanks for reminding me of mcopy!

Re: FAT32 and MBR-Partitioned Disk Questions

Posted: Mon Jul 11, 2016 9:14 am
by iansjack
sudo is not the same as granting root access.

But anyway, you have found an acceptable solution so all is well.

Re: FAT32 and MBR-Partitioned Disk Questions

Posted: Mon Jul 11, 2016 9:50 am
by ScropTheOSAdventurer
I know it isn't the same as actually BEING root, but it still gets me admin for the moment. I am not ignorant in that regard. It just seems all unnecessary to me.

Anyways, thanks for reminding me about mtools guys. It is so convenient.