Linux System Administrator's Survival Guide lsg04.htm

Previous Page TOC Next Page



Chapter 4


LILO


Whenever you hear about Linux, you'll also hear about LILO. LILO is the boot loader Linux uses to load the operating system kernel. Whenever you change or move the Linux kernel, you must invoke LILO to rebuild a map of the kernel locations. LILO is versatile—it can boot Linux kernels from any type of filesystem, including floppy disk, as well as from other operating systems. This chapter looks at LILO, the way hard disks are laid out with Linux, the boot process, the most common boot processes, and LILO's interactions with each. This information should help you install and use LILO effectively.

Several versions of LILO are available. Most current versions support one of two different directory structures. The more traditional (and older) structure resides in the /etc/lilo directory. The newer structure has files scattered in several directories, including /etc, /sbin, and /boot. Because the older /etc/lilo structure is the most common, it is used for examples in this chapter. If you are using the new structure (check for the existence of /etc/lilo), substitute the new pathnames as necessary.

Installing LILO


Most systems will have LILO already installed and configured. If your system already has LILO installed, you can skip this section unless you want to update your version. A quick installation procedure is available with most versions of Linux to install a minimum set of LILO. This procedure is described in the file QuickInst.old or QuickInst.new, depending on the version of Linux. You can only use the QuickInst routines for a first-time LILO installation or to replace an existing LILO set. You cannot use them for updates as any existing configuration information is overwritten.

A full installation of LILO requires that all the files in the LILO distribution archive (usually called lilo.xxx.tar.gz where xxx is the version number) are extracted into a directory other than /etc/lilo. (Otherwise, installation will fail if the final destination is the same as the source directory.) After the distribution files are located in a temporary directory, follow these steps:

  1. Check the Makefile for valid configuration information (see the following LILO Makefile section).

  2. Compile LILO. If you want to use the older /etc/lilo directory structure, issue the first command that follows. If you want to use the new directory structure, issue the second command.
    make -f Makefile.old
    make -f Makefile.new
  3. Copy all the LILO files to the target directory with one of the following commands, depending on whether you selected the new or old directory structure:
    make -f Makefile.old install
    make -f Makefile.new install
  4. Check the directories. You should see the following files: any_d.b, boot.b, chain.b, disktab, lilo, os2_d.b. If the files do not exist or errors are generated in the process, restart the installation. Check the Makefile for accurate information. Once LILO has been installed properly, you can use it to install a boot process.



Before you can compile LILO for use, you have to configure the kernel by running make config. All kernel header files must be in the directory /usr/include/linux for LILO to compile properly. The LILO installation and compilation process should be run from a Bourne shell (or complete compatible). Problems have been reported with versions of the Korn shell when LILO is compiled, so use /bin/sh or /bin/bash.


Handling Disk Problems


Some systems may have difficulty with hard disks that do not allow the disk parameters (heads, sectors per track, and cylinders) to be read. If you get error messages about bad geometry or the LILO installation fails with disk errors, the disk parameters are a likely source of trouble, especially if you're dealing with SCSI disks and hard disks with a capacity of 1G or more.

In this case, you must manually enter the disk parameters into the file disktab. The section "Disk Parameter Table" later in this chapter discusses this step in more detail. Edit the disktab file as explained to include the disk parameters. Then test the new LILO configuration by copying it to a floppy disk and booting from it. Follow these steps:

  1. Change to the LILO directory (usually /etc/lilo).

  2. Execute the following command to copy the LILO configuration to the floppy. Substitute the kernel image name after the image parameter.
    echo image=kernel_name | ./lilo -C - -b /dev/fd0 -v -v -v
  3. Reboot your system from the floppy disk.

If the configuration is correct, LILO will read the floppy disk for the boot loader, and then load the kernel from the hard disk. If everything boots properly and you can move around the filesystem, the disk parameters are correct. If you can't access the hard disk filesystem, the parameters are incorrect and should be entered again.

Using the LILO Makefile


The LILO Makefile supplied with the LILO installation files is valid for most installations, although you should carefully check all the entries. LILO uses either the Makefile, which contains all the instructions for a C compiler to compile a binary from the source code, or another file called /etc/lilo/config.defines. If the config.defines file exists, Makefile is ignored. For most purposes, editing the Makefile is sufficient, although if you plan to use LILO a lot, the config.defines file is a better alternative because it isn't overwritten with new versions of LILO.

