Hello world boot loader


What is a boot loader?

  • It is a piece of code that runs before any operating system is running.
  • Boot loaders are used to boot other operating systems, usually each operating system has a set of boot loaders specific for it.
  • Boot loaders usually contain several ways to boot the OS kernel and also contain commands for debugging and/or modifying the kernel environment.

In this blog, I am concentrating only on Linux boot loaders. I’m trying to implement a simple 16 bit “hello world” boot loader which runs in an infinite loop.

OS used : Kubuntu 12.04, 64 bit.

Installing all the essential packages

  • $ sudo apt-get install nasm build-essential
  • Installation of virtual box in Linux (Download  Oracle Virtualbox from here)

Create a Virtual Drive image

Lets create a virtual drive image to copy the boot loader in-order to save a physical storage medium. Our first task is to find a place where we can put our boot loader virtually which can be loaded into a Virtual machine later. We’ll use a virtual floppy disk to do so.

Create a virtual floppy disk

$ head -c 1474560 /dev/zero > bootloader.vfd

You’ll have an empty “1.44 MB” image.


This is the link to the code
compile the code using this step:

$ nasm -f bin -o OS.bin 1.asm

Copying the boot sector to virtual floppy drive

$ dd status=noxfer conv=notrunc if=OS.bin of=bootloader.vfd

This does a none-truncating move of the OS.bin into ‘bootloader.vfd’ (so it’s not blank anymore, its now got a boot loader installed), but the vfd file stays at a size of 1.44MB and the first 512 bytes of the file is overwritten with the bin file.

Running our code

Lets open up our Virtual machine. Create a new machine. Create a tiny virtual disk image of say 500 MB (minimum size of a VDI that can be created in a VM)

Adding a virtual floppy drive in Virtual box

Bootloader displaying “Hello World” message

Choose type as others and version as DOS Go to that VM’s settings->storage and select the virtual floppy disk that you have created. Now its time to boot and you can see this message printed!


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s