Configuring GRUB

To use GRUB, you must both install it on your system and configure it. GRUB installation involves more than just installing the GRUB package; you must run a command to copy the GRUB boot loader code to the MBR. Once installed, GRUB

doesn't need to be installed to the boot sector again, unless you change the boot partition or need to reinstall GRUB because it has been wiped out by another OS. GRUB consults files on the hard disk to boot. These files must be on a supported filesystem and present options that enable GRUB to locate your Linux kernel or boot another OS.

Installing GRUB

If necessary, you should install the GRUB package (generally called grub) using your distribution's package manager, or you should compile and install the package from source code, which is available from http://www.gnu.org/software/grub/. Once you've done this, you install GRUB to the MBR with the grub utility, which presents a command prompt at which you type a few commands:

# grub grub> find /boot/grub/stagel

grufc» quit

The find command locates the partition on which the GRUB configuration files reside. If the command as shown here returns a "file not found" error, try omitting the leading /boot in the pathname. GRUB searches partitions, not your fully mounted directory tree, so if /boot is a separate partition, you must omit the /boot specifier. The returned value (hd0,5 in this example) is expressed in GRUB's own style. The first number (0) refers to the disk device—0 is usually /dev/hda in Linux terms. The second number (5) is the partition number, numbered starting from 0. Linux numbers partitions starting from 1, so hd0,5 refers to /dev/hda6. The GRUB files normally reside in /boot, so if you know where that directory resides, you can forgo the find command; however, it's a useful double-check to use find even in this case.

The root command sets GRUB's root device. Note that the GRUB root device may not be the same as the Linux root partition; the GRUB root device is the partition on which GRUB's files reside. If your/boot directory is a separate partition, the GRUB root device will likely be different from your Linux root partition. A pointer to the GRUB root device is stored in the GRUB boot loader code, so that the code can find the GRUB configuration files when the system boots. You should pass the value returned by find to root.

The setup command writes the GRUB first-stage boot loader code—to hdO (/dev/hda) in this example. If you want to use GRUB in conjunction with another primary boot loader, you should instead write GRUB to a Linux boot partition—probably the GRUB root partition, such as hd0,5 in this example.

Once this task is done, you can exit from grub. The system will attempt to boot using files stored in the GRUB root partition. This partition can be on any Linux native filesystem (Minix, ext2fs, ext3fs, ReiserFS, JFS, orXFS), on a FAT filesystem, or on a handful of other Unix-like operating systems' native filesystems, such as the Fast File System (FFS) used by FreeBSD and some others.

Configuring GRUB

GRUB is configured through a file called /boot/grub/menu. 1st. (Red Hat calls the file /boot/grub/grub.conf and also creates a symbolic link to this file from /etc.) Listing 10.1 shows a typical menu.1st file.

Listing 10.1: Typical GRUB Configuration File default=0 timeout=10

splashimage=(hd0,4)/grub/splash.xpm.gz title Linux (2.4.19) root (hd0,5)

kernel /bzlmage-2.4.19 ro root=/dev/hda7 title Windows unhide (hd0,1) hide (hdO.O) rootnoverify (hd0,1) chainloader +1 makeactive boot title DOS

unhide (hd0,0) hide (hd0,1) rootnoverify (hd0,0) chainloader +1 makeactive boot

The first three lines of Listing 10.1 set global options—the default OS to boot (numbered starting from 0, or the first definition in this example), the timeout in seconds before booting the default OS, and a graphics file to display as a background for selecting an OS. Many other global options are available, and many distributions set some of them. Consult the GRUB documentation (available as info pages, so type info grub to view them) for more details.

Subsequent lines are broken into sections beginning with the keyword title, which defines the name of the option that will appear in the GRUB boot menu. The first definition in Listing 10.1 is for Linux. The root keyword sets the GRUB root device, not the Linux root partition. The kernel keyword defines the kernel that's to be booted—bzlmage-2.4.19 in this example, defined relative to the GRUB root device. Because this root device is /boot from Linux's point of view, Listing 10.1 tells GRUB to use /boot/bzlmage-2.4.19 as the boot kernel. You can pass options to the kernel on this line. In Listing 10.1, ro tells the kernel to mount its root partition read-only (it's subsequently mounted read/write by the /etc/fstab entry) and the root parameter specifies Linux's root partition.

The Windows and DOS definitions in Listing 10.1 tell GRUB how to boot Windows and DOS, respectively. Because these OSs shouldn't be able to see each other's primary partitions, the unhide and hide keywords unhide the target partition and hide the one belonging to the other OS. Similarly, makeactive sets the target partition's bootable flag. The chainloader +1 keyword tells GRUB to use the boot sector of the active partition (specified with rootnoverify on the preceding line) as a secondary boot loader. When GRUB hits the boot line, it passes control to this boot sector, thereby booting the OS that resides on this partition.

To reconfigure GRUB, you need only modify the menu.1st file. Thus, if you make a mistake when configuring GRUB, you can correct it from any OS that can read and write the filesystem on which it's stored. You don't need to reinstall GRUB in the MBR or partition boot sector, as you must do when reconfiguring LILO.

0 0

Post a comment