Booting ISO

09 Aug 2013

I have always liked playing with operating systems and hardware near technologies and in this note I will show how you can create an iso file which you can boot from.

First we need to download the bootloader that we want to use. I have chosen to use the isolinux bootloader since it is very easy to use for my purpose. The isolinux bootloader is part of the syslinux project. You can also use other bootloaders like grub or lilo.

tar xvf syslinux-6.01.tar.xz
cd syslinux-6.01

Next we need to build the syslinux package to get the necessary components for installing isolinux on an iso image.

make bios installer

Next we need to create a directory tree where we put all our files needed for booting.

mkdir -p cd-root/isolinux

Now we need to copy the necessary files from syslinux into our directory tree. The files we need are isolinux.bin which is the actual bootloader and ldlinux.c32 which contains files that the bootloader needs.

cp syslinux-6.01/bios/core/isolinux.bin \
   syslinux-6.01/bios/com32/elflink/ldlinux/ldlinux.c32 \

Previous versions of syslinux did not need the ldlinux.c32 file but the most recent one does. We also need to provide our own kernel. I prefer to use a kernel where I have embedded an initramfs filesystem, this is to minimize the points of failure. You can basically use any kernel that you want.

cp linux-3.10.5/arch/x86/boot/bzImage cd-root/isolinux

The last file we need is a configuration file. We basically need to tell syslinux where to locate our kernel

nano cd-root/isolinux/isolinux.cfg

The content of this file should be this:

default kjetilos
timeout 0

LABEL kjetilos
  KERNEL bzImage

Now that we have the content of our iso file we need to create the actual iso file. We will be using mkisofs for this task.

mkisofs -o bootable-cd.iso \
        -b isolinux/isolinux.bin \
        -c isolinux/ \
        -no-emul-boot \
        -boot-load-size 4 \
        -boot-info-table  \

From the man pages of mkisofs we can see that -b tells mkisofs where the boot image is, and tells it to create an "El Torito" bootable iso image for x86. -c tells mkisofs where to create the boot catalog file which is required for "El Torito" bootable iso images. -no-emul-boot tells mkisofs that the boot image provided is not a floppy drive image so there is no need to emulate a floppy drive when booting with the provided image. -boot-load-size 4 specifies how many sectors of 512-bytes that should be loaded when loading the boot image. -boot-info-table tells mkisofs to insert a 56-bytes information table.

Congratulations now you have a bootable iso file with your own kernel. You are amazing! If you want to test this iso file on your own machine you can use an emulator like qemu or VirtualBox or you can burn a cd and try to boot from that. I prefer using the emulator since it's the quickest way to test if it works.

qemu-system-x86_64 --cdrom bootable-cd.iso