Chapter 5. GRUB

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

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

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

This chapter discusses GRUB, the method Red Hat Linux uses to launch operating systems on x86 systems, and looks at various command and configuration options that allow you to control 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 you to place specific instructions in the MBR that loads a GRUB menu or command environment, permitting you to start the operating system of your 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, commonly called the MBR, start the process of bringing up 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:

  1. Loading 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. Loading 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. Loading 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 your 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, consult the GRUB info pages.

This 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 boot methods, allowing you to use it with almost any operating system, most popular filesystems, and almost any hard disk your 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 allow you to control 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 your BIOS supports LBA mode (most do).

  • GRUB's configuration file is read from the disk every time the system boots, preventing you from having to write over the MBR every time you change the boot options.

    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, you 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 you with an unbootable system. With GRUB, if you misconfigure the configuration file and reboot, it will simply drop you to a command line and allow you 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 you do restart GRUB, you will be dropped to the command line GRUB shell.

Installing GRUB

If during the Red Hat Linux installation process you did not install GRUB, here is how you can install it and make it your default boot loader.

NoteNote
 

If you are already using LILO as your boot loader, you do not have to remove it in order to use GRUB. Once installed, GRUB will be the default boot loader for your system.

First, make sure you have the latest GRUB package available. You can also use the GRUB package from the Red Hat Linux installation CD-ROMs.

Next, run the command /sbin/grub-install <location> from a shell prompt, where <location> is the location where GRUB should be installed, such as /dev/hda1.

When you reboot your system, you will see the GRUB boot loader.