Creating a bootable ISO image with custom bootloader

It appears you found your example for creating a bootable ISO image from this StackOverflow Answer. Unfortunately you picked an accepted answer that is incorrect in many ways. Pretend you never saw that answer.

On most Linux distros either a program called genisoimage or mkisofs exists. These days they are actually the same program. Whichever you have can be substituted in the examples below. My examples will assume the ISO creation utility is called genisoimage.


In your question you have some bootloader code in a file called boot.asm. You correctly assemble this to a boot sector binary image with:

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

This creates boot.bin which is your boot sector. The next step is to create a floppy disk image and place boot.bin in the first sector. You can do that with this:

dd if=/dev/zero of=floppy.img bs=1024 count=1440
dd if=boot.bin of=floppy.img seek=0 count=1 conv=notrunc

The first command simply makes a zero filled disk image equal to the size of a 1.44MB floppy (1024*1440 bytes). The second command places boot.bin into the first sector of floppy.img without truncating the rest of the file. seek=0 says seek to first sector (512 bytes is default size of a block for DD). count=1 specifies we only want to copy 1 sector (512 bytes) from boot.bin. conv=notrunc says that after writing to the output file, that the remaining disk image is to remain intact (not truncated).


After building a disk image as shown above, you can create an ISO image with these commands:

mkdir iso
cp floppy.img iso/
genisoimage -quiet -V 'MYOS' -input-charset iso8859-1 -o myos.iso -b floppy.img \
    -hide floppy.img iso/

The commands above first create a sub-directory called iso that will contain the files to be placed onto the final CD-ROM image. The second command doesn’t do anything more than copy our floppy.img into iso directory because we need that for booting. The third command does the heavy lifting and builds the ISO image.

  • -V 'MYOS' sets the volume label (It can be whatever you want)
  • -input-charset iso8859-1 sets the character set being used. Don’t change it
  • -o myos.iso says the ISO image will be output to the file myos.iso
  • -b floppy.img says that our ISO will be bootable and the boot image being used is the file floppy.img
  • -hide floppy.img isn’t needed but it hides the boot image from the final ISO’s directory listing. If you were to mount this ISO and do an ls on it to list the files, floppy.img wouldn’t appear.
  • iso/ on the end of the command is the directory that will be used to build the ISO image from. It needs to at least contain our bootable floppy image, but you can place any other files you wish into the iso/ directory.

The ISO image myos.iso that is generated can be booted. An example of using QEMU to launch such an image:

qemu-system-i386 -cdrom ./myos.iso

Leave a Comment