Boot Loader and OS Kernel Startup

This is a homebrew x86 bootloader and "do nothing" kernel. Developed mostly as a learning exercise.

The key source files are:




Source Code on github

OS Development Notes

On-line Tutorials


I used qemu extensively for testing this software. It worked really well for this kind of development. The ability to connect to the emulation with GDB was especially useful.


Create Raw Disk Image

This sequence create a fake disk with the boot program to the first sector and the kernel program to the second sector. Essentially this is a raw disk with no filesystem. This fake disk is used to boot the qemu emulation for testing.

    dd if=/dev/zero of=drive.bin bs=512 count=16
    dd if=boot.bin of=drive.bin bs=512 conv=notrunc
    dd if=os.bin of=drive.bin bs=512 seek=1 conv=notrunc

This sequence creates a disk image with a ext filesystem. The bootloader installed on the first sector. Once this disk is mounted you could write files onto the image. (I never got this far)

dd if=/dev/zero of=disk.img bs=1024 count=1024
mkfs.ext disk.img
dd if=boot.bin of=disk.img
mount -o loop disk.img /mnt/virtual

Virtual Box Disk Swap

Generally I find this a royal pain and would recommend using qemu/kvm or another virtual system.

Assuming the VM already has an attached hard disk.

Remove the old disk file:

rm -rf drive.vdi

Convert the new binary disk file to VDI format

VBoxManage convertfromraw drive.bin drive.vdi --format VDI

Change the VM to have no disk file attached to the drive

VBoxManage storageattach boot --storagectl "IDE Controller" --port 0 --device 0 --type hdd --medium none

Have to be in the VMs directory so VBoxManage can find the disk file. We "close" it to remove it from VBoxs registry

cd /home/john/VirtualBox\ VMs/boot
VBoxManage closemedium disk /home/john/VirtualBox\ VMs/boot/drive.vdi

Move the new disk file into the VMs directory and attach it to the hard drive

cp /home/john/src/pc_boot/boot5/drive.vdi /home/john/VirtualBox\ VMs/boot/drive.vdi
VBoxManage storageattach boot --storagectl "IDE Controller" --port 0 --device 0 --type hdd --medium drive.vdi

Creating the Cross Compiler

Downloaded the source for gcc 4.9.2 and binutils 2.2.5 https://gnu.org/software/gcc/ https://gnu.org/software/binutils/

Installed dependencies


Prepare environment

export PREFIX="$HOME/opt/cross"
export TARGET=i686-elf
export PATH="$PREFIX/bin:$PATH"

Build binutils

cd $HOME/src
mkdir build-binutils
cd build-binutils
../binutils-x.y.z/configure --target=$TARGET --prefix="$PREFIX" --with-sysroot --disable-nls --disable-werror
make install

Build GCC

cd $HOME/src
mkdir build-gcc
cd build-gcc
../gcc-x.y.z/configure --target=$TARGET --prefix="$PREFIX" --disable-nls --enable-languages=c,c++ --without-headers
make all-gcc
make all-target-libgcc
make install-gcc
make install-target-libgcc