Linux System Administration: Using LILO, The Linux Loader

This excerpt from Essential System Administration describes useful details of booting Linux on a PC.

In general, the boot process on a microcomputer has three stages: the system's master boot record (MBR) contains the primary boot program which starts the boot process and loads a secondary boot program from the boot blocks of the active partition; this second boot program is what loads the actual kernel.

Linux provides LILO, the Linux Loader, which can function as either a master boot program or a secondary boot program. lilo is installed with a command like this one:

# lilo -C /etc/lilo.conf

The -C option specifies the location of LILO's configuration file. (The location in the preceding command is, in fact, the default location, and so the -C clause is redundant.)

The lilo.conf file specifies LILO's behavior for certain aspects of the boot process and also defines the kernels and operating systems that it can boot. The following excerpt from a lilo.config file lists the most important entries—and the ones that you are most likely to want or need to modify:

# Wait 10 seconds before autobooting 1st entry.timeout=100
# Allow user to enter a boot command.
# Where to install/configure LILO
# (no partition #=MBR) [see below]
# Text file displayed before boot prompt.
message = /boot/boot.message
# Default kernel is the first one listed.
image = /vmlinuz
# Boot prompt command to boot this kernel.
  label = linux
# Fix for Sony CD-ROM (post 1.1.72)
# Specifies parameters to pass to kernel,
# changing CD-ROM's compiled-in I/O address.
  append = "cdu31a=0x340,0,"
# An alternate Linux kernel
image = /safe
# Its boot command
  label = safe
  append = "cdu31a=0x340,0,"
# A different operating system (DOS)
other = /dev/hdb1
# Use the D: drive boot loader.
  loader = /boot/any_d.b
# Use this partition table.
  table = /dev/hdb
# This is the corresponding boot command.
  label = ddog

[I tend to install LILO both in the MBR and the Linux partition for maximum flexibility, by running a second LILO command using its -b option (which replaces the boot entry in the configuration file):# lilo -b /dev/hda1 -C /etc/lilo.confThis way, if I decide to remove LILO from the MBR, I'll be all set to switch over to the Linux partition version.]

The final section (“stanza”) illustrates the format for booting a DOS partition on the second hard disk; it uses an alternate loader, any_d.b, which tricks DOS into thinking it's on the C: drive. There are also loaders provided for OS/2 on the D: drive and DOS on the B: drive (os2_d.b and any_b.d, respectively; chain.b is the default loader for other operating systems).

If the label for a stanza is omitted, it defaults to the final component of the image or other entry (for example, vmlinuz or hda1).

The entry for a DOS partition on the C: drive is simpler, looking something like this:

other = /dev/hda1  label = dos
  table = /dev/hda

This stanza is actually what you need for any foreign operating system on /dev/hda1. There is one additional trick needed if SCO Unix is the operating system you want to boot. In order for LILO to successfully boot a SCO Unix partition, that partition must be the only active partition on the C: drive. This means you will have to turn off the active (boot) flag on the Linux partition and turn it on for the SCO Unix partition, using the Linux fdisk or cfdisk, before trying to boot SCO Unix (in addition to running LILO to install the new configuration). Note that LILO must be the master boot loader in this case.

Note: You will need to rerun the LILO command to reinstall it every time you rebuild the kernel or change any relevant aspect of the disk partitioning scheme. If you forget to do this, the system will not boot and you'll have to boot from a floppy. You will also need to rerun LILO if you change the text of the boot.message file.

More Complex Booting Scenarios

Booting a Linux partition on the second hard drive is also possible. For this to work, LILO must be installed in the MBR of the system's boot disk, as well as the secondary boot program in the Linux partition itself—this is usually taken care of when you install Linux on the hard disk and will be assumed in what follows. In this case, the best way to proceed is in two stages:

  • First, set up a lilo.conf like this one:

  • Define all of the partitions on both hard disks in the same way; the unsafe keyword tells LILO not to read the boot blocks or the disk's partition table for that entry—it basically says, “Trust me and do what I tell you.” Install this LILO configuration, and make sure that Linux is bootable.

  • Then, modify the file, changing entries for any bootable partitions on /dev/hda to their correct form and removing ones you don't need, and rerun the LILO command.

It is also possible to boot a Linux partition on each of two disks. The procedure for doing so is the following:

  • Decide which one will be the usual Linux boot partition and set up LILO to boot it and any other non-Linux operating systems on both disks. Create an entry like the following for the second Linux partition:

    other = /dev/hdb2  label=eviltwin
  • Create a boot.message file which tells you which Linux will be booted when you select the default option. Install this configuration into the MBR on the C: drive.

  • Create (or retain) another LILO configuration for the second Linux partition, this time including an unsafe entry for the first Linux partition if you want to (this again assumes that LILO is installed in that partition, which usually happens at upon installation of the OS). Make sure that this partition's boot.message file also lets you know where you are. Install this configuration into the Linux partition only—make sure that the boot entry specifies the partition and not the disk as a whole.

    The boot sequence will then go something like this:

    Welcome to gallant.Boot choices: linux (default; on C:), dos,
     eviltwin (Linux on D:), sco
    boot: eviltwin
    Welcome to goofus.
    Boot choices: test (default; on D:),  goodtwin (Linux on C:)
    boot: [Return]
    Loading test...

Given these selections, Linux will boot from the D: drive. What happens is the LILO from the MBR on drive C: runs first, and it then starts the boot program on the Linux partition on the D: drive—which is again LILO. That (second) LILO then loads the kernel from the D: drive. (Note that if you wanted to, you could just keep popping back and forth between the LILO programs on C: and D: ad infinitum.)

If you think this is pretty silly, then omit the prompt keyword from the LILO configuration file for the D: drive (as well as its image section for the Linux partition on the C: drive), resulting in a simple lilo.conf file on the D: drive:


Once this is installed, selecting eviltwin at the initial boot prompt will immediately boot the Linux partition on the second hard disk.


Geek Guide
The DevOps Toolbox

Tools and Technologies for Scale and Reliability
by Linux Journal Editor Bill Childers

Get your free copy today

Sponsored by IBM

Upcoming Webinar
8 Signs You're Beyond Cron

Scheduling Crontabs With an Enterprise Scheduler
11am CDT, April 29th
Moderated by Linux Journal Contributor Mike Diehl

Sign up now

Sponsored by Skybot