What is GRUB boot Loader ?

On a Red Hat Linux system, the boot loader's function is to locate the Linux Kernel, and any other necessary files, and load them into memory. It then starts the kernel so that the kernel can run processes.

The boot loader also lets you to control how a system is booted. If you dual boot, a boot loader enables you to choose between operating systems at startup.

When a computer boots, the basic input/output system (BIOS) in read only memory usually loads the boot loader from the Master Boot Record (MBR) on the system's primary hard drive.

However some versions of Linux run directly from the flash memory, by passing the BIOS and the boot loader. Linux was designed to run without an interactive boot loader with the kernel located at particular sectors on the disk.

Using a boot loader offers several benefits including

  • the ability to boot multiple operating systems
  • the ability to pass parameters interactively to the kernel, which is useful for disabling certain features in order to solve hardware problems
  • the ability to load different kernels interactively, which is useful when you deploy a new kernel because it is easy to revert to the working kernel.

What are the stages involved in loading GRUB?

Most boot loaders execute in two or more stages. GRUB loads itself into memory by

1. loading the stage 1 boot loader

  • First the BIOS reads the stage 1 or primary boot loader into memory from the MBR. 
  • The primary boot loader takes up less than 512 bytes of disk space in the MBR - too small a space to contain the instructions necessary to load a complex operating system. 
  • Instead the primary boot loader performs the function of loading either the stage 1.5 or stage 2 boot loader.

2. loading the stage 1.5 boot loader

  • Some hardware requires an intermediate step between the stage 1 and stage 2 boot loaders. 
  • This can happen when the /boot partition is situated beyond the 1024 cylinder head of the hard drive, or when you are using LBA mode.
  • GRUB Stage 1.5 is located in the first 30 KB of Hard disk immediately after MBR and before the first partition.
  • This space is utilised to store file system drivers and modules.
  • This enabled stage 1.5 to load stage 2 to load from any known loaction on the file system i.e. /boot/grub

3. loading the stage 2 boot loader

  • The secondary boot loader is located somewhere on the disk - on the boot sector of the first partition. 
  • For Example it displays the GRUB menu and command environment, which enables you to select which operating system or Linux kernel to boot. 
  • You can also use it to pass arguments to the kernel.

4. loading the operating system or kernel

  • GRUB determines which operating system to start and loads the operating system or kernel and initrd into memory. 
  • It then transfers control of the computer to the OS.

GRUB vs LILO

The two boot loaders that Red Hat Linux provides for x86 architecture are the Grand Unified Boot Loader (GRUB) and the Linux Loader (LILO). In the past LILO has been the most popular for Linux and the default loader on most distributions.

However, the GNU project's GRUB is new more commonly used.

GRUB is currently the default Red Hat Linux boot Loader. It is an improvement over LILO in that it enables you to

  • use password protection
  • try different boot parameters during the boot process without permanently hanging the GRUB configuration file.
  • boot Windows NT operating system from the MBR area of the hard drive
GRUB also supports Logical Block Addressing (LBA) mode which enables the computer to find the /boot files more easily, particularly if they are located beyond the 1024th cylinder of the hard drive.

Direct vs Chain-loading Method

The boot method for Red Hat Linux is called the direct loading method, because the boot loader loads the operating system directly without using an intermediary stage between the boot loader and the kernel.

In the chain loading boot method, the MBR points to the first sector of the partition that contains the operating system. The MBR uses the files in this location to boot the operating system.

GRUB supports both direct and chain loading boot methods, so it can boot almost any operating system.
'

Related Articles
What is kernel-PAE in Linux?
What is a Kernel in Linux?
What is swappiness and how do we change its value?
What is virtual memory, paging and swap space?
What is the difference between POP3 and IMAP?