LILO (Linux Loader) and GRUB (GRand Unified Bootloader) are both configured as a primary boot loader (installed on the MBR) or secondary boot loader (installed onto a bootable partition). Both work with supporting operating systems such as Linux, FreeBSD, Net BSD, and OpenBSD. They can work with unsupported operating system, such as Microsoft Windows XP, in the configuration file. Both allow users—root users—to boot into single-user-mode.
LILO comes as standard on all distributions of Linux. To work with LILO an administrator edits the file /etc/lilo.conf to set a default partition to boot, the time-out value, which choices should appear in a menu, kernel parameters, which partition to mount as the root partition, whether or not to initially load a RAM disk, where LILO should be installed, and other information. The administrator must then update the loader by running the LILO command.
The configuration file, by default is read by LILO. The configuration file tells LILO where it should place its boot loader. In general, you can either specify the master boot record (MBR) on the first physical disk (/dev/hda) or the root partition of your Linux installation (/dev/hda1 or /dev/hda2). The first stage of loading LILO is completed when LILO brings up in order of the each of the letters—L-I-L-O. When you see the LILO prompt, you are in the second stage.
If you have WINXP installed to MBR on your hard drive, install LILO to the root partition instead of the MBR. If you want to boot up Linux, you must mark the LILO partition as bootable. If you don't overwrite the master boot sector, you'll find it easier to uninstall Linux and LILO.
If you are starting with LILO, you can begin editing the configuration file. For existing Linux users migrating to LILO, you should get the latest version of LILO. Before you try LILO, you should have an emergency Linux boot disk in case you have problems booting the system from the hard disk, a CD-ROM, or another storage device. After you install LILO on your system, you can make it take over your MBR. As a root user, type:
# /sbin/lilo –v -v
Given below is a sample /etc/lilo.conf file. You should follow the naming conventions like Linux (for kernel 2.6.23-13). You can have many kernel images on the same /boot system. Get the latest Linux kernel versions before you try out the configuration file.
For other parameters, refer to the manual pages (man lilo.conf).
boot=/dev/hda map=/boot/map install=/boot/boot.b prompt timeout=50 compact default=Linux image=/boot/vmlinuz-2.6.23-13 label=Linux read-only root=/dev/hdb3 password=Linux image=/boot/vmlinuz-2.4.18-14 label=ker2418 read-only root=/dev/hdb3 other = /dev/hda label = WindowsXP
boot = option tells LILO to install the boot loader to the MBR of the first hard disk. The
map = and
install = options point to the files that LILO uses internally during bootup. Do not change these files.
When booting, the boot loader will wait five seconds for you press Shift. If you don't, then Linux, the first kernel, will be booted. If you do, the boot loader will ask you which image to boot. If you forgot the possible choices, press TAB and you will be presented with a menu. You now have the choice of booting Linux, ker2418, or WindowsXP. After you make your selection, you will find the
compact option speeds up the booting process. Loading Linux prompts you to enter a password for the image. You can add the
fallback=<command_line> option to any image. This option specifies that is stored as the default command line if the current image is booted. If using the fallback option, the next reboot will load a different kernel.
Since lilo.conf is not read at boot time, the MBR needs to be "refreshed" when it is changed. Like getting LILO into the MBR, you need to run:
$ /sbin/lilo –v -v
When you install Microsoft Windows on a computer that has the Linux operating system installed, Windows may overwrite or deactivate the Linux boot manager. As a result, you can no longer access the Linux operating system.
Here's how to fix the problem. If LILO was installed to the MBR, restart the computer using a bootable Linux floppy disk and then run LILOCONF program from the floppy drive. If LILO was installed to the superblock, use the FDISK command to activate the Linux partition.
Another possible solution is to delete the Linux partitions on a Windows-based computer, restart the computer, and then use Partition Magic to create Linux partitions. This utility comes with BootMagic, which allows you to switch operating systems.
To allow Linux system fixes, you can enter rescue at the boot prompt to boot Linux into single-user mode. Similar to rescue, you can also enter single to try to boot from your hard drive. You can also use
root=<device>to allow you to boot from a CD-ROM.
GRUB combines installations with one install command and allows for MD5 encryption of passwords. When a configuration file is configured incorrectly, the system reverts to the command-line prompts.
If you have WINXP installed to MBR on your hard drive, install GRUB to the root partition instead of the MBR. Better yet is the grubinstall.exe, a GRUB installer for Windows. This program configures the GRUB so that it can be installed inside an NTFS or FAT partition on Windows NT/2K/XP, and can be loaded from the default bootloader NTLDR. This means that you can safely install this bootloader and remove it, without ever touching the MBR and risking any problem with your disk.
For existing Linux users wanting to migrate to GRUB, get the latest version of GRUB. Before you try GRUB, you should have an emergency Linux boot disk in case you have problems of booting the system from a hard disk or another storage device. After you install GRUB, you can make it take over your MBR. Do this at the prompt as a root user:
Now, you can use the GRUB command
grub> install (hd1,2)/boot/grub/stage1 (hd1) (hd1,2)/boot/grub/stage2 p (hd1,2)/boot/grub/menu.conf
While this is a bit hard to read at first glance, it is more efficient than the LILO counterparts. Installation of stage one and two images and the configuration are combined with one install command. Let's take a look at the installation of the first stage in the install command:
install (hd1,2)/boot/grub/stage1 (hd1)
What this says is that GRUB is installing the first stage image on the third partition of the second disk (Linux), counterpart to LILO's hdb3. It is also installing to MBR on this same disk.
In the second part of the command, the stage two image is installed:
Finally, the installation is complete with the optional location of the configuration file:
Given below is a sample /boot/grub/grub.conf file.
default=0 timeout=10 splashimage=(hd1,2)/grub/splash.xpm.gz password --md5 [encrypted password] title Linux password --md5 [encrypted password] root (hd1,2) kernel /vmlinuz-2.6.23-13 ro root=LABEL=/ initrd /initrd-2.6.23-13.img title Windows XP password --md5 [encrypted password] rootnoverify (hd0,0) chainloader +1
default = option tells GRUB which image to boot by default after the timeout period. The
splashimage option specifies the location of the image for use as the background for the GRUB GUI. The
password option specified the MD-5 password to gain access to GRUB's interactive boot options. To generate an md5 password, run the tool
grub-md5-crypt as root. Copy this into your grub-conf password—md5. You can create separate passwords for each entry in the file. The
initrd option specifies the file that will be loaded at boot time as the initial RAM disk.
rootnoverify option tells GRUB to not try to vary the root of the OS. The
chainloader+1 tells GRUB to use a chain loader to load Windows on the first partition of the first disk. It uses the blocklist notation to grab the first sector of the current partition with '
For other parameters refer to grub man pages.
GRUB supports a fallback mechanism of booting one or more other entries if a default boot entry fails.
Suppose that you have three systems, "A," "B," and "C." "A" is a system that you want to boot by default. "B" is a backup system, which is supposed to boot safely. "C" is another backup system, which is used in cases where "B" is not working properly.
Let's suppose you want GRUB to boot the first system that is bootable among "A," "B," and "C." To do this, write configuration file like this:
default saved timeout 10 fallback 1 2 title A root (hd0,0) kernel /kernel savedefault fallback title B root (hd1,0) kernel /kernel savedefault fallback title C root (hd2,0) kernel /kernel savedefault
GRUB will boot a saved entry by default and save a fallback entry as next boot entry.
When GRUB tries to boot "A', GRUB saves "1' as next boot entry, because the fallback command
specifies that "1' is the first fallback entry. The entry "1' is "B', so GRUB will try to boot "B" at next boot time if "A" fails.
Likewise, when GRUB tries to boot "B," GRUB saves "2" as next boot entry, because fallback specifies "2" as next fallback entry. GRUB will boot "C" after booting "B."
You need to run
grub-set-default when "A" starts correctly or you fix "A" after it crashes, since GRUB always sets next boot entry to a fallback entry. You should run this command in a startup script such as rc.local to boot "A" by default:
# grub-set-default 0
where "0" is the number of the boot entry for the system "A."
Let's suppose you installed GRUB, a third party boot manager program, on a Windows XP-based machine. When you try to start this computer after an unsuccessful upgrade to Windows Vista, the computer does not start. Instead, a black screen appears together with a blinking underscore. The Windows Vista Setup program does not restore GRUB.
To fix this problem, use the Windows XP Recovery Console to write a new boot sector to the system partition. To do this, follow these steps:
LILO is older and less powerful. Originally LILO did not include a GUI menu choice (but did provide a text user interface). To work with LILO an administrator has many tasks to perform in addition to editing the configuration files.
GRUB is a bit easier to administer because the GRUB loader is smart enough to locate the /boot/grub/grub.conf file when booting. An administrator only needs to install GRUB once, using the "grub-install" utility. Any changes made to grub.conf will be automatically used when the system is next booted. In contrast, any changes made to lilo.conf are not read at boot time. The MBR needs to be "refreshed."
Like GRUB does, LILO has no interactive command interface and does not support booting from a network. If LILO MBR is configured correctly, the LILO system becomes unbootable. If the GRUB configuration file is configured incorrectly, it will default to the GRUB command-line interface without risking of making the system unbootable.
LILO and GRUB allows users—the root users—to boot into single-user mode. Both have a password protection feature with a difference. While GRUB allows for MD5 encrypted passwords, LILO manages only text passwords, which anyone can read from the lilo.conf file with the command
For the novice, start with LILO and then migrate to GRUB.
Judith Myerson is a systems architect and engineer. Her areas of interest include enterprise-wide systems, database technologies, network & system administration, security, operating systems, programming, desktop environments, software engineering, web development, and project management. You can contact her at firstname.lastname@example.org
Return to LinuxDevCenter.
Copyright © 2009 O'Reilly Media, Inc.