Booting and Shutting Down Lilo and Grub What Is Bootloader (Or Boot Manager) ?
Booting and Shutting Down Lilo and Grub What Is Bootloader (Or Boot Manager) ?
For any operating system to boot on standard PC hardware, you need what is called a boot
loader. The boot loader is the first software program that runs when a computer starts. It is
responsible for handing over control of the system to the operating system.
Typically, the boot loader will reside in the Master Boot Record (MBR) of the disk, and it
knows how to get the operating system up and running. The main choices that come with
Linux distributions are GRUB (the Grand Unified Bootloader) and LILO (Linux
Loader).GRUB and LOLO are the boot managers.
LILO is what is known as a two-stage boot loader. The first stage loads LILO itself into
memory and prompts you for booting instructions with the lilo: prompt or a colorized boot
menu. Once you select the OS to boot and press enter, LILO enters the second stage, booting
the Linux operating system.
While GRUB performs the same tasks, it offers greater functionality than LILO. For
example, there are more commands available at the grub> prompt. You don’t really want to
use either boot loader’s prompt if you can avoid it (if, like the rest of us, you want your
systems to install and run effortlessly), but because GRUB can read ext2 and ext3 partition
data, it is possible to access disk data without even booting into the operating system. A
further consequence of being able to read ext2 file system data is that GRUB can
automatically find any updates to its configuration.
LILO, on the other hand, must be run every time you change something, or it won’t update its
configuration information.
1.Configuring LILO
What is LILO?
LILO is the Linux Loader, the most popular boot loader for Linux. It is used to load Linux
into memory and start the operating system. On a machine with multiple operating systems,
LILO can be configured to boot the other systems as well. Normally LILO is initially
configured for you during the Linux installation process.
As with many Linux utilities, LILO can be customized with a configuration file in the /etc
directory.
The sample lilo.conf file shown below is for a typical dual-boot configuration, with Windows
installed on the first partition and Linux on the second.
boot=/dev/hda
map=/boot/map
install=/boot/boot.b
compact
prompt
timeout=50
image=/boot/vmlinuz-2.0.36
label=linux
root=/dev/hda2
read-only
other=/dev/hda1
label=win
boot=/dev/hda
map=/boot/map
install=/boot/boot.b
Tells LILO what to use as the new boot sector. This file contains the “bootstrap” code that
starts your operating system.
compact
prompt
Tells LILO to prompt us at boot time to choose an operating system for the Linux kernel.
Keep this.
timeout=50
Tells LILO how long to wait at the prompt before booting the default operating system,
measured in tenths of a second. The configuration shown waits for 5 seconds. If timeout is 0
or not present, LILO waits forever (if prompt is specified, otherwise boots the default
immediately).
image=/boot/vmlinuz-2.0.36
label=linux
The name that is used to identify this image at the LILO: boot prompt. Typing this name will
select this image. When asked to list the available images (by pressing TAB at the LILO:
prompt), LILO will display this name in the list.
root=/dev/hda2
Tells LILO where the root (/) file system is (in other words, where Linux lives), so that the
Linux kernel can mount it at boot time. In my case, Linux is installed in the second primary
partition.
read-only
Tells LILO to instruct the Linux kernel to initially mount the root file system as read-only. It
will be remounted as read-write later in the boot process. This is the normal method of
booting Linux.
other=/dev/hda1
Like the image line, this begins a section. Other tells LILO to boot an operating system other
than Linux. It is given the value of the partition where this other operating system lives. LILO
will simply load and execute the boot sector of this partition at boot time.
label=win
Same as the label above gives you a way to refer to this section.
2.Configuring a GRUB
Since you only have to install GRUB once on the MBR or partition of your choice, you have
the luxury of simply editing a text file, (/boot/grub/menu.1st), in order to make changes to
your boot loader. When you are done editing this file, you can reboot and select any new
kernel that you added to the configuration. The configuration file looks like the following
(please note that line numbers 1–16 have been added to the output to aid readability):
[root@fedora-serverA ~]# cat /boot/grub/menu.lst
1) default=0
2) timeout=5
3) splashimage=(hd0,0)/grub/splash.xpm.gz
4) hiddenmenu
5) title Fedora (2.6.25-14.fc9.i686)
6) root (hd0,0)
7) kernel /vmlinuz-2.6.25-14.fc9.i686 ro root=UUID=7db5-4c27 rhgb quiet
8) initrd /initrd-2.6.25-14.fc9.i686.img
The entries in the preceding sample configuration file for GRUB are discussed here:
■ Line 1, default this directive tells GRUB which entry to automatically boot. The
numbering starts from zero. The preceding sample file contains only one entry—the entry
titled Fedora (2.6.25-14.fc9.i686).
■ Line 2, timeout this means that GRUB will automatically boot the default entry after five
seconds. This can be interrupted by pressing any key on the keyboard before the counter runs
out.
■ Line 3, splashimage this line specifies the name and location of an image file to be
displayed at the boot menu. This is optional and can be any custom image that fits GRUB’s
specifications.
■ Line 4, hiddenmenu this entry hides the usual GRUB menu. It is an optional entry.
■ Line5, title this is used to display a short title or description for the following entry it
defines. The title field marks the beginning of a new boot entry in GRUB.
■ Line 6, root You should notice from the preceding listing that GRUB still maintains its
device-naming convention (e.g., (hd0,0) instead of the usual Linux /dev/sda1).
■ Line 7, kernel Used for specifying the path to a kernel image. The first argument is the
path to the kernel image in a partition. Any other arguments are passed to the kernel as boot
parameters.
Note that the path names are relative to the /boot directory, so, for example, instead of
specifying the path to the kernel to be “/boot/vmlinuz-2.6.25-14.fc9. i686,” GRUB’s
configuration file references this path as “/vmlinuz-2.6.25-14. fc9.i686.”
▲ Line 8, initrd the initrd option allows you to load kernel modules from an image, not the
modules from /lib/modules.
More important, this entry allows you to keep the existing, working configuration in case the
new kernel doesn’t work as you’d like it to. You can always reboot and select an older kernel
that does work.
You have compiled the new kernel, vmlinuz-2.5.44, and it is placed in the /boot directory.
Your first step is to append the relevant information to the /boot/grub/grub.conf or
/etc/lilo.conf file.
4.Running LILO
The LILO configuration file is /etc/lilo.conf. In most cases, you won’t need to modify the file
in any significant way. When you do need to change this file, the options are quite plain and
simple to follow. Let’s begin by reviewing a simple configuration. The file shown here is
probably quite similar to what is already in your default lilo.conf file:
boot=/dev/hda
prompt
timeout=50
image=/boot/vmlinuz-2.4.18-14
label=linux
root=/dev/hda2
read-only
other = /dev/hda1
label = dos
table = /dev/hda
The first line, boot=/dev/hda, tells LILO where to write the boot sector. Usually, this is the
first sector of the boot drive: /dev/hda for IDE-based disks, and /dev/sda for SCSI-based
disks.
The next command is prompt. This instruction tells LILO to give the lilo: prompt at boot
time. At this prompt, the user can either type in the name of the boot image that is to start, or
press TAB to list the available options. By default, LILO will wait indefinitely for user input
unless a time-out command is specified.
The timeout=50 command tells LILO to wait for 50 deciseconds (5 seconds) before selecting
the default boot image and starting the boot process.
The next line begins a small block. The line image=/boot/vmlinuz-2.4.18-14 indicates a
specific boot image. This being the first block, it will be the default boot image.
The image to boot is the file /boot/vmlinuz-2.4.18-14, which is a Linux kernel. Inside the
block is the line label=linux, which is the name that is displayed if the user asks for a list of
available boot options at the lilo: prompt.
Once you are comfortable working with the command line, you’ll quickly find that it is easy
to enable or disable a service.
Enabling Services
The startup runlevels of the service/program can also be managed using the chkconfig utility.
To view all the runlevels in which the carpald.sh program is configured to start up, type
On a system running OpenSuSE Linux, the equivalent GUI program (see Figure 6-2) can be
launched by typing:
suse-serverA:~ # yast2 runlevel
On an Ubuntu system, the equivalent GUI tool (see Figure 6-3) can be launched by typing:
For example, to disable our “life-saving” carpald.sh program, you could type
[root@fedora-serverA ~]# chkconfig carpald off
If you check the list of runlevels for the carpald.sh program again, you will see that it has
been turned off for all runlevels. Type
[root@fedora-serverA ~]# chkconfig - - list carpald
carpald 0:off 1:off 2:off 3:off 4:off 5:off 6:off
To permanently remove the carpald.sh program from under the chkconfig utility’s control,
you will use chkconfig’s delete option. Type
[root@fedora-serverA ~]# chkconfig - - del carpald
We are done with our sample carpald.sh script, and to prevent it from flooding us with email
notifications in the future (in case we accidentally turn it back on), we can delete it from the
system for good. Type
[root@fedora-serverA ~]# rm -f /usr/local/sbin/carpald.sh
Press the power button on your system, and after few moments you see the Linux login
prompt.
Have you ever wondered what happens behind the scenes from the time you press the power
button until the Linux login prompt appears?
The following are the 6 high level stages of a typical Linux boot process.
1. BIOS
BIOS stands for Basic Input/Output System
Performs some system integrity checks
Searches, loads, and executes the boot loader program.
It looks for boot loader in floppy, cd-rom, or hard drive. You can press a key
(typically F12 of F2, but it depends on your system) during the BIOS startup to change
the boot sequence.
Once the boot loader program is detected and loaded into the memory, BIOS gives the
control to it.
So, in simple terms BIOS loads and executes the MBR boot loader.
2. MBR
MBR stands for Master Boot Record.
It is located in the 1st sector of the bootable disk. Typically /dev/hda, or /dev/sda
MBR is less than 512 bytes in size. This has three components 1) primary boot loader
info in 1st 446 bytes 2) partition table info in next 64 bytes 3) mbr validation check in
last 2 bytes.
It contains information about GRUB (or LILO in old systems).
So, in simple terms MBR loads and executes the GRUB boot loader.
3. GRUB
GRUB stands for Grand Unified Bootloader.
If you have multiple kernel images installed on your system, you can choose which
one to be executed.
GRUB displays a splash screen, waits for few seconds, if you don’t enter anything; it
loads the default kernel image as specified in the grub configuration file.
GRUB has the knowledge of the file system (the older Linux loader LILO didn’t
understand file system).
Grub configuration file is /boot/grub/grub.conf (/etc/grub.conf is a link to this). The
following is sample grub.conf of CentOS.
#boot=/dev/sda
default=0
timeout=5
splashimage=(hd0,0)/boot/grub/splash.xpm.gz
hiddenmenu
title CentOS (2.6.18-194.el5PAE)
root (hd0,0)
initrd /boot/initrd-2.6.18-194.el5PAE.img
As you notice from the above info, it contains kernel and initrd image.
So, in simple terms GRUB just loads and executes Kernel and initrd images.
4. Kernel
Mounts the root file system as specified in the “root=” in grub.conf
Kernel executes the /sbin/init program
Since init was the 1st program to be executed by Linux Kernel, it has the process id
(PID) of 1.
initrd stands for Initial RAM Disk.
initrd is used by kernel as temporary root file system until kernel is booted and the
real root file system is mounted. It also contains necessary drivers compiled inside, which
helps it to access the hard drive partitions, and other hardware.
5. Init
Looks at the /etc/inittab file to decide the Linux run level.
Following are the available run levels
0 – halt
1 – Single user mode
2 – Multiuser, without NFS
3 – Full multiuser mode
4 – unused
5 – X11
6 – reboot
Init identifies the default initlevel from /etc/inittab and uses that to load all appropriate
program.
If you want to get into trouble, you can set the default run level to 0 or 6. Since you
know what 0 and 6 means, probably you might not do that.
Typically you would set the default run level to either 3 or 5.
6. Runlevel programs
When the Linux system is booting up, you might see various services getting started.
For example, it might say “starting sendmail …. OK”. Those are the runlevel programs,
executed from the run level directory as defined by your run level.
Depending on your default init level setting, the system will execute the programs
from one of the following directories.
Run level 0 – /etc/rc.d/rc0.d/
Run level 1 – /etc/rc.d/rc1.d/
Run level 2 – /etc/rc.d/rc2.d/
Run level 3 – /etc/rc.d/rc3.d/
Run level 4 – /etc/rc.d/rc4.d/
Run level 5 – /etc/rc.d/rc5.d/
Run level 6 – /etc/rc.d/rc6.d/
Please note that there are also symbolic links available for these directory under /etc
directly. So, /etc/rc0.d is linked to /etc/rc.d/rc0.d.
Under the /etc/rc.d/rc*.d/ directories, you would see programs that start with S and K.
Programs starts with S are used during startup. S for startup.
Programs starts with K are used during shutdown. K for kill.
There are numbers right next to S and K in the program names. Those are the
sequence number in which the programs should be started or killed.
For example, S12syslog is to start the syslog deamon, which has the sequence number
of 12. S80sendmail is to start the sendmail daemon, which has the sequence number of
80. So, syslog program will be started before sendmail.
There you have it. That is what happens during the Linux boot process.
Global Options
Image Options
Kernel Options
lilo Command Options
1. Global Options
backup=backup-file
boot=boot-device
Sets the name of the device that contains the boot sector. boot defaults to the device
currently mounted as the root, such as /dev/hda2. Specifying a device, such
as /dev/hda (without a number), indicates that LILO should be installed in the master
boot record; the alternative is to set it up on a particular partition, such as /dev/hda2.
compact
Merges read requests for adjacent disk sectors to speed up booting. Use of compact is
particularly recommended when booting from a floppy disk.
default=name
Uses the image name as the default boot image. If default is omitted, the first image
specified in the configuration file is used.
delay=tsecs
Specifies, in tenths of a second, how long the boot loader should wait before booting
the default image. If serial is set, delay is set to 20 at a minimum. The default is not to
force-backup=backup-file
ignore-table
install=boot-sector
Installs the specified file as the new boot sector. If install is omitted, the boot sector
defaults to /boot/boot.b.
message=message-file
Specifies a file containing a message to be displayed before the boot prompt. The
maximum length of the file is 65,535 bytes.
nowarn
prompt
Automatically displays the boot prompt without waiting for the user to press the Shift,
Alt, or Scroll Lock key.
2. Image Options
alias=name
Provides an alternate name for the image that can be used instead of the name
specified with the label option.
image=pathname
Specifies the file or device containing the boot image of a bootable Linux kernel.
label=name
Specifies the name that is used for the image at the boot prompt.
lock
Tells LILO to record the boot command line and use it as the default for future boots
until it is overridden by a new boot command line. lock is useful if there is a set of
options that you need to enter on the boot command line every time you boot the
system.
3. Kernel Options
The following kernel options can be specified in /etc/lilo.conf as well as on the boot
command line:
append=string
Appends the options specified in string to the parameter line passed to the kernel.
This is typically used to specify certain hardware parameters. For example, if your
system has more than 64 MB of memory (i.e., more than your BIOS can recognize),
you can use append: append = "mem=128M"
initrd=filename
literal=string
noinitrd
Preserves the contents of /dev/initrd so they can be read once after the kernel is
booted.
ramdisk_size=n
Specifies the amount of memory, in kilobytes, to be allocated for the RAM disk. The
default is 4096, which allocates 4 MB.
root=root-device
The following list describes the lilo command options. Multiple options are given separately:
% lilo -q -v
-C config-file
-I label
Prints the path to the kernel specified by label to standard output or outputs an error
message if no matching label is found. For example:
% lilo -I linux
/boot/vmlinuz-2.0.34-0.6
-q
% lilo -q
linux *
test
-R command-line
Sets the default command for the boot loader the next time it executes. The command
executes once and then is removed by the boot loader. This option is typically used in
reboot scripts.
-t
Indicates that this is a test and does not really write a new boot sector or map file. It
can be used with -v to find out what LILO would do during a normal run.
-v
-V