Ask A Scientist

Please explain the process in which the GRUB boot loader works??

Asked by: Samuel Breese
School: St. James Middle School
Grade: 7
Teacher: Mrs. Hantsch
Hobbies/Interests: Virtualization, Operating Systems, Computer Networks
Career Interest: Programmer

Answer from Kartik Gopalan

Associate Professor, Binghamton University

GRUB stands for "GRand Unified Boot loader". For now let\'s safely ignore the "GRU" part of GRUB and focus only on the B -- the boot loader. The most basic function of a boot loader is to find the location where the Operating System (OS) is installed in the computer, load the OS code into main memory, and hand over the control of the processor (CPU) to the OS code. But let\'s start at the beginning.

When you power on a computer, the very first piece of software (or rather "firmware") to run on the CPU is the BIOS (Basic Input/Output System), which is stored in a flash memory chip on the motherboard. The BIOS transfers control of the processor to the first boot device, which is usually the hard disk, but it can also be a CDROM, floppy disk, USB flash drive etc. For simplicity, let\'s assume its the hard disk.

In the hard disk, the very first sector (storage unit of a hard disk) is called the Master Boot Record (MBR). The MBR is very small – only 512 bytes. Of these, 64 bytes is used to store the partition table of the hard disk and remaining 446 bytes store a small piece of code called the "boot loader". Now different partitions on the hard disk can have different OSes installed in them. The default code in the MBR (one that comes pre-installed in the hard disk) searches for the first partition marked as "active" and loads the OS installed in that active partition.

But this basic boot loader is not very useful for people who want more advanced control over the boot procedure. For example, when the computer is powered on, someone might want to select which OS to boot from (Windows or Linux), instead of the default OS in the first active partition. So people have developed various boot loaders, such as Linux Loader (LILO), GRUB, GRUB-2, and so on, which differ in the features they offer. We will focus on GRUB, which was your original question. Other boot loaders also operate very similarly.

GRUB overwrites the default boot loader in the MBR with its own

instructions. In fact, GRUB consists of multiple stages of code. Stage 1 is very small and is located in the MBR. It simply tells the processor where Stage 2 is located. Stage 2 can be placed anywhere on the hard disk, allowing it to be much more complex and larger than Stage 1. Stage 2 provides an interface thorough which the user can configure various boot options, such as selecting which OS to boot from, changing the boot parameters, performing administrative tasks, and so on. Depending on what the user selects, Stage 2 then loads the user-specified OS (with user-specified parameters) into main memory and lets the OS take over the control of the CPU.

GRUB has been recently superseded by GRUB-2, which provides a lot more features such as scripting, graphical interface, extensibility, internationalization, etc. You can find much more information on GRUB at the following website: http://www.gnu.org/software/grub/

 

 

Last Updated: 9/18/13