So I am creating a custom bootloader:

nasm -f bin boot.asm -o boot.bin

It is 512 bytes. How do I place this into a floppy image and boot with qemu?

I tried:

dd if=boot.bin of=floppy.img bs=512 count=2880
dd if=floppy.img of=floppy2.img bs=512 count=1
qemu-system-i386 -fda floppy2.img

But the floppy2.img gets resized to 512 bytes instead of the normal size of 1.44MB. Is this the correct way? I would rather not use any fancy tools, if it can be done with dd, that would be great.


If the only problem is that the image file is too short, you could try appending 2879*512 zero bytes to the floppy.imgfile:

dd if=/dev/zero count=2879 bs=512 >> floppy.img

On the other hand, if you need to store somthing else than just the boot sector on the floppy image, you will have to create a FAT file system on it. The way to do this is to use a loop device.

sudo losetup /dev/loop0 floppy.img
sudo mkfs -t fat /dev/loop0
sudo mount /dev/loop0 somedir

where somedir is an empty directory where /dev/loop0 is mounted. You can now copy the needed files to this directory.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.