4.2. Objective 2: Install a Boot Manager
While it is possible to boot Linux from a floppy disk, most Linux installations boot from the computer's hard disk. This is a two-step process that begins after the system BIOS is initialized and ready to run an operating system. Starting Linux consists of the following two basic phases:
All Linux systems require some sort of boot loader, whether it's simply bootstrap code on a floppy disk or an application such as LILO or GRUB. Because the popularity of GRUB has grown, LPI has added it to the second release of the 101 exams.
The LILO is a small utility designed to load the Linux kernel (or the boot sector of another operating system) into memory and start it. A program that performs this function is commonly called a boot loader. While other boot loaders exist, LILO is the most popular and is installed as the default boot loader on most Linux distributions. LILO consists of two parts:
22.214.171.124. The boot loader
When the system BIOS launches, LILO presents you with the following prompt:
The LILO prompt is designed to allow you to select from multiple kernels or operating systems installed on the computer and to pass parameters to the kernel when it is loaded. Pressing the Tab key at the LILO prompt yields a list of available kernel images. One of the listed images will be the default as designated by an asterisk next to the name:
LILO: <TAB> linux* linux_586_smp experimental
Under many circumstances, you won't need to select a kernel at boot time because LILO will boot the kernel configured as the default during the install process. However, if you later create a new kernel, have special hardware issues, or are operating your system in a dual-boot configuration, you may need to use some of LILO's options to load the kernel or operating system you desire.
126.96.36.199. The LILO map installer and its configuration file
Before any boot sequence can complete from your hard disk, the boot loader and associated information must be installed by the LILO map installer utility. The lilo command writes the portion of LILO that resides in the MBR, customized for your particular system. Your installation program will do it, then you'll repeat it manually if you build a new kernel yourself.
LILO's configuration file contains options and kernel image information. An array of options is available. Some are global, affecting LILO overall, while others are specific to a particular listed kernel image. Most basic Linux installations use only a few of the configuration options.Example 4-1 shows a simple LILO configuration file.
Example 4-1. Sample /etc/lilo.conf file
Each of these lines is described in the following list:
There is more to configuring and setting up LILO, but a detailed knowledge of LILO is not required for this LPI Objective. It is important to review one or two sample LILO configurations to make sense of the boot process. A discussion on using LILO to boot multiple kernels is presented in Chapter 13.
188.8.131.52. LILO locations
During installation, LILO can be placed either in the boot sector of the disk or in your root partition. If the system is intended as a Linux-only system, you won't need to worry about other boot loaders, and LILO can safely be placed into the boot sector. However, if you're running another operating system you should place its boot loader in the boot sector. Multiple-boot and multiple-OS configurations are beyond the scope of the LPIC Level 1 exams.
GRUB is a multistage boot loader, much like LILO. Unlike LILO, GRUB is very flexible, including support for booting arbitrary kernels on various filesystem types and support for booting several different operating systems.
184.108.40.206. GRUB device naming
GRUB refers to disk devices as follows:
The xd above will either be fd or hd for floppy disk or hard disk respectively. The n refers to the number of the disk as seen by the BIOS, starting at 0. The optional ,m denotes the partition number, also starting at 0.
The following are examples of valid GRUB device names:
Note that GRUB does not distinguish between IDE and SCSI disks. It only refers to the order of the disks as seen by the BIOS, which means that the device number that GRUB uses for a given disk will change on a system with both IDE and SCSI if the boot order is changed in the BIOS.
220.127.116.11. Installing GRUB
The simplest way to install GRUB is to use the grub-install script.
For example, to install GRUB on the master boot record of the first hard drive in a system, invoke grub-install as follows:
# grub-install '(hd0)'
grub-install looks for a device map file (/boot/grub/device.map by default) to determine the mapping from BIOS drives to Linux devices. If this file does not exist, it will attempt to guess what devices exist on the system and how they should be mapped to BIOS drives. If grub-install guesses incorrectly, just edit /boot/grub/device.map and re-run grub-install.
The device map file contains any number of lines in this format:
So, for example, on a system with a floppy and a single SCSI disk, the file would look like this:
(fd0) /dev/fd0 (hd0) /dev/sda
GRUB can also be installed using the grub command. The grub-install example above could also have been done as follows, assuming /boot is on the first partition of the first hard disk:
# grub grub> root (hd0,0) grub> setup (hd0)
18.104.22.168. Booting GRUB
If there is no configuration file (or the configuration file does not specify a kernel to load), when GRUB loads it will display a prompt that looks like this:
GRUB expects a certain sequence of commands to boot a Linux kernel. They are as follows:
For example, the following sequence would boot a stock Red Hat 8.0 system with /boot on /dev/hda1 and / on /dev/hda2:
grub> root (hd0,0) grub> kernel /vmlinuz-2.4.18-14 ro root=/dev/hda2 grub> initrd /initrd-2.4.18-14.img grub> boot
22.214.171.124. The GRUB configuration file
GRUB can be configured to boot into a graphical menu, allowing the user to bypass the GRUB shell entirely. To display this menu, GRUB needs a specific configuration file, /boot/grub/menu.lst.
Tip: The location of this file may be different on your system. For example, on Red Hat systems the default configuration file is /boot/grub/grub.conf.The configuration file defines various menu options along with the commands required to boot each option. The earlier example of booting a stock Red Hat 8.0 system could have been accomplished with the following configuration file:GRUB has many more features, including serial console support, support for booting other operating systems, and so on. For more information about GRUB, see the info documentation (info grub or pinfo grub) or the online documentation at http://www.gnu.org/manual/grub.