Page 1 of 1

mformat creating disk image with bad partition table.

Posted: Wed Apr 06, 2022 6:46 pm
by CrashAndSideburns
Hey all,

I'm working on a simple bootloader, and I'm running into some issue with by build environment. To generate my bootable image, I have a Makefile that looks like

Code: Select all

all: target/bootloader target/disk.iso

target/bootloader:
	mkdir -p target
	nasm -o target/bootloader src/stage1.s
target/disk.iso: target/bootloader
	mformat -FC -i target/disk.iso -T 66581
	dd if=target/bootloader of=target/disk.iso bs=1 count=446 conv=notrunc
	dd if=target/bootloader of=target/disk.iso bs=1 count=2 skip=510 seek=510 conv=notrunc
but when my MBR attempts to read the LBA of the active partition from the partition table, it just reads 0's. I have checked a hexdump of the disk image, and the relevant bytes are indeed 0. I was under the impression that these bytes should give me the LBA of the boot record of the partition, so I'm not sure why it's 0 in the generated disk image. I have also checked the image generated before my MBR is copied in, in case I was somehow overwriting it, and the same problem exists. I'm not really sure what the issue is here. Is there some utility that I have to use in order to properly initialize the partition table? Is these bytes being 0 actually correct? If so, how do I know which sectors to load from disk to get the boot record of the active partition?

Re: mformat creating disk image with bad partition table.

Posted: Wed Apr 06, 2022 7:40 pm
by Octocontrabass
You're not creating any partitions. mformat only creates a filesystem, nothing else. If you want that filesystem to be a partition on the disk, you need to either manually assemble your disk image by partitioning it and copying the filesytem created by mformat into the partition, or mount your disk image as a loopback device and tell mformat to operate on the partition sub-device.

There may also be some utility that can more conveniently create a partitioned and formatted disk image for you, but I don't know of any off the top of my head.

Unrelated, but the ".iso" file extension implies you're creating an optical disc image. You should choose a different extension.