How Does Grub Work in Linux?
Grub, now named Grub 2, is the default boot loader for the Linux operating system. According to Gnu.org, the last release of the original Grub boot loader was made in 2005 and was replaced by the Grubm2 boot loader. Grub 2 is a more powerful version of the Grub boot loader. Both versions use similar methods for booting the operating system. As of 2009, most of the main Linux distributions have replaced Grub Legacy with Grub 2 as the default boot loader.
-
Master Boot Record
-
The Master Boot Record is located on the first 512 bytes of the primary partition. Its only function is to look for an active partition, load the partition's boot sector into memory and pass control to it. It consists of the primary boot loader and the partition table. The partition table describes the primary and extended partitions contained on the device. The Grub boot loader replaces the primary boot loader with its own code.
Grub Boot Loader
-
Grub is a chain loading boot loader. Chain loading passes control from the boot manager to a boot sector typically contained on the primary partition of the hard drive. Grub Legacy, the original Grub boot loader, uses Stages for the boot process. Grub 2 uses images and dynamically loaded modules instead of stages. The Grub 2 process can be explained in terms of the Grub Legacy stages.
-
Stage 1
-
Stage 1 is stored directly within the MBR. Its primary function is to point to Stage 2 because the MBR is too small for the data required. In Grub 2, this function is replaced by the boot image. The boot image's only function is to read the first sector of the core image and pass the control to it.
Stage 1.5
-
Stage 1.5 includes enough file system code to read Stage 2 from an ordinary file system. This stage was replaced by the core image in Grub 2. The core image is more powerful than the original Stage 1.5. It provides a rescue shell and makes it possible to recover the process manually if the other modules cannot be loaded. It allows the use of Logical Volume Manager (LVM) and Redundant Array of Independent Disks (RAID) devices.
Stage 2
-
The function of Stage 2 is to point to the Grub configuration file which contains the boot options. There is no Stage 2 equivalent in Grub 2. Instead, the boot modules are loaded by core image and read from the /boot/grub directory at runtime.
-
References
Resources
- Photo Credit Jupiterimages/Photos.com/Getty Images