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:
- Run the boot loader from the boot device
It is LILO 's job to find the selected kernel and get it loaded into memory, including any user-supplied options.
- Launch the Linux kernel and start processes
Your boot loader starts the specified kernel. The boot loader's job at this point is complete and the hardware is placed under the control of the running kernel, which sets up shop and begins running processes.
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:
- The boot loader
This part of LILO is a two-stage program intended to find and load a kernel. It's a two-stage operation because the boot sector of the disk is too small to hold the entire boot loader program. The code located in the boot sector is compact because its only function is to launch the second stage, which is the interactive portion. The first stage of LILO usually resides in the MBR of the hard disk. This is the code that is started at boot time by the system BIOS. It locates and launches a second, larger stage of the boot loader that resides elsewhere on disk. The second stage offers a user prompt to allow boot-time and kernel image selection options, finds the kernel, loads it into memory, and launches it.
- The lilo command
Also called the map installer, lilo is used to install and configure the LILO boot loader. The lilo command reads a configuration file , which describes where to find kernel images, video information, the default boot disk, and so on. It encodes this information along with physical disk information and writes it in files for use by the boot loader.
When the system BIOS launches, LILO presents you with the following prompt:
LILO:
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.
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
- Syntax
lilo [
options
]The lilo map installer reads a configuration file and writes a map file, which contains information needed by the boot loader to locate and launch Linux kernels or other operating systems.
- Frequently used options
- -C config_file
Read the config_file file instead of the default /etc/lilo.conf.
- -m map_file
Write map_file in place of the default as specified in the configuration file.
- -q
Query the current configuration.
- -v
Increase verbosity.
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
boot = /dev/hda timeout = 50 prompt read-only map = /boot/map install = /boot/boot.b image = /boot/vmlinuz-2.2.5-15 label = linux root = /dev/hda1
Each of these lines is described in the following list:
-
boot
Sets the name of the hard disk partition device that contains the boot sector. For PCs with IDE disk drives, the devices will be /dev/hda, /dev/hdb, and so on.
-
timeout
Sets the timeout in tenths of a second (deciseconds) for any user input from the keyboard. To enable an unattended reboot, this parameter is required if the
prompt
directive is used.-
prompt
Sets the boot loader to prompt the user. This behavior can be stimulated without the prompt directive if the user holds down the Shift, Ctrl, or Alt key when LILO starts.
-
read-only
Sets the root filesystem to initially be mounted read-only. Typically, the system startup procedure will remount it later as read/write.
-
map
Sets the location of the map file, which defaults to /boot/map.
-
install
Sets the file to install as the new boot sector, which defaults to /boot/boot.b.
-
image
Sets the kernel image to offer for boot. It points to a specific kernel file. Multiple image lines may be used to configure LILO to boot multiple kernels and operating systems.
-
label
Sets the optional label parameter to be used after an image line and offers a label for that image. This label can be anything and generally describes the kernel image. Examples include
linux
andsmp
for a multiprocessing kernel.-
root
Sets the devices to be mounted as root for specified image (used after each image line).
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.
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.
GRUB refers to disk devices as follows:
(x
dn
[,m
])
The x
d
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:
-
(fd0)
The first floppy disk.
-
(hd0)
The first hard disk.
-
(hd0,1)
The second partition on the first hard disk.
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.
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:
(disk
) /dev/device
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)
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>
GRUB expects a certain sequence of commands to boot a Linux kernel. They are as follows:
root
device
kernel
filename
[options
](optional)
initrd
filename
boot
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
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:
default=0 timeout=3 title Red Hat Linux (2.4.18-14) root (hd0,0) kernel /vmlinuz-2.4.18-14 ro root=/dev/hda2 initrd /initrd-2.4.18-14.img
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.
Get LPI Linux Certification in a Nutshell, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.