Chapter 4. GRUB

Before Red Hat Linux can load on a system, it must be told to boot by special instructions placed on a boot loader, a program that exists on the system's primary hard drive or other media device that knows how to start the Linux kernel.

If using an x86 system that only boots Red Hat Linux and only one version of the Linux kernel, then the exact process used by the boot loader to start Red Hat Linux is not very important. The Red Hat Linux installation program allows users to quickly and easily configure the boot loader in the primary hard drive's Master Boot Record (MBR) to load the operating system.

However, in order to have the choice to boot from multiple Linux kernels or other operating systems, it is essential to have the knowledge of the method used by Red Hat Linux to provide the necessary boot options, as well as an understanding of the boot process and what to change.

This chapter discusses GRUB, the default method Red Hat Linux uses to launch operating systems on x86 systems. The chapter will also detail various commands and configuration options that enable control over the boot process.

Defining GRUB

GNU GRUB (GRand Unified Bootloader) is a program that installs a boot loader to the MBR, which exists at the beginning sectors of a disk. It allows the placement of specific instructions in the MBR that loads a GRUB menu or command environment, which enables users to start the operating system of choice, pass special instructions to kernels when they boot, or discover system parameters (such as available RAM) before booting.

x86 Boot Process

When an x86 machine first starts up, the BIOS of the system checks for particular system parameters, such as the amount of RAM in the machine, the date and time, disk devices present, and the order in which those disk devices should be checked for bootable media. Usually, the BIOS is configured to check the machine's floppy disk drive or CD-ROM drive (or both) before attempting to boot from the hard drive. If no bootable media can be found in those removable devices, the BIOS usually turns to the first few sectors of the first hard drive for instructions on where to find and load an operating system. These first few sectors — the MBR — start the process of loading a pre-selected operating system, a GRUB menu of operating system options, or a GRUB command line interface to execute special options.

The process of loading GRUB, and then the operating system, involves several stages of operation:

  1. Load the primary boot loader, commonly called Stage 1. The primary boot loader must exist in the very small space allocated for the MBR, which is less than 512 bytes. Therefore, the only thing the primary boot loader accomplishes is loading the secondary boot loader, due to the fact that there is not enough space in the MBR for anything else.

  2. Load the secondary boot loader, commonly called Stage 2. The secondary boot loader actually brings up the advanced functionality that allows you to load a specific operating system. With GRUB, this is the code that allows you to display a menu or type commands.

  3. Load the operating system, such as the Linux kernel, on a specified partition. Once GRUB has received the correct instructions for the operating system to start, either from its command line or configuration file, it finds the necessary boot file and hands off control of the machine to that operating system.

NoteNote
 

Some filesystems, as well as filesystem configurations, may require a Stage 1.5 file that essentially bridges the gap between the primary and secondary boot loaders.

For example, if the Stage 2 boot loader file is on a partition using a filesystem that the Stage 1 boot loader cannot access, it is possible to direct the Stage 1 boot loader to load additional instructions from the Stage 1.5 file that allows it to read the Stage 2 boot loader file. For more information, refer to the GRUB info page.

The aforementioned boot method is called direct loading, because instructions to directly load the operating system are used, with no intermediary code between the boot loaders and the operating system's main files (such as the kernel). The boot process used by different operating systems may differ slightly from the above, however. For example, Microsoft's DOS and Windows operating systems tend to completely overwrite anything on the MBR when they are installed without incorporating any of the current MBR's configuration. This destroys any other information stored in the MBR by other operating systems, such as Red Hat Linux. The Microsoft operating systems, as well as various other proprietary operating systems, are loaded using a chain loading boot method. With this method, the MBR simply points to the first sector of the partition holding the operating system, where it finds the special files necessary to actually boot that operating system.

GRUB supports both direct and chain-loading boot methods. It is possible to use it with almost any operating system, most popular filesystems, and almost any hard disk the system BIOS can recognize.

GRUB Features

GRUB contains a number of features that make it preferable to other available boot loaders. These are some of the most important:

  • GRUB provides a true command-based, pre-OS environment on x86 machines to allow maximum flexibility in loading operating systems with certain options or gathering information about the system. Many non-x86 architectures have employed pre-OS environments for years that allows control over how the system boots from a command line. While some command features are available with LILO and other x86 boot loaders, GRUB contains a greater number of features.

  • GRUB supports Logical Block Addressing (LBA) mode. LBA places the addressing conversion used to find files on the drive in the drive's firmware, and it is used on many IDE and all SCSI hard disks. Before LBA, hard drives could encounter a 1024-cylinder limit, where the BIOS could not find a file after that point, such as a boot loader or kernel files. LBA support allows GRUB to boot operating systems from partitions beyond the 1024-cylinder limit, so long as the system BIOS supports LBA mode (most do).

  • GRUB's configuration file is read from the disk every time the system boots, preventing the user from having to write over the MBR every time a change the boot options is made. Most boot loaders are not sophisticated enough to read configuration files and use them to set up boot options. For example, to change a LILO boot configuration, such as changing the default operating system to boot, users must change a LILO configuration file and run a command that overwrites the system's MBR with the new configuration data. This is more risky than GRUB's method, because a misconfigured MBR would leave the system unbootable. With GRUB, if the configuration file is erroneously configured and rebooted, it will simply default to a command line and allow the user to manually type commands that will launch the operating system. The MBR is not touched except to update the Stage 1, Stage 2, or menu configuration file locations, and this is rarely necessary.

    NoteNote
     

    When changes are made to the GRUB configuration file, it is not necessary to restart GRUB. Any changes made are automatically detected. If GRUB is restarted, the user will be dropped to the command line GRUB shell.

Installing GRUB

If GRUB was not installed during the Red Hat Linux installation process, the following explains how to install it and make it the default boot loader.

NoteNote
 

If LILO has been installed and is currently the system boot loader, it is not necessary to remove it in order to use GRUB. Once installed, GRUB will be the default boot loader for the system.

First, make sure to have the latest GRUB package available. The GRUB package from the Red Hat Linux installation CD-ROMs can also be used.

From a shell prompt, run the command /sbin/grub-install <location>, where <location> is the location where GRUB should be installed. For example:

/sbin/grub-install /dev/hda

Finally, reboot the system. The GRUB graphical boot loader menu should appear.