[Войти] [Зарегистрироваться]

Наши друзья и партнеры

Беспроводные выключатели nooLite

Lines Club

Ищем достойных соперников.

Книги по Linux (с отзывами читателей)

Библиотека сайта или "Мой Linux Documentation Project"

Linux System Administrator's Survival Guide lsg04.htm

Previous Page TOC Next Page

Chapter 4


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.

<NOTE>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.<NOTE>

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:

  • IGNORECASE makes image names case insensitive. This parameter is active by default and should be left alone.

  • NO1STDIAG does not generate diagnostic messages when read errors are encountered in the boot loader. This parameter is disabled by default. It's best to leave it disabled unless you don't care about the error messages.

  • The NOINSTDEF parameter tells you that if the install option is omitted from the command line, don't install a new boot sector. Instead, modify the old one. This parameter is disabled by default.

  • ONE_SHOT disables the command line timeout if any key is pressed. This parameter is disabled by default.

  • READONLY prevents overwriting of the default command line sector of the map file. This parameter is disabled by default.

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.

<NOTE>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.<NOTE>

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.

<NOTE>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.<NOTE>

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.

<NOTE>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.<NOTE>

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.

<NOTE>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.<NOTE>

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


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

<NOTE>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<NOTE>

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.

<NOTE>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.<NOTE>

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.


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.

<NOTE>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.<NOTE>

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 Li>

Transfer interrupted!

Эта статья еще не оценивалась
Вы сможете оценить статью и оставить комментарий, если войдете или зарегистрируетесь.
Только зарегистрированные пользователи могут оценивать и комментировать статьи.

Комментарии отсутствуют