Loading Linux with GRUB

During the installation of Red Hat Linux 7.2, you're asked to select which boot loader should be used. By default, Red Hat uses the Grand Unified Bootloader (GRUB), and creates a GRUB configuration based on the values you select during the installation. Listing 1.1 shows the GRUB configuration generated by the Red Hat installation program for a desktop client. A dual-boot client configuration is used as an example because it is slightly more complex than a server configuration (servers do not usually dual-boot).

Listing 1.1: The Default GRUB Configuration

# grub.conf generated by anaconda

# Note that you do not have to rerun grub after making changes to this file

# NOTICE: You do not have a /boot partition. This means that

# all kernel and initrd paths are relative to /, eg.

# kernel /boot/vmlinuz-version ro root=/dev/hda3

# initrd /boot/initrd-version.img #boot=/dev/hda default=0 timeout=10

splashimage=(hd0,2)/boot/grub/splash.xpm.gz password —md5 $1$Lo0CX<Ea$qgeIevUEDvvQAmrm4jCd31 title Red Hat Linux (2.4.7-10) root (hd0,2)

kernel /boot/vmlinuz-2.4.7-10 ro root=/dev/hda3 initrd /boot/initrd-2.4.7-10.img title DOS

rootnoverify (hd0,0) chainloader +1

The GRUB configuration is stored in grub.conf, which is a simple text file. Lines that begin with # are comments, and the Red Hat installation program inserts several comments at the beginning of the file.

The first active command line in this configuration is default=0. This command identifies which operating system should be booted by default in a dual-boot configuration. The operating systems that are available to GRUB are defined at the end of the configuration. Each operating system is assigned a number, sequentially starting from 0. Thus, the first operating system defined is 0, the second is 1, the third is 2, and so on. This configuration defines two operating systems: Red Hat Linux and DOS. Red Hat Linux is listed first; therefore, it is operating system 0, and it is the operating system that will be booted by default. In this case, the command default=0 is not really required because default is set to 0 whenever the default command is not included in the configuration. However, including the command makes a clean, self-documenting configuration.

The second active line, timeout=10, also relates to the default boot. The timeout command sets the number of seconds the operator has to interrupt the boot process before GRUB automatically loads the default operating system. In this example, the operator has 10 seconds to select the alternate operating system before Red Hat Linux is automatically booted. Even for systems that do not dual-boot, set a value for timeout because this allows the operator to interrupt the boot process if it is necessary to pass arguments to the kernel. Providing kernel input at the boot prompt is covered later in this chapter.

The splashimage command points to a file that contains the background image displayed by GRUB. During the timeout period, GRUB displays a boot menu. The splashimage file is the background displayed behind that menu.

During the initial installation of Red Hat Linux 7.2, you have an opportunity to enter a GRUB password. The password entered at that time is stored in the grub.conf file using the password command. The password "Wats?Watt?" was entered during the installation of our sample system. Note that the password is not stored as clear text. The password is encrypted, and the —md5 option on the password command line lets us know that the password is encrypted with the Message Digest 5 (MD5) algorithm. The operator must enter the correct password to gain access to the full range of GRUB features. The operator can boot any of the operating systems listed in the GRUB menu without entering the password; however, optional input, such as kernel parameters, cannot be entered without the correct password. If the password command is not included in the grub.conf file, a password is not required to access any GRUB features.

The title command defines the exact text that will be displayed in the GRUB menu to identify an operating system. The commands that follow a title command and occur before the next title command describe an operating system to the boot loader. The sample configuration defines the following two operating systems:

kernel /boot/vmlinuz-2.4.7-10 ro root=/dev/hda3 initrd /boot/initrd-2.4.7-10.img title DOS

rootnoverify (hd0,0) chainloader +1

The first title command defines the menu text Red Hat Linux (2.4.7-10). The next three lines define the operating system that is booted when that item is selected from the GRUB menu:

root (hd0,2) Defines the physical location of the filesystem root for this operating system. The values defined for the root command are the disk device name and the partition number. Notice that GRUB device names are slightly different from normal Linux device names. GRUB calls the first hard disk hd0. Additionally, GRUB counts partitions differently than Linux does. GRUB counts from 0, whereas Linux counts from 1. Thus, the GRUB value hd0,2 on a Linux system that boots from an IDE drive is the same as the Linux value hda,3—partition number 3 on the first IDE drive.

kernel /boot/vmlinuz-2.4.7-10 ro root=/dev/hda3 Identifies the file that contains the operating system that is to be started, and defines any arguments passed to that operating system at run time. In this case, GRUB will load the Linux kernel stored in vmlinuz-2.4.7-10, and it will pass the Linux kernel the arguments ro root=/dev/hda3, which tell the kernel where the filesystem root is located, and that it should be mounted as read-only. The ro option causes Linux to mount the root read-only during the initial phase of the boot. (Later, the rc.sysinit script changes it to read-write after successfully completing the filesystem checks.)

initrd /boot/initrd-2.4.7-10.img Identifies a ramdisk file for Linux to use during the boot. Red Hat uses the ramdisk to provide Linux with critical modules that the kernel might need to access the disk drives.

The last title command defines the DOS menu entry. Two commands define the operating system loaded when DOS is selected from the menu:

rootnoverify (hd0,0) Like the root command, defines the physical location of the filesystem root for this operating system. But rootnoverify tells GRUB that the filesystem found at this location does not comply with the multiboot standards, and thus cannot be validated.

chainloader +1 Emulates the function of the DOS MBR by simply loading the specified sector and passing boot responsibilities to the loader found there. The value +1 is a blocklist value, which defines the sector address of the loader relative to the partition defined by the rootnoverify command. +1 means the first sector of the partition. Taken together, the rootnoverify command and the chainloader command from our sample mean that GRUB will pass control to the loader found in the first sector of the first partition on the first IDE drive when DOS is selected from the GRUB menu. In this example, that partition contains the DOS boot loader that will be responsible for loading DOS.

The grub.conf file on your system will be very similar to the one in this example. The location of files may be different, and a server system's configuration usually won't define multiple operating systems, but the commands will be essentially the same.

GRUB is used with several different flavors of UNIX. It is not, however, the only boot loader used with Linux—or even the most popular Linux boot loader. Red Hat, prior to 7.2, used LILO, and most other versions of Linux still do. The next section takes a close look at LILO configuration.

Was this article helpful?

0 0

Post a comment