Lessons Learned

Own Bootloader vs. GRUB

When writing your own bootloader, you are responsible for finding the kernel binary or bootstrap code and loading it at the correct memory location. GRUB on the other hand will automatically give you a lot of features.

A good GRUB example can be found here http://www.jamesmolloy.co.uk/tutorial_html/.

A good custom bootloader example can be found here https://github.com/cfenollosa/os-tutorial

  • Kernel Binary Loading – Your first bootloader will be very simple. Unless you implement filesystem support, your loader has to read the binary using BIOS calls. It cannot know how large a kernel file is without node information of a filesystem. Hence the sectors read by the BIOS have to be hardcoded and you have to read enough sectors to read your entire kernel in. If you read your kernel only partially, your OS will fail. As your kernel grows, it will outgrow the hardcoded value and you have to update the loader or else the OS will fail. GRUB can read the filesystem on a floppy for example. It knows how large your kernel using the node information provided by the filesystem. No partial loading of your kernel will ever occur.
  • Protected Mode – GRUB can immediately put the CPU into protected mode for you.
  • Graphics Mode – GRUB can set the video mode for you.
  • Multiboot – GRUB can give the user the option to choose which OS to boot. If your OS plays nicely by adhering to the multiboot specification, you can easily have several OS installed on the same machine. A good GRUB multiboot example can be found here http://www.jamesmolloy.co.uk/tutorial_html/.

Leave a Reply