4.3. GRUB: The Grand Unified BootloaderLike LILO, the GRUB boot loader can load other operating systems in addition to Linux. GRUB was written by Erich Boleyn to boot operating systems on PC-based hardware, and is now developed and maintained by the GNU project. GRUB was intended to boot operating systems that conform to the Multiboot Specification, which was designed to create one booting method that would work on any conforming PC-based operating system. In addition to multiboot-conforming systems, GRUB can boot directly to Linux, FreeBSD, OpenBSD, and NetBSD. It can also boot other operating systems such as Microsoft Windows indirectly, through the use of a chainloader. The chainloader loads an intermediate file, and that file loads the operating system's boot loader. GRUB provides a graphical menu interface. It also provides a command interface that is accessible both while the system is booting (the native command environment) and from the command line once Linux is running. While LILO works perfectly well, especially if you usually boot the default image, GRUB has some advantages. The graphical menu interface shows you exactly what your choices are for booting so you don't have to remember them. It also lets you easily edit an entry on the fly, or drop down into the command interface. In addition, if you are using the menu interface and something goes wrong, GRUB automatically puts you into the command interface so you can attempt to recover and boot manually. Another advantage of GRUB is that if you install a new kernel or update the configuration file, that's all you have to do; with LILO, you also have to remember to rerun the lilo command to reinstall the boot loader. On the other hand, if you are used to LILO, don't need to see the prompts often, and have a stable system, LILO is quick and convenient. A GRUB installation consists of at least two and sometimes three executables, known as stages. The stages are:
If it was compiled with netboot support, GRUB can also be used to boot over a network. We don't describe that process here; see the file netboot/README.netboot in the GRUB source directory for detailed information. One of the first things to understand about GRUB is that it uses its own naming conventions. Drives are numbered starting from 0; thus, the first hard drive is hd0, the second hard drive is hd1, the first floppy drive is fd0, and so on. Partitions are also numbered from 0, and the entire name is put in parentheses. So the first partition of the first drive, /dev/hda1, is known as (hd0,0) to GRUB. The third partition of the second drive is (hd1,2). GRUB makes no distinction between IDE drives and SCSI drives, so the first drive is hd0 whether it is IDE or SCSI. Files are specified either by the filename or by blocklist, which is used to specify files such as chainloaders that aren't part of a filesystem. A filename looks like a standard Unix path specification with the GRUB device name prepended; for example: (hd0,0)/grub/grub.conf If the device name is omitted, the GRUB root device is assumed. The GRUB root device is the disk or partition where the kernel image is stored, set with the root command. See Section 4.4 for the command descriptions. When you use blocklist notation, you tell GRUB which blocks on the disk contain the file you want. Each section of a file is specified as the offset on the partition where the block begins plus the number of blocks in the section. The offset starts at 0 for the first block on the partition. The syntax for blocklist notation is: [device][offset]+length[,offset]+length... In this case, too, the device name is optional for a file on the root device. With blocklist notation, you can also omit the offset if it is 0. A typical use of blocklist notation is when using a chainloader to boot Windows. If GRUB is installed in the MBR, you can chainload Windows by setting the root device to the partition that has the Windows boot loader, making it the active partition, and then using the chainloader command to read the Windows boot sector: rootnoverify (hd0,0) makeactive chainloader +1 In this example, the blocklist notation (+1) does not include either the device name or the offset because we set the root device to the Windows partition, and the Windows loader begins at offset 0 of that partition. GRUB also includes a device map. The device map is an ASCII file, usually /boot/grub/device.map. Since the operating system isn't loaded yet when you use GRUB to boot Linux (or any other operating system), GRUB knows only the BIOS drive names. The purpose of the device map is to map the BIOS drives to Linux devices. For example: (fd0) /dev/fd0 (hd0) /dev/hda 4.3.1. Installing GRUBInstalling GRUB involves two stages. First, you install the GRUB files on your system, either by compiling and installing the source tarball or from a package. That puts the GRUB files in the correct locations on your system. The second step is to install the GRUB software as your boot manager. This is the step we describe in this section. If you installed GRUB as part of your Linux installation, the distribution's installation program took care of both stages of installing GRUB, and you'll most likely see the GRUB menu when you boot Linux. If you didn't install GRUB as part of your Linux installation, you have two choices. The easiest way to install GRUB is with the grub-install shell script that comes with GRUB. If grub-install doesn't work, or if you want to do the installation manually, you can run the grub command and issue the installation commands yourself. The following sections describe how to create a GRUB boot floppy and how to install GRUB. 4.3.1.1. Creating a GRUB boot floppyYou can create a GRUB boot floppy for everyday use or to have for an emergency. The following instructions make a floppy that boots to the GRUB command line:
Put together, the process looks like this: % dd if=stage1 of=/dev/fd0 bs=512 count=1 1+0 records in 1+0 records out % dd if=stage2 of=/dev/fd0 bs=512 seek=1 254+1 records in 254+1 records out The boot floppy is now ready to boot to the GRUB command line. You can also make a boot floppy that boots to the GRUB menu:
You should now be able to boot to the GRUB menu from the floppy disk you just created. 4.3.1.2. Using grub-installGRUB comes with a shell script, grub-install, which uses the GRUB shell to automate the installation. The command syntax is: grub-install options install-device where install-device is the name of the device on which you want to install GRUB, specified as either the GRUB device name (e.g., (hd0)) or the system device (e.g., /dev/hda). For example, you might issue following the command (as root): # grub-install /dev/hda This command installs GRUB into the MBR of the first hard drive. The grub-install options are:
4.3.1.3. Installing from the GRUB command lineTo install GRUB from the native command environment, make a GRUB boot floppy as described previously. You will use that floppy to boot to the GRUB command line to do the installation. If you know which partition holds the GRUB files, you're all set. Otherwise, you can find the partition with the find command: grub> find /boot/grub/stage1 (hd0,0) Here, the files are on (hd0,0). Use that information to set the GRUB root device: grub> root (hd0,0) Run the setup command to install GRUB. To install GRUB on the MBR, run setup as follows: grub> setup (hd0) If you are going to chainload Linux and want to install GRUB on the boot sector of the Linux partition, run setup like this: grub> setup (hd0,0) 4.3.2. The GRUB Configuration FileGRUB uses a configuration file that sets up the menu interface. The configuration file is called grub.conf and is found with the other GRUB files in the /boot/grub directory. grub.conf is also known as menu.lst, and at least on some distributions (e.g., Red Hat 8), menu.lst is a symbolic link to grub.conf. The configuration file begins with a section containing global commands that apply to all boot entries, followed by an entry for each Linux image or other operating system that you want to be able to boot. Here is an example of a global section (a hash sign, #, begins a comment): default=0 # default to the first entry timeout=20 # set the timeout to 20 seconds splashimage=(hd0,0)/grub/splash.xpm.gz # the splash image displayed with # the menu Certain GRUB commands are available only in the global section of the configuration file, for use with the GRUB menu. These commands are described in the following list. All other commands can be used either in the configuration file or on the command line and are described later in Section 4.4.
Following the global section, the configuration file includes an entry for each boot image. An entry begins with a title command that specifies the text that will appear on the menu for that entry when the system boots. A typical boot entry might look like this one from a Red Hat 8.0 system: title Red Hat Linux (2.4.18-14) root (hd0,1) kernel /vmlinuz-2.4.18-14 ro root=LABEL=/ hdc=ide-scsi initrd /initrd-2.4.18-14.img This entry provides the information GRUB needs to boot to Linux. When the menu is displayed, it will include an entry that says: Red Hat Linux (2.4.18-14) The GRUB root is on the second partition of the first hard drive (hd0,1). The kernel command specifies which Linux kernel to run and passes some parameters to the kernel, and the initrd command sets up an initial RAM disk. The configuration file also provides some security features, such as the ability to set passwords and to lock certain entries so only the root user can boot them. The configuration file can be set up so that a password is required to run interactively (i.e., for editing menu entries or using the command interface) or simply to protect certain menu entries while leaving other entries available to all users. See the explanation of the password and lock commands in Section 4.4. In addition to providing a password feature, GRUB provides the command md5crypt to encrypt passwords in MD5 format, and a corresponding Linux command, grub-md5-crypt. grub-md5-crypt is a shell script that acts as a frontend to the grub shell, calling md5crypt. Passwords encrypted either directly with md5crypt or with grub-md5-crypt can be used with the password command to set up a GRUB password. grub-md5-crypt has three possible options:
4.3.3. Using the Menu InterfaceThe most common way to use GRUB is with the menu interface. The Stage 2 loader reads the configuration file grub.conf and displays the menu. If a timeout is set in the configuration file, GRUB displays a countdown at the bottom of the window showing how much time is left before it boots to the default entry. Move the cursor to an entry and press Enter to boot; or, press e to edit the command line for that entry, a to modify the kernel arguments, or c to go to the command-line interface to issue commands manually. If you go to the command line, you can return to the menu at any time by pressing Esc. Selecting a and e are similar, except that a displays only the kernel command line and lets you append options to it, while e displays the entire boot entry for you to edit. In either case, the available editing commands are similar to those available on the shell command line. When you are through editing, press Esc to return to the main menu. Your changes take effect for this session only; the configuration file is not permanently changed. One common use for editing a kernel command is to boot to single-user mode. To do that, select a from the menu and append the word "single" to the end of the kernel command. Then press Esc to return to the menu and select the entry. 4.3.4. The GRUB ShellIn addition to using the command line from within the GRUB menu interface (or booting directly to the command line), you can run a GRUB shell directly from the Linux command line with the grub command. For the most part, using the grub shell is the same as running in the native command-line environment. The major difference is that the shell uses operating system calls to emulate the BIOS calls that the native environment uses. That can lead to some differences in behavior. The syntax of the grub command is: grub [options] For example: % grub --no-floppy The grub command-line options are:
When you run grub, you will see something like this: GRUB version 0.92 (640K lower / 3072K upper memory) [ Minimal BASH-like line editing is supported. For the first word, TAB lists possible command completions. Anywhere else TAB lists the possible completions of a device/filename. ] grub> You can now enter commands at the "grub>" prompt. Press Tab to get a brief help message, listing all the commands: grub> Possible commands are: blocklist boot cat chainloader cmp color configfile debug device displayapm displaymem dump embed find fstest geometry halt help hide impsprobe initrd install ioprobe kernel lock makeactive map md5crypt module modulenounzip pager partnew parttype password pause quit read reboot root rootnoverify savedefault serial setkey setup terminal testload testvbe unhide uppermem vbeprobe Using Tab is a quick way to remind yourself of the commands, but it can be confusing to see them all run together and wrapping across lines. You can also run the help command, which lists the most frequently used commands and their syntax: grub> help blocklist FILE boot cat FILE chainloader [--force] FILE color NORMAL [HIGHLIGHT] configfile FILE device DRIVE DEVICE displayapm displaymem find FILENAME geometry DRIVE [CYLINDER HEAD SECTOR [ halt [--no-apm] help [--all] [PATTERN ...] hide PARTITION initrd FILE [ARG ...] kernel [--no-mem-option] [--type=TYPE] makeactive map TO_DRIVE FROM_DRIVE md5crypt module FILE [ARG ...] modulenounzip FILE [ARG ...] pager [FLAG] partnew PART TYPE START LEN parttype PART TYPE quit reboot root [DEVICE [HDBIAS]] rootnoverify [DEVICE [HDBIAS]] serial [--unit=UNIT] [--port=PORT] [-- setkey [TO_KEY FROM_KEY] setup [--prefix=DIR] [--stage2=STAGE2_ terminal [--dumb] [--timeout=SECS] [-- testvbe MODE unhide PARTITION uppermem KBYTES vbeprobe [MODE] You can add the --all option to see all the commands. To get help for a specific command, add the command name (e.g., help read). help treats the text you enter as a pattern; therefore, if you enter help find, you'll get help for the find command, but if you enter help module, you'll get help for both module and modulenounzip. Copyright © 2003 O'Reilly & Associates. All rights reserved. |
|