I am following the BrokenThorn tutorial about OS development.
Windows is used in the tutorial, but I decided to use Ubuntu, because the build process is better.
Until now, I only had the program for the Master Boot Record.
I used a bash script to build
nasm -f bin -o boot.bin boot.asm
dd status=noxfer conv=notrunc if=boot.bin of=boot.flp
qemu-system-i386 -fda boot.flpNow I am at a point where I want to load a second Stage bootloader. In the tutorial the floppy has a FAT12 filesystem. So I tried to adapt this in my build script
mkfs.vfat -F 12 ./boot.flp
sudo mount -o loop ./boot.flp /media/floppy1/
nasm -f bin -o STAGE2.SYS stage2.asm
sudo cp ./STAGE2.SYS /media/floppy1/
sudo umount /media/floppy1/
nasm -f bin -o boot.bin boot.asm
dd status=noxfer conv=notrunc if=boot.bin of=boot.flp
qemu-system-i386 -fda boot.flp The image still boots, but when I try open the image as a loop device, Ubuntu drops an error
mount: /media/floppy1: wrong fs type, bad option, bad superblock on /dev/loop16, missing codepage or helper program, or other error.
So I think that the FAT12 is corrupted.
How can I setup a working FAT12 floppy image with my own Master Boot Record?
2 Answers
Before creating file system, you have to partition the image and in your case to be a primary partition with bootable flag
1I solved the problem by adding the things from the bios parameter block as options to the mkfs.vfat command. It is not necessary to create a partition.
mkfs.vfat -F 12 ./boot.flp -f 2 -h 0 -i 0xa0a1a2a3 -I -n "NAME OF OS " -r 224 -R 1 -s 1 -S 512