The Makefile has several parameters that control the compilation process. You may need to change some of the values, depending on your system requirements. Check the following parameters in the Makefile and ensure that the values they have set are what you want:


Updating LILO


If you want to update an existing version of LILO with a newer one, the process is the same as a first-time installation except that existing configuration files are renamed to .old. For example, chain.b is renamed to chain.old. If the new version of LILO behaves properly, you can delete the .old files. Whenever you update the version of LILO, you must update the boot sector to add the new locations and map file format. To update the boot sector, run LILO.

Linux and Hard Disk Layouts


To understand how LILO works, you must understand how a hard disk is laid out. You probably already know that a hard disk is essentially a set of concentric tracks, radiating out from the center of the disk platter. Each track is divided into a number of sectors.

Hard disks are identified by the number of platters (or more accurately, the number of heads; the number of platters can be greater than the number of heads because one or more surfaces, typically the top and bottom, might not be used for data storage), the number of tracks per inch of disk platter (measured radially), and the number of sectors per track. The capacity of each sector leads to the total capacity of the disk by multiplying by the number of sectors per track, the number of tracks, and the number of platters with heads.

Linux is usually integrally tied with DOS, so it is useful to look at the way DOS uses a hard disk. A single-purpose (single DOS operating system, for example) hard disk (and most floppy disks) has a boot sector, followed by a data area that includes an administrative block. The boot sector is the first sector on the hard disk and is read when the system starts to load the operating system. The boot sector contains a bootstrap to direct the machine to the startup routines. The data area stores files, including the operating system startup code. (A bootstrap is a short piece of code that tells the BIOS how to load the operating system. It essentially starts the operating system load process by providing the bare bones instructions necessary to read the operating system files from disk.)

Although the administrative block is usually part of the data area, users commonly cannot access it directly. Each file on the hard disk has an entry in the administrative block's tables that indicates the file's location in terms of the head, track, and sector and the file name. Other information, such as owner, permissions, date and time, is usually stored in the administrative block as well. In DOS, this information makes up the File Allocation Table (FAT); UNIX and Linux use the superblock or i-node tables. The administrative table is not usually read until the boot process has been started.

When the hard disk has lots of space, you will probably want to install more than one partition. Multiple partitions are especially useful if you want to support more than one operating system (DOS and Linux, for example) on the same hard disk. You can create up to four primary partitions on a DOS disk.



With some operating systems, you can have more than four partitions, but if you are using DOS on the hard disk, don't create more than four primary partitions. Doing so may cause DOS to improperly read any data in the DOS partition because DOS has a built-in limitation of four partitions per disk. DOS' FDISK can't handle more than that amount. If you need to provide more than four logical disk drives, you can use extended partitions. An extended partition is a primary partition that has been subdivided.

A partition table that contains the details of the partitions on the disk is written to the first sector (boot sector) of each hard disk (not each platter). This sector is sometimes called the Master Boot Record or MBR. Although the terms boot sector and MBR are often used interchangeably, MBRs differ from boot sectors in that MBRs contain partition information. In other words, you can call a hard drive's boot sectors MBRs, but floppy disks' boot sectors are never MBRs. Extended partitions also have partition tables written to their beginning sectors. A program called the map installer creates Linux boot sectors.

When a hard disk has several partitions, Linux refers to them by device numbers after the primary disk name, such as /dev/hda1, /dev/hda2, and so on. In this case, /dev/hda is the first hard drive (/dev/hdb would be the second, /dev/hdc the third, and so on). Within the first hard drive, the partitions are named /dev/hda1, /dev/hda2, and so on. A second hard disk called /dev/hdb has partitions called /dev/hdb1, /dev/hdb2, and so on. The disk names may have other letters, depending on the type of hard disk and its adapter. For example, a hard disk may be called /dev/sd1 instead of /dev/hda. Extended partitions would be numbered /dev/hda5, /dev/hda6, and so on because only four primary partitions, or /dev/hda4, are allowed.

The Boot Sector


To understand the Linux boot process, a look at the DOS boot sector is necessary. Figure 4.1 shows the DOS boot sector layout. The program code is the bootstrap to the operating system. The disk parameters include the File Allocation Table (FAT).

Figure 4.1.
The DOS boot sector layout.

Linux's LILO boot sector is similar to the DOS boot sector, except that the disk parameter section is not used and the boundaries between code sections are different. The differences between the two boot sectors can cause a problem for DOS if the Linux LILO boot sector is written to a DOS disk's Master Boot Record, because DOS won't be able to load properly. Figure 4.2 shows the Linux boot sector layout. The magic number referred to in this and the previous boot sector layout is a two-byte number used by some operating systems to verify that the sector read is the boot sector.

Figure 4.2.
The Linux LILO boot sector layout.

You could, in theory, use the Linux LILO boot sector to boot DOS, as the partition table area of the boot record could contain DOS' FAT, but in practice, the boot process usually fails. It is much better to use a boot sector written to the DOS partition.



Because the DOS and Linux LILO boot sectors differ, you should install DOS before Linux. Doing so ensures that the DOS boot sector is written to the hard disk. If you install Linux first and the Linux LILO boot sector is written to the hard disk, DOS cannot boot.

You can save the LILO boot sector on a boot floppy disk, in the Master Boot Record of the hard disk, on the boot sector of the Linux partition, or in the boot sector of an extended partition. You cannot store it in any non-Linux partition or on any hard disk other than the first. Note that although DOS cannot handle a boot sector in an extended partition, Linux can through extensions to fdisk or a utility program called activate.



A common problem with LILO is that it will write a LILO boot sector anywhere, even into locations that the operating system cannot access. Make sure you are writing your LILO boot sector to a valid location. If you have already installed Linux and are making changes, keep a boot floppy disk at hand.


The Boot Process


During the boot process, the boot sector is read to obtain the bootstrap for the operating system. In the case of DOS, the Master Boot record or boot sector is read, and then COMMAND.COM is loaded. COMMAND.COM is DOS' kernel.

Although usually the boot system is set up when the Linux installation process is followed, you may want to alter Linux's boot system. Depending on your requirements and machine hard drive configuration, you can take one of several approaches. The following sections look at a few of the typical configuration examples to show how you can modify the boot process. These sections begin by explaining the process to follow to install LILO manually, although you can often perform these processes automatically when installing the Linux software. This section looks at the automated installation process and its options later on. For now, though, the details of each alternative should help you decide how to install LILO on your system.

Installing a Dedicated Linux Hard Disk


With a dedicated Linux installation, or a Linux boot by default despite other operating systems on the hard disk, the Linux LILO boot sector can replace the Master Boot Record. LILO will then boot straight into Linux from the Master Boot Record without touching partition boot sectors. In some cases, though, you may have to explicitly specify the boot sector. In other words, you may have to specify boot=/dev/hda (or whichever device holds the modified master boot record) at the boot prompt if the default values do not work.



If you replace the Master Boot Record with LILO for a dedicated Linux system then later remove Linux, you will have to low-level format the hard drive or restore the old MBR before another operating system, such as DOS, can use the drive.

To install LILO as a dedicated Linux boot, follow these steps:

  1. Boot Linux as usual. Make sure you have a boot floppy disk in case of problems.

  2. Copy your existing Master Boot Record to a floppy disk in case of problems. The command to copy the MBR from the main drive (/dev/hda) to a floppy disk using 512 character blocks (the default) is
    dd if=/dev/hda of=/fd/MBR bs=512 count=1
  3. Use the setup or LILO installation program to copy LILO into the boot sector, setting LILO in the Master Boot Record.

  4. Reboot the machine to boot from the Master Boot Record.

Your machine should load Linux automatically. If Linux does not boot, use your boot floppy to start Linux and either repeat the process or restore the original Master Boot Record from the floppy disk using the command


dd if=/fd/MBR of=/dev/hda bs=446 count=1

Using BOOTACTV


A slight modification of the last boot process is replacing the normal MBR with a utility called BOOTACTV, which prompts for the partition to boot from. This utility requires that a non-DOS-compatible copy of the boot sector be written, so you should use it only when Linux will be the dominant operating system and LILO is not booting the other operating systems properly.

When in place, the Master Boot Record holds a copy of BOOTACTV. When booted, BOOTACTV enables you to choose which operating system to boot. BOOTACTV can then read a boot sector from a partition to load that operating system. When the MBR holds BOOTACTV, you can't use the MBR as you normally would with other operating systems, such as DOS or OS/2. You can, though, replace BOOTACT with a normal MBR.

To install BOOTACTV, follow these steps:

  1. Boot Linux as usual. Make sure you have a boot floppy disk in case of problems.

  2. Copy your existing Master Boot Record to a floppy disk in case of problems. The command to copy the MBR from the main drive (/dev/hda) to a floppy disk using 512 character blocks (the default) is
    dd if=/dev/hda of=/fd/MBR bs=512 count=1
  3. Use the setup or LILO installation program to copy LILO into the boot sector of the Linux partition (not the Master Boot Record).

  4. Install BOOTACTV into the Master Boot Record. The BOOTACTV utility is usually called bootactv.bin and should be in the current directory when you install it into the MBR with the command
    dd if=bootactv.bin of=/dev/hda bs=446 count=1
  5. Reboot the machine to boot BOOTACTV from the Master Boot Record.

Your machine should load BOOTACTV and allow you to boot any other operating system on a partition. If Linux or another operating system does not boot, use your boot floppy disk to start Linux. If only Linux doesn't boot, the boot sector LILO for the Linux partition is not working and can be rewritten using the setup or LILO configuration utilities. If none of the partitions boot, remove BOOTACTV by replacing the old Master Boot Record with the command


dd if=/fd/MBR of=/dev/hda bs=446 count=1

You can also reinstall the Master Boot Record from within DOS, if you have a DOS boot floppy disk. When in DOS, issue the command


fdisk /mbr


If you don't want to alter your Master Boot Record but have more than one partition dedicated to Linux, you can install BOOTACTV on one of the partition's boot sectors and use the fdisk utility to toggle the active partition. However, if the hard disk is repartitioned or the filesystems are altered in size, the boot sector will have to be rewritten. To write BOOTACTV to the fourth primary hard disk partition, for example, copy the existing MBR to the partition's boot sector, and then install BOOTACTV with the following commands:
dd if=/dev/hda of=/dev/hda4 bs=512 count=1
dd if=bootactv.bin of=/dev/hda4 bs=446 count=1



Installing DOS and Linux


Most Linux installations coexist with DOS and use the DOS Master Boot Record. In this case, the MBR is read and the active partition (set by fdisk) is booted automatically. This installation method is one of the safest because no changes to the DOS-installed Master Boot Record are performed, and it is easy to remove or reconfigure partitions at any time without worrying about compatibility with the MBR.



Later versions of DOS (6.00 or higher) will overwrite an existing MBR if they are installed after Linux. If this happens, you won't be able to boot Linux from the MBR, although DOS will boot. You can fix the problem by running LILO again or by making the Linux partition active.

You can change the active partition at any time using the fdisk utility or the Linux utility activate. The setup program within Linux can usually change the boot partition, too. Only one partition on a hard disk can be active at a time. Some operating systems, including Linux, let you change your mind about which operating system to boot after the active partition has been read, assuming a delay was built into the boot process. Linux, for example, can display the boot prompt and wait for a reply or a timeout to occur before starting to boot Linux.

To use this type of approach for Linux, install LILO into the boot sector of the Linux partition. To make it bootable, run fdisk and set that partition number as the active partition. Rebooting the machine will boot into the active partition. When Linux is replaced or removed, the boot sector of the new operating system will overwrite the Linux partition's boot sector, requiring no changes to the MBR.

Using BOOTLIN


With the Linux BOOTLIN configuration, which is also a common method of installation, the Master Boot Record does not change. During the boot process, the Master Boot Record is read, and then a decision about which operating system to load is made. This decision is usually based on a user prompt. Essentially, this boot process is the same as a normal DOS boot except the program BOOTLIN is invoked in either the CONFIG.SYS or AUTOEXEC.BAT files. This program can then execute a program that lets you choose the operating system to load. The program BOOT.SYS, for example, may be used to present a menu that enables you to choose between a Linux and DOS boot.

To install BOOTLIN in your DOS partition, follow these steps:

  1. Boot Linux. Make sure you have a boot floppy disk in case of problems.

  2. Place a copy of the Linux kernel in your DOS partition either through DOS or with one of the Linux Mtools. You only have to copy the kernel file into the home directory (or any subdirectory) of the DOS partition. You can even do this step from the floppy disk.

  3. Copy BOOT.SYS and BOOTLIN.SYS to the DOS partition, using the same process you used to copy the Linux kernel.

  4. Add both the BOOT.SYS and BOOTLIN.SYS files to your CONFIG.SYS file.

  5. Make sure DOS is the active partition, and reboot the machine.

When DOS starts, the BOOT device driver should give you the option of booting DOS or Linux. If you have problems, remove the BOOT.SYS and BOOTLIN.SYS files from the CONFIG.SYS file and you are back to normal.

Using the BOOT.SYS program has a useful advantage in that no boot sectors are altered to support several operating systems. As a result, loading and removing operating systems from a hard disk is easier. You can use both the Master Boot Record with active partition and BOOT.SYS approaches so that the hard disk starts to boot whichever operating system has the active flag, and then pauses and waits for confirmation from the user (or a timeout to occur). In this case, no changes to the Master Boot Record need to be made.

Automated LILO Creation


Most recent versions of Linux, including the one supplied on this book's CD-ROM, let you manage LILO through a menu-driven routine usually started through setup. Typically, when you have made any changes to the installation (such as adding new software), the last component of the setup program asks you whether you want to work with LILO. Figure 4.3 shows this screen.

Figure 4.3.
Whenever you make changes to Linux through the setup utility, it asks whether you want to use LILO.

From the menu-driven system shown in Figure 4.3, select the Begin option. Usually, the first thing the program asks for is any boot-time instructions that need to be specified when Linux starts, as shown in Figure 4.4. Normally, there are no boot-time instructions, but if you had to enter any parameters to start the Linux installation process, specify the same options here.

Figure 4.4.
The LILO installation process starts by asking whether you need any special boot-time instructions.

The next prompt, shown in Figure 4.5, asks where you want your LILO instructions written. The primary options were discussed earlier in the chapter. This version of LILO lets you select the Master Boot Record (MBR), the master sector of the primary Linux partition (called a superblock on this screen), or a floppy disk. The method you select depends on how you want Linux to start and whether it coexists with another operating system. For a minimal impact on your system, select the floppy disk boot option. This option requires you to place the boot floppy disk in the floppy disk drive when starting the machine, but then it boots cleanly into Linux. If the boot floppy disk is left out of the floppy disk drive, any other active partition (such as DOS or OS/2) is booted. Because the LILO instructions are only written to floppy disk with this approach, existing MBRs or partition boot sectors don't change at all. This approach makes it very easy to remove Linux and prevent problems with other operating systems that exist on your drives.

Figure 4.5.
You are asked where you want to install LILO.

If you are installing only Linux, or plan to have very rare use of existing DOS or OS/2 partitions, use the Master Boot Record of partition boot sector. The only drawback to this approach is that, you must low-level format your hard drive if you want to remove Linux in the future. The Linux MBR is not compatible with DOS'.

A compromise is to use the partition boot sector (superblock). This approach lets you boot straight into Linux when the partition is active or use fdisk to activate any other partition. Although this option has more impact than the floppy disk boot option, yo can easily remove it by reformatting the partition and installing a new operating system.



If you are installing Linux to experiment with it and you are not sure whether you will leave it on your hard drive, use the boot floppy disk. This option provides the most hassle-free approach for backing out of Linux in the future. You can always rerun LILO and write the boot instructions to the MBR or superblock later.

The LILO system asks you whether you want a delay before Linux starts to boot, as shown in Figure 4.6. You can decide to not pause, to wait either 5 or 30 seconds, or to wait until LILO is told explicitly to boot. This last option is useful if you have two operating systems on your hard drive because it saves you from fooling around with fdisk to alter the active partition. A good compromise is either 5 or 30 seconds.

Figure 4.6.
You can set a delay before booting into Linux with one of the options shown in this menu.

After you set the delay, LILO returns you to the main LILO menu (shown in Figure 4.3). The next step is to identify the partitions that LILO will know about. The menu lists three operating systems: DOS, OS/2, and Linux. If you have either DOS or OS/2, you can give the partition information to LILO to allow it to boot this operating system instead of Linux (assuming you have a delay in the boot process). Begin with the Linux operating system, though. Select Linux on the menu (the menu choices are in order of most common use from top to bottom, generally) to display the Linux partition information screen shown in Figure 4.7.

Figure 4.7.
Use this screen to identify the boot Linux partition. In this example, only a single Linux data partition exists.

The example shown in Figure 4.7 shows a single Linux data partition on the hard drive, called /dev/sda3. The Linux swap partitions never show up on these lists (unless they were misidentified when they were installed). Enter the name of the Linux partition that is to be used for the boot partition (in the example, /dev/sda3 would be typed in the entry field). The next screen, shown in Figure 4.8, asks for a name for this partition. This name is used to identify the partition at boot time. For Linux partitions, just enter the word Linux to provide an unambiguous name for the partition.

Figure 4.8.
You need to assign a name to the Linux partition.

After entering the partition name, you are back to the main LILO menu. Now, add any other operating systems, such as DOS or OS/2. To install a DOS partition, for example, select DOS from the menu. A screen very similar to the one for selecting the Linux partition appears, as shown in Figure 4.9. Enter the name of the DOS partition (in this case, /dev/sda1).

Figure 4.9.
When you add another operating system to LILO, the partitions that apply are displayed. You can add this partition to the LILO boot table.

After the partition has been identified, name the partition as shown in Figure 4.10. Again, a simple name is best, so enter DOS or OS/2 as applicable. Don't bother with fancy names; they are more trouble than they are worth!

Figure 4.10.
As with the Linux partition, you need to assign a name to the other partitions LILO will know about.

After you name all the partitions, you are brought back yet again to the LILO menu. The next step is to install the LILO information. Select the Install option from the menu. The system writes all the partition details you've supplied, and then you can exit LILO. The other options on the LILO menu allow you to modify an existing LILO table. In most cases, it's easier to just start again. You can use this automated LILO installation any time you want. Take care that you enter the proper information, though, as an error can make it impossible to access a partition. Keep an emergency boot disk handy!

Setting Boot Parameters


Regardless of which boot process you use, LILO pauses momentarily when Linux is booting to check that the Shift, Ctrl, and Alt keys are not pressed and that Caps Lock and Scroll Lock are set. If none of the keys are pressed and the locks are on, LILO displays the boot prompt. At this point, LILO is waiting for the name of the boot image to use to be entered. If a timeout occurs or Enter is pressed, the default boot image is loaded. The boot image is the kernel of whichever operating system is to be loaded, including DOS.

If you want to boot an image other than the default, you can enter its name at the boot prompt. To obtain a list of all known boot images, enter a question mark or hit the Tab key (depending on the image and keyboard setting). Recent versions of Linux set the boot image name in a LILO file, as described in the next section. With some earlier versions of Linux, the name of the default boot image is located in the file /etc/rc (or in a file in the subdirectory /etc/rc.d) on a line with the keyword


BOOT_IMAGE=

You also can specify parameters for the kernel by entering them at the boot prompt. Unless overridden, the parameters will be used by the default image when it boots. Valid parameters differ a little depending on the version of Linux, but most versions support the following:

As mentioned in the preceding list, you can use a hexadecimal device number in the root parameter. The device numbers are assigned depending on the type of device. For floppy disk drives, the numbers are assigned starting with 200: /dev/fd0 is 200, /dev/fd1 is 201, /dev/fd2 is 202, and so on. Hard disks have numbers assigned depending on the type of device. For most hard disks, the numbers start at 301 (not 300 because there is no /dev/hd0): /dev/hda1 is 301, /dev/hda2 is 302, and so on. When a second hard drive is used, the numbers jump to 340: /dev/hdb1 is 341, /dev/hdb2 is 342, and so on. For /dev/sda devices, numbering starts at 801: /dev/sda1 is 801, /dev/sda2 is 802, and so on. The second hard drive starts at 811: /dev/sdb1 is 811, /dev/sdb2 is 812, and so on. Because floppy disk and hard disk drives are usually the only devices that can act as a boot devices, these numbers should suffice for all occurrences except removable media.

You can combine parameters if you separate them with a space. At the boot prompt, the line


image5 root=/dev/hda2 single ro

will boot the kernel called image5 located on the device /dev/hda2, for example. The filesystem will be mounted as a read-only device, and single-user mode will be invoked.

The Map Installer


The map installer is the program that updates the boot sector and creates the map file. The map installer is usually the file /etc/lilo/lilo. Whenever the map installer is running, it checks for errors in the boot sector. If an error is detected, no changes to the boot sector are written, and the installer terminates.

When a boot sector is successfully updated by the map installer, the old boot sector contents are copied into the directory /etc/lilo with the name boot.hex_num where hex_num is the hexadecimal device number of the partition that was rewritten. The hexadecimal device numbers were mentioned in the previous section. When the map installer writes to a partition's boot sector, the old copy of the boot sector is stored in a file with the name part.hex_num. Again, hex_num is the number of the device.

You can modify the map installer's behavior by supplying command line parameters when the installer is invoked or by making entries in the configuration file /etc/lilo/config. On later versions of Linux, including the version supplied on the CD-ROM with this book, the file is /etc/lilo.conf. A sample /etc/lilo.conf looks like the following:


# LILO configuration file

# generated by 'liloconfig'

#

# Start LILO global section

boot = /dev/fd0

#compact # faster, but won't work on all systems.

delay = 50

vga = normal # force sane state

ramdisk = 0 # paranoia setting

# End LILO global section

# Linux bootable partition config begins

image = /vmlinuz

 root = /dev/sda3

 label = Linux

 read-only # Non-UMSDOS filesystems should be mounted read-only for checking

# Linux bootable partition config ends

# DOS bootable partition config begins

other = /dev/sda1

 label = DOS

 table = /dev/sda

# DOS bootable partition config ends

As you can see, this lilo.conf file uses a boot floppy disk to hold the LILO image (/dev/fd0) and avoids overwriting the MBR or superblock of a partition. The Linux partition is /dev/sda3 and is called Linux. A DOS partition, /dev/sda1, called DOS also exists on the hard drive. You can use many of the available options from either the LILO command line or the configuration file. The following sections discuss the configuration options.

Map Installer Command-Line Options


The LILO map installer utility accepts a number of options on the command line. Many of the command-line options are mirrored by configuration variables, discussed in the next section. The following list describes the command-line options:


Map Installer Configuration File Options


You can store configuration options for the map installer in the file /etc/lilo/config or /etc/lilo.conf (depending on the version of Linux). The file consists of sets of parameter-value pairs, although some options do not need a value. You can use whitespace between the parameter and the equal sign and between the equal sign and the value. You can include comments by starting the line with a pound sign. A new line character terminates the comment. As a rule, variable names are case insensitive, while values are usually case sensitive. It is good practice, though, to keep all entries lowercase (as is UNIX convention).

You can put the following options into the map installer configuration file /etc/lilo/config or /etc/lilo.conf:

If any parameter is not specified either on the command line or in the configuration file, default values are used. Some values are also maintained within the kernel image (such as ramdisk, root, and vga).

Boot Images


LILO can boot a kernel image from several locations, such as a regular file on the root filesystem or any other mounted filesystem, a block device such as a floppy disk, or the boot sector of another partition or disk. The type of boot is dictated by entries in a configuration file. Boot image configuration files can have several variables defined, all of which have been mentioned in the preceding sections. Valid configuration file variables include alias, label, optional, password, ramdisk, read-only, read-write, restricted, root, and vga.

To boot a kernel image from a file, all that is necessary in the configuration file is the name of the image. For example, the line


image=/linux_main

boots the image called linux_main.

To boot an image from another device, the sectors that must be read on that device have to be specified. Several methods of providing the sector information exist. The starting sector must be provided, but you can then either specify a number of sectors to be read (start+length) or the end sector number (start-finish). If only one number is provided (the start sector), only that sector is read.

For example, the contents of this configuration file


image=/dev/fd0

 range=1+512

will boot the kernel from the floppy disk, starting at sector 1 and reading the next 512 sectors.

You can specify more than one configuration for an image because LILO stores values in an image descriptor file and not in the image itself. For example, a configuration file can contain the following entries:


image=/linux_main

 label=linux-hda1

 root=/dev/hda1

image=/linux_main

 label=linux-hda3

 root=/dev/hda3

image=/linux_main

 label=linux-flop

 root=/dev/fd0

This code has three configurations for the same Linux kernel (linux_main), but it also has different root devices with three different alternate names. The boot devices for the image are /dev/hda1, /dev/hda3, and /dev/fd0 respectively. Whitespace in the configuration file is ignored, so the indentations are for ease of reading only.

Disk Parameter Table


LILO is usually able to obtain information about the hard disks and floppy disks on the system by reading the kernel. On some systems(especially some SCSI adapters and adapters that do not behave as IDE or SCSI normal devices), though, this isn't possible. When LILO can't obtain the disk parameter information, it generates an error message about "bad geometry."

The disk parameters can be physically read by LILO from the file /etc/lilo/disktab, which exists only with some versions of Linux. When the disktab file exists, it takes precedence over any auto-detected values. The disktab file contains the device number (hexadecimal), its BIOS code, and the disk geometry. A sample disktab file could have the following entries:


# /etc/lilo/disktab - LILO disk paramter table

#

# Dev. num BIOS code Secs/track Heads/cyl Cyls Part. Offset

#

 0x800 0x80 32 64 1714 0

 0x801 0x80 32 64 1714 1001

This example shows a SCSI disk with two partitions. The first partition /dev/sda1 has a device number 800, and the second partition /dev/sda2 has the device number 801. Both partitions have the BIOS code 80. Both the device number and BIOS code have to be given in hex format, which accounts for the leading 0x. The disk has 32 sectors per track, 64 heads per cylinder, and 1714 cylinders. Because both partitions are on the same disk, these parameters will be the same.

The partition offset is an optional field. The first partition starts at offset 0, and the second starts at offset 1001 (the number of sectors from the start of the disk). The partition offsets need only be explicitly given when the kernel cannot obtain that information. Most hard disks (including removable and optical disks) don't need the partition offsets, but CD-ROMs sometimes do.



When filling in the /etc/lilo/disktab file you don't have to have the details exactly right. Most systems will remap the drive parameters to 32 sectors per track and 64 heads, whether those numbers are correct or not. (This is a BIOS action.) The number of cylinders must be at least equal to or higher than the number of actual cylinders to avoid truncation of the disk space the operating system recognizes.

Some BIOS versions will not allow disks exceeding certain values. This problem usually occurs with IDE and SCSI controller cards that are designed for DOS systems with relatively small (<1G) disk drives and older BIOSs. Device drivers allow some high-capacity drives to be used, although some systems will have a problem accessing files beyond the 1G limit.

Removing or Disabling LILO


To prevent LILO from booting the system, you must disable the boot sector (by using fdisk to change the active partition) or remove it completely. Most versions of LILO can be quickly disabled with the command


/etc/lilo/lilo -u

If you are using the newer directory structure, substitute the pathname as necessary. Some later versions of LILO use the menu-driven setup utility instead of a lilo binary. In most cases, there is a file called /etc/lilo/install that can accomplish the same procedures.

When removing a LILO boot sector in the Master Boot Record of the disk, you must replace the MBR with another record. If you want to replace the MBR with a DOS MBR, from a booted DOS floppy disk, enter the command


fdisk /mbr

Because backup copies of the boot sector are created whenever LILO creates a new version, you can copy the older versions of the boot sector back in place (assuming they are still available). For example, to restore the Master Boot Record saved in a file called boot.0800 (800 is the device number of a SCSI drive), issue the command


dd if=/etc/lilo/boot.0800 of=/dev/sda bs=446 count=1

If you are using another device, substitute the name of the saved boot file and the device name.

Troubleshooting LILO


LILO displays error messages when it can't function properly. These error messages should be sufficient to identify the problem. The most common error messages and their solutions are shown in Table 4.1.

Table 4.1 Common LILO error messages.

Message Solution
Can't put the boot sector on logical partition X LILO attempted to put the boot sector on the correct root filesystem on a logical partition. MBRs can only boot primary partitions by default. Override with the -b option and an explicit boot partition value, or use the configuration variable boot=device.
Got bad geometry The disk controller (mostly SCSI) doesn't support automatic geometry detection. Use the file /etc/lilo/disktab to provide the disk parameters.
Invalid partition table, entry X The sector/head/cylinder and linear addresses of the first sector of the partition don't match. This error usually occurs when an operating system creates partitions not aligned to tracks. Try the fix-table option.
First sector doesn't have a valid boot signature The first sector of the device doesn't seem to be a valid boot sector. Check the device name or rerun LILO to install the boot sector.
Cylinder number is too big A file is located beyond the 1024th cylinder, which LILO can't access because of BIOS limitations. In most cases, the extra disk space is lost.
XXX doesn't have a valid LILO signature XXX was located but it isn't a valid LILO entry. If XXX is the boot sector, use the -i option or the install option to install the LILO boot sector.
XXX has an invalid stage code The entry at XXX is corrupted. Rerun LILO.
Kernel XXX is too big. The kernel is larger than 512K, which LILO can't handle. Remove some unused drivers and recompile the kernel.
Partition entry not found The partition is not in the partition table. Use fdisk to enter the partition number in the partition table.
Sorry, don't know how to handle device XXX LILO can't determine the disk parameters. Use the file /etc/lilo/disktab to specify them.

Summary


This chapter should include all the information you need to install and use LILO to create your boot sectors for Linux. LILO is quite versatile and can handle several different configurations with ease. It allows you to tailor your installation to boot the best way for your use.

Although LILO is only used when first setting up your Linux system and after kernel changes, you should know the basics of its operation so you know what is happening to your hard disks and their boot sectors. knowing about LILO is especially important when you use other operating systems in addition to Linux on the same system.

Previous Page Page Top TOC Next Page