LILO Generic boot loader for Linux

Werner Almesberger

             almesber@nessie.cs.id.ethz.ch

March 8, 2004

LILO is a versatile boot loader for Linux. It does not depend on a specfic file system, can boot Linux boot images and unstripped Linux kernels from floppy disks and from hard disks and can even boot other operating systems^{1}.

Up to sixteen different boot images can be selected at boot time. The root and swap device can be set independently for each of them. LILO can even be used as the master boot record.

This document introduces the basics of disk organization and booting, continues with an overview of common boot techniques and finally describes installation and use of LILO in greater detail.

1 Disk organization

When designing a boot concept, it is important to understand all the subtleties of how MS-DOS organizes disks. The most simple case are floppy disks. They consist of a boot sector, some administrative data (FAT or super block, etc.) and the data area. Because that administrative data is irrelevant as far as booting is concerned, it is added to the data area for simplicity.

Boot sector Data area

The entire disk appears as one device (i.e. /dev/fd0) on Linux.

The MS-DOS boot sector has the following structure:

1MS-DOS, DR DOS, OS/2, 386BSD, …

0x000 Jump to the program code

                     0x003

Disk parameters

               0x02C/0x03E

Program code

0x1FE Magic number (0xAA55)

LILO uses a similar boot sector, but it does not contain the disk parameters part. This is no problem for Minix or EXT file systems, because they don’t look at the boot sector, but putting a LILO boot sector on an MS-DOS file system makes it inaccessible for MS-DOS.

Hard disks are organized in a more complex way than floppy disks. They contain several data areas called partitions. Up to four so-called primary partitions can exist on an MS-DOS hard disk. If more partitions are needed, a primary partition is used as an extended partition that contains several logical partitions.

The first sector of each hard disk contains a partition table and an extended partition and each logical partition contains a partition table too.^{2}

Partition table /dev/hda Partition 1 /dev/hda1

Partition 2 /dev/hda2

The entire disk can be accessed as /dev/hda, /dev/hdb, /dev/sda, etc. The primary partitions are /dev/hda1 … /dev/hda4.

2Is it legal to have more than one extended partition ? Linux appears to be able to handle this, but is DOS ?

Partition table /dev/hda Partition 1 /dev/hda1

Partition 2 /dev/hda2

Extended partition /dev/hda3 Extended partition table Partition 3 /dev/hda5

Extended partition table

Partition 4 /dev/hda6

This hard disk has two primary partitions and an extended partition that contains two logical partitions. They are accessed as /dev/hda5 …

Note that the partition tables of logical partitions are not accessible as the first blocks of some devices, while the main partition table, all boot sectors and the partition tables of extended partitions are.

Partition tables are stored in partition boot sectors. Only the partition boot sector of the entire disk is usually used as a boot sector. It is also frequently called the master boot record (MBR).

                   0x000

Program code

0x1BE  Partition table
0x1FE Magic number (0xAA55)

The LILO boot sector is designed to be usable as a partition boot sector. Therefore, the LILO boot sector can be stored at the following locations:

• boot sector of a Linux floppy disk. (/dev/fd0, …)

• MBR of the first hard disk. (/dev/hda, …)

• boot sector of a Linux primary partition on the first hard disk. (/dev/hda1, …)

• partition boot sector of an extended partition on the first hard disk.

     (/dev/hda1, . . .)^{3}

3Most FDISK-type programs don’t believe in booting from an extended partition and refuse to activate it. LILO is accompanied by a simple program that doesn’t have this restriction.

It can’t be stored at any of the following locations:

• boot sector of a non-Linux floppy disk of primary partition.

• a Linux swap partition.

• boot sector of a logical partition in an extended partition.

• on the second hard disk. (Unless for backup installations or if the current first disk will be removed or disabled.)

2 Booting basics

When booting from a floppy disk, the first sector of the disk, the so-called boot sector, is loaded. That boot sector contains a small program that loads the respective operating system. MS-DOS boot sectors also contain a data area, where the disk parameters (number of sectors, number of heads, etc.) are stored.

When booting from a hard disk, the very first sector of that disk, the so-called Master boot record (MBR) is loaded. This sector contains a loader program and the partition table of the disk. The loader program usually loads the boot sector, as if the system was booting from a floppy.

Note that there is no functional difference between the MBR and the boot sector other than that the MBR contains the partition information but doesn’t contain any (MS-DOS) disk parameter information.

The first 446 (0x1BE) bytes of the MBR are used by the loader program. They are followed by the partition table, with a length of 64 (0x40) bytes. The last two bytes contain a magic number that is sometimes used to verify that a given sector really is a boot sector.

There is a large number of possible boot configurations. The most common ones are described in the following sections.

2.1 MS-DOS alone

Master Boot Record Boot sector

Operating system

DOS-MBR ⟶ MS-DOS ⟶ COMMAND.COM

This is what usually happens when MS-DOS boots from a hard disk: the DOS-MBR determines the active partition and loads the MS-DOS boot sector. This boot sector loads MS-DOS and finally passes control to COMMAND.COM. (This is greatly simplified.)

2.2 BOOTLIN

Master Boot Record Boot sector

Operating systems

DOS-MBR ⟶ MS-DOS ⟶ COMMAND.COM
⟶ BOOTLIN ⟶ Linux

A typical BOOTLIN setup: everything happens like when booting MS-DOS, but in CONFIG.SYS, BOOTLIN is invoked. This approach has the pleasent property that no boot sectors have to be altered.

Installation:

• boot Linux.

• copy a bootable kernel image to your MS-DOS partition.^{4}

• install BOOT.SYS and BOOTLIN.SYS on your MS-DOS partition and add them to your CONFIG.SYS. (The READMEs describe how this is done.)

• reboot.

Deinstallation:

   • remove BOOT.SYS and BOOTLIN.SYS from your CONFIG.SYS.

2.3 LILO started by DOS-MBR

Master Boot Record Boot sector

Operating system

DOS-MBR ⟶ LILO ⟶ Linux
⟶ other OS

This is a “safe” LILO setup: LILO is booted by the DOS-MBR. No other boot sectors have to be touched. If the other OS (or one of them, if there are several of them) should be booted, the other partition has to be marked “active” with (e)fdisk.

Installation:

• install LILO with its boot sector on the Linux partition.

• use (e)fdisk to mark that partition active.

• reboot.

Deinstallation:

• mark a different partition active.

• install whatever should replace LILO or Linux.

4With Mtools or the MS-DOS FS.

2.4 Several alternate branches

Master Boot Record Boot sector

Operating systems

DOS-MBR ⟶ MS-DOS ⟶ COMMAND.COM
⟶ BOOTLIN ⟶ Linux
⟶ LILO ⟶ Linux
⟶ MS-DOS — ⋯

An extended form of the above setup: the MBR is not changed and both branches can either boot Linux or MS-DOS. (LILO could also boot any other operating system.)

2.5 LILO started by BOOTACTV

Master Boot Record Boot sector

Operating system

BOOTACTV ⟶ LILO ⟶ Linux
⟶ other OS

Here, the MBR is replaced by BOOTACTV (or any other interactive boot partition selector) and the choice between Linux and the other operating system can be made at boot time. This approach should be used if LILO fails to boot the other operating system(s).^{5}

Installation:

• boot Linux.

• make a backup copy of your MBR on a floppy disk, e.g.

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

• install LILO with the boot sector on the Linux partition.

• install BOOTACTV as the MBR, e.g.

     dd if=bootactv.bin of=/dev/hda bs=446 count=1

• reboot.

Deinstallation:

• boot Linux.

• restore the old MBR, e.g.

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

5And the author would like to be notified if booting the other operating system(s) doesn’t work with LILO, but if it works with an other boot partition selector.

If replacing the MBR appears undesirable and if a second Linux partition exists (e.g. /usr, not a swap partition), BOOTACTV can be merged with the partition table and stored as the “boot sector” of that partition. Then, the partition can be marked active to be booted by the DOS-MBR.

Example:

# dd if=/dev/hda of=/dev/hda3 bs=512 count=1
# dd if=bootactv.bin of=/dev/hda3 bs=446 count=1

Warning: whenever the disk is re-partitioned, the merged boot sector on that “spare” Linux partition has to be updated too.

2.6 Shoelace started by BOOTACTV

Master Boot Record Boot sector

Operating system

BOOTACTV ⟶ Shoelace ⟶ Linux
⟶ other OS

Shoelace, LILO’s predecessor, can be started by BOOTACTV as well, of course. The same indirection as outlined above is possible. There are probably many other ways to install Shoelace.

2.7 LILO alone

Master Boot Record Operating system

LILO ⟶ Linux
⟶ other OS

LILO can also take over the entire boot procedure. If installed as the MBR, LILO is responsible for either booting Linux or any other OS. This approach has the disadvantage, that the old MBR is overwritten and has to be restored (either from a backup copy, with FDISK /MBR on MS-DOS 5.0 or by overwriting it with BOOTACTV) if Linux should ever be removed from the system.

You should verify that LILO is able to boot your other operating system(s) before relying on this method.

Installation:

• boot Linux.

• make a backup copy of your MBR on a floppy disk, e.g.

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

• install LILO with its boot sector as the MBR.

• reboot.

Deinstallation:

• boot Linux.

• restore the old MBR, e.g.

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

If you’ve installed LILO to be the master boot record, you have to explicitly specify the boot sector when updating the map. Otherwise, it will try to use the boot sector of your current root partition, which may even work, but will leave your system unbootable.

2.8 Special names

The following names have been used to describe boot sectors or parts of operating systems:

DOS-MBR is the original MS-DOS MBR. It scans the partition table for a partition that is marked “active” and loads the boot sector of that partition. Programs like MS-DOS’ fdisk, Owen Le Blanc’s fdisk for Linux (on MCC-interim or 0.97 rootimage, or named efdisk on the 0.96 rootimage) or activate (accompanies LILO) can change the active marker in the partition table.

MS-DOS denotes the MS-DOS boot sector that loads the other parts of the system (IO.SYS, etc.).

COMMAND.COM is the standard command interpreter of MS-DOS.

BOOTLIN is a program that loads a Linux boot image from an MS-DOS partition into memory and executes it. It is usually invoked from CONFIG.SYS and used in conjunction with a CONFIG.SYS configuration switcher, like BOOT.SYS.^{6}

LILO can either load a Linux kernel or the boot sector of any other operating system. It consists of a first stage boot sector that loads the remaining parts of LILO from various locations.

6BOOTLIN is available for anonymous FTP from tsx-11.mit.edu:/pub/linux/INSTALL/bootlin4.zip or nic.funet.fi:/pub/OS/Linux/tools/bootlin.zip, BOOT.SYS is available for anonymous FTP from nic.funet.fi:/pub/OS/Linux/tools/boot142.zip or wuarchive.wustl.edu:/mirrors/msdos/sysutl/boot142.zip.

BOOTACTV permits interactive selection of the partition from which the boot sector should be read. If no key is pressed within a given interval, the partition marked active is booted. BOOTACTV is included in the pfdisk package. There are also several similar programs, like PBOOT and OS-BS.^{7}

Shoelace is a different boot loader for Linux. It is functionally similar to LILO, but it can only use the Minix file system.

3 Choosing the “right” boot concept

Although LILO can be installed in many different ways, the choice is usually limited by the present setup and therefore there is typically only a small number of configurations which fit naturally into an existing system.

In all examples, the names of the AT-type hard disk devices (/dev/hda…) are used. Everything applies to SCSI disks (/dev/sda…) too.

3.1 One disk, Linux on a primary partition

If at least one primary partition of the first hard disk is used as a Linux file system (/, /usr, etc. but not for a swap partition), the LILO boot sector should be stored on that partition and it should be booted by the original master boot record or by a program like BOOTACTV.

                        MBR  /dev/hda
                          MS-DOS /dev/hda1

                    →  Linux /     /dev/hda2

A typical /etc/lilo/install file would look like this:

/etc/lilo/lilo -c -i /etc/lilo/boot.b \
    /linux \
    /linux.backup \
    msdos=/etc/lilo/chain.b+/dev/hda1@/dev/hda

7pfdisk is available for anonymous FTP from tsx-11.mit.edu:/pub/linux/INSTALL/pfdisktc.zip or nic.funet.fi:/pub/OS/Linux/tools/pfdisk.tar.Z. PBOOT can be found at the same sites in the same directories.

3.2 One disk, Linux on an extended partition

If no primary partition is available for Linux, but at least one logical partition of an extended partition on the first hard disk contains a Linux file system, the LILO boot sector should be stored in the partition sector of the extended partition and it should be booted by the original master boot record or by a program like BOOTACTV.

                        MBR  /dev/hda
                          MS-DOS /dev/hda1

                    →  Extended /dev/hda2

                            Linux  /dev/hda5
                            . . .  /dev/hda6

A typical /etc/lilo/install file for this configuration would look like this:

/etc/lilo/lilo -b /dev/hda2 -c -i /etc/lilo/boot.b \
    /linux \
    /linux.backup \
    msdos=/etc/lilo/chain.b+/dev/hda1@/dev/hda

3.3 Two disks, Linux (at least partially) on the first disk

This case is equivalent to the configurations, where only one disk is in the system. The Linux boot sector resides on the first hard disk and the second disk is used later.

Only the location of the boot sector matters – everything else (/etc/lilo/boot.b, /etc/lilo/map, the root file system, a swap partition, other Linux file systems, etc.) can be located anywhere on the second disk.

3.4 Two disks, Linux on the second disk, the first disk has an extended partition

If there is no Linux partition on the first disk, but there is an extended partition, the LILO boot sector can be stored in the partition sector of the extended partition and it should be booted by the original master boot record or by a program like BOOTACTV.

First disk  Second disk

          MBR  /dev/hda  MBR  /dev/hdb
             MS-DOS /dev/hda1  Linux  /dev/hdb1
      →  Extended /dev/hda2  . . .  /dev/hdb2
               . . .  /dev/hda5
               . . .  /dev/hda6

A typical /etc/lilo/install file for this configuration would look like this:

/etc/lilo/lilo -b /dev/hda2 -c -i /etc/lilo/boot.b \
    /linux \
    /linux.backup \
    msdos=/etc/lilo/chain.b+/dev/hda1@/dev/hda

The program activate, that accompanies LILO, has to be used to set the active marker on an extended partition, because MS-DOS’ fdisk and (e)fdisk refuse to do that. (Which is generally a good idea.)

3.5 Two disks, Linux on the second disk, the first disk has no extended partition

If there is neither a Linux partition nor an extended partition on the first disk, where a LILO boot sector could be stored, then there’s only one place left: the master boot record.

In this configuration, LILO boots all other operating systems too.

First disk  Second disk

      → MBR  /dev/hda  MBR  /dev/hdb
             MS-DOS /dev/hda1  Linux  /dev/hdb1
             . . .  /dev/hda2  . . .  /dev/hdb2

You should back up your old MBR before installing LILO and verify that LILO is able to boot your other operating system(s) before relying on this approach.

A typical /etc/lilo/install file for this configuration would look like this:

/etc/lilo/lilo -b /dev/hda -c -i /etc/lilo/boot.b \
    /linux \
    /linux.backup \
    msdos=/etc/lilo/chain.b+/dev/hda1@/dev/hda

4 Technical overview

This section contains a description of several internals of LILO. It is not necessary to understand them in order to install LILO.

4.1 Load sequence

The boot sector is loaded by the ROM-BIOS at address 0x07C00. It moves itself to address 0x90000, sets up the stack (growing downwards from 0x92000 to 0x91000), loads the secondary boot loader at address 0x92000 and transfers control to it. It displays an “L” after moving itself and an “I” before starting the secondary boot loader.

The secondary boot loader loads the descriptor table at 0x92E00 and checks for user input. If either the default is used or if the user has specified an alternate image, the setup part of that image is loaded at 0x90200 and the kernel part is loaded at 0x10000. During that load operation, the sectors of the map file are loaded at 0x93000.

If the loaded image is a traditional boot image, control is transferred to its setup code. If it is an unstripped kernel, its BSS is zeroed first. If a different operating system is booted, things are a bit more difficult: the chain loader is loaded at 0x90200 and the boot sector of the other OS is loaded at 0x90400. The chain loader moves the partition table (loaded at 0x903BE as part of the chain loader) to 0x00600 and the boot sector to 0x07C00. After that, it passes control to the boot sector.

The secondary boot loader displays an “L” after being started and an “O” after loading the descriptor table.

0x00000

0x00600  Partition table  64 bytes

0x00640

0x07C00  Boot load area  512 bytes

0x07E00

0x10000  Kernel  320 kB

0x60000

0x90000 Primary boot loader 512 bytes
0x90200  Setup (kernel)  2 kB

0x90A00

0x91000  Stack  4 kB
0x92000 Secondary boot loader 3.5 kB
0x92E00  Descriptor table  512 bytes
0x93000  Map load area  512 bytes
0x93200  Scratch space  51.5 kB

0xA0000

4.2 File references

This section describes the references among files involved in the boot procedures.

The boot sector contains the primary boot loader, the address of the descriptor table sector and the addresses of the sectors of the secondary boot loader. The boot sector is copied from boot.b.

The primary boot loader can store up to four sector addresses of the secondary boot loader.

The map file consists of sections and of special data sectors. Each section spans an integral number of disk sectors and contains addresses of sectors of other files.^{8} The last address slot of each sector is either unused (if the map ends in this sector) or contains the address of the next sector in the section.

8There are two exceptions: 1. If a “hole” is being covered, the address of the zero sector

The two sectors at the beginning of the map file are special: the first sector contains the boot image descriptor table and the second sector is filled with zero bytes. This sector is mapped whenever a file contains a “hole”.

A traditional boot image consists simply of a sequence of sectors that are loaded. Images that are loaded from a device are treated exactly the same way as images that are loaded from a file.

The first sector of the boot image contains the floppy boot sector and is not mapped.

Unstripped kernels consist of the setup part and of the kernel file. The descriptor also contains information about the start and the size of the BSS segment. The boot loader clears BSS before starting the kernel.

When booting another operating system, the chain loader (chain.b) is merged with the partition table^{9} and written into the map file. The map section of this boot image starts after that sector and contains only the address of the loader sector and of the boot sector of the other operating system.

5 The boot prompt

Immediately after it’s loaded, LILO checks, whether one of the following is happening:

• any of the Shift, Control or Alt keys is being pressed.

• CapsLock or ScrollLock is set.

If this is the case, LILO displays the boot: prompt and waits for the name of a boot image. Otherwise, it boots the default boot image^{10} or – if a delay has been specified – waits for one of the listed activities until that amount of time has passed.

is used. This sector is part of the map file. 2. When booting a different operating system, the first sector is the merged chain loader that has been written to the map file before that section.

9If the partition table is omitted, that area is filled with zero bytes.

10The default boot image is either the first boot image or the image that has been selected at the boot prompt.

At the boot prompt, the name of the image to boot can be entered. Typing errors can be corrected with the keys BackSpace, Delete, Ctrl U and Ctrl X. A list of known images can be obtained by pressing ? (on the US keyboard) or Tab.

If Enter is pressed and no file name has been entered, the default image is booted.

6 Map installer

The map installer program /etc/lilo/lilo updates the boot sector and creates the map file. It is usually run from the shell script /etc/lilo/install. If the map installer detects an error, it terminates immediately and does not touch the boot sector and the map file.

Whenever LILO updates a boot sector, the original boot sector is copied to /etc/lilo/boot.number, where number is the hexadecimal device number. If such a file already exists, no backup copy is made.

LILO may create some device special files in your /tmp directory that are not removed if an error occurs. They are named /tmp/dev.number.

6.1 Command-line arguments

The LILO map installer accepts the following command-line options:

-b boot device Sets the name of the device that contains the boot sector. If -b is omitted, the boot sector is read from (and possibly written to) the device that is currently mounted as root. A BIOS device code can be specified.

-c

Tries to merge read requests for adjacent sectors into a single read request. This drastically reduces load time and keeps the map smaller. Using -c is especially recommended when booting from a floppy disk.

-i boot sector Install the specified file as the new boot sector. If -i is omitted, the old boot sector is modified. A BIOS device code can be specified. -i is usually a permanent part of the invocation of the map installer in

     /etc/lilo/install.

-m map file Specifies the location of the map file. If -m is omitted, a file /etc/lilo/map is used. A BIOS device code can be specified.

-r root directory Chroot to the specified directory before doing anything else. This is useful when running the map installer while the normal root file system is mounted somewhere else, e.g. when recovering from an installation failure with a bootimage/rootimage.^{11}

-s backup file Copy the original boot sector to backup file (which may also be a device,

e.g. /dev/null) instead of /etc/lilo/boot.number

-S backup file Like -S, but overwrite an old backup copy if it exists.

-t

Test only. This performs the entire installation procedure except replacing the map file and writing the modified boot sector. This can be used in conjunction with the -v option to verify that LILO will use sane values.

-v

Turns on lots of progress reporting. Repeating -v will turn on more reporting. (-v -v -v -v is the highest verbosity level and displays all mappings.)

If no image files are specified, the currently mapped files are listed. Only the options -m, -v and -r can be used in this mode.

If at least one file name is specified, a new map is created for those files and they are registered in the boot sector. If root or swap devices have been set in the images, they are copied into the descriptors in the boot sector. If no root device has been set^{12}, the current root device is used. The root and swap devices can be overridden by appending them to the image specification, e.g.

               lilo

\underbrace{foo}_{image}

                        ,

                          /dev/hda1

root

                                   , \underbrace{0x302}_{swap}

11I.e. if your root partition is mounted on /mnt, you can update the map by simply running /mnt/etc/lilo/install with the argument -r /mnt. If you’re normally using the default boot sector, you have to specify it explicitly in this case: -b /dev/device name. So the complete command may be something like this:

/mnt/etc/lilo/install -r /mnt -b /dev/hda1 You also have to set the environment variable ROOT before running the update script, e.g.:

export ROOT=/mnt

12Or if this is not a traditional boot image.

Either numbers or device names can be used.

It is perfectly valid to use different root/swap settings for the same image, because LILO stores them in the image descriptors and not in the images themselves. Example:

    lin-hd=/linux,/dev/hda2
    lin-fd=/linux,/dev/fd0

The image files can reside on any media that is accessible at boot time. There’s no need to put them on the root device, although this certainly doesn’t hurt.

If LILO doesn’t guess the correct BIOS device code, it can be specified by appending a colon and the code to the file name, e.g. /linux:0x80^{13}

LILO uses the first file name (without its path) of each image specification to identify that image. A different name can be used by prefixing the specification with label=, e.g.

    msdos=/etc/lilo/chain.b+/dev/sda1@/dev/sda

6.2 Boot image types

LILO can boot the following types of images:

• “traditional” boot images from a file.

• “traditional” boot images from a block device. (I.e. a floppy disk.)

• unstripped kernel executables.

• the boot sector of some other OS.

The image type is determined by the syntax that is used for the image specification.

6.2.1 Booting “traditional” boot images from a file

If defined, root and swap definitions are taken from the boot image. The image is specified as follows:

file name[:BIOS code]

Example: /linux 6.2.2 Booting “traditional” boot images from a device

13This is typically used to install LILO on a second disk that will be usd as the first disk later.

Root and swap settings in the image are ignored. The range of sectors that should be mapped, has to be specified. Either a range (start-end) or a start and a distance (start+number) have to be specified. If only the start if specified, only that sector is mapped.

device name[:BIOS code]#start[-end|+number]

Example: /dev/fd0#1+512

6.2.3 Booting unstripped kernel executables

Unstripped kernel executables contain no root or swap device information. The setup code of the kernel has also to be added to the kernel. First, it has to be copied to a suitable place and its header has to be removed, e.g.

    dd if=/usr/src/linux/boot/setup of=/etc/lilo/setup.b \
      bs=32 skip=1

If this command is placed at the beginning of /etc/lilo/install, setup.b is automatically updated whenever that script is run because anything else changes.

The image specification looks like this:

setup name[:BIOS code]+kernel name[:BIOS code]

Example: /etc/lilo/setup.b+/usr/src/linux/tools/system

6.2.4 Booting a foreign OS

LILO can even boot other operating systems, i.e. MS-DOS. This feature is new and may not yet work totally reliably. (Reported to work with PC-DOS 4.0, MS-DOS 5.0, DR-DOS 6.0, OS/2 2.0 and 386BSD.) To boot an other operating system, the name of a loader program, the device that contains the boot sector and the device that contains the partition table have to be specified:

loader+boot dev[:BIOS code]@[part dev]

Example: /etc/lilo/chain.b+/dev/hda2@/dev/hda

The name of the device that contains the partition table can be omitted if the respective operating system has other means to determine from which partition it has been booted. (E.g. MS-DOS stores the geometry of the boot disk or partition in its boot sector.)

The boot sector is merged with the partition table and stored in the map file.

Currently, only the loader chain.b exists. chain.b simply starts the specified boot sector.^{14}

6.3 Disk parameter table

For floppies and IDE disks (or MFM, RLL, ESDI, etc.), LILO can obtain the disk geometry information from the kernel. Unfortunately, this is not possible with SCSI disks. The file /etc/lilo/disktab is used to describe such disks. For each device (/dev/sda → 0x800, /dev/sda1 → 0x801, etc.), the BIOS code, the disk geometry and the offset of the first sector of that partition (measured in sectors) have to be specified, e.g.

# /etc/lilo/disktab  -  LILO disk parameter table
#
# This table contains disk parameters for SCSI disks and non-
# standard parameters of IDE disks. Parameters in disktab
# _always_override auto-detected disk parameters.
# Dev.  BIOS    Secs/   Heads/  Cylin-  Part.
# num.  code    track   cylin.  ders    offset
0x800   0x80    32      64      631     0       # /dev/sda
0x801   0x80    32      64      631     32      # /dev/sda1
0x802   0x80    32      64      631     204800  # /dev/sda2

(Those parameters are just a random example from my system. However, many SCSI controllers re-map the drives to 32 sectors and 64 heads. The number of cylinders does not have to be exact, but it shouldn’t be lower than the number of effectively available cylinders.)

Note that the device number and the BIOS code have to specified as hexadecimal numbers with the “0x” prefix.

The disk geometry parameters can be obtained by booting MS-DOS and running the program DPARAM.COM with the hexadecimal BIOS code of the drive as its argument, e.g. dparam 0x80 for the first hard disk. It displays the number of sectors per track, the number of heads per cylinder and the number of cylinders.

The partition offset is printed by the Linux kernel when the SCSI disk is detected at boot time. Example:

14The boot sector is loaded by LILO’s second boot loader before control is passed to the code of chain.b.

sd0 :
 part 1 start 32 size 204768 end 204799
 part 2 start 204800 size 1087488 end 1292287

The first partition has an offset of 32 sectors, the second has an offset of 204800 sectors.

Because many SCSI controllers don’t support more than 1 GB when using the BIOS interface, LILO can’t access files that are located beyond the 1 GB limit of large SCSI disks and reports errors in these cases.

7 Installation

7.1 First-time installation

You have to run the 0.96c-pl1 kernel or any newer release. First, you have to install the LILO files:

• extract all files from lilo.version.tar.Z

• run make to compile and assemble all parts.

   • run make install to copy all LILO files to /etc/lilo. /etc/lilo

should now contain the following files: boot.b, chain.b, disktab and

     lilo.

If you want to use LILO on a SCSI disk, you have to determine the parameters of your SCSI disk(s) and put them into the file /etc/lilo/disktab. See section 6.3 for details.

The next step is to test LILO with the boot sector on a floppy disk:

• insert a blank (but formatted) floppy disk into /dev/fd0.

   • chdir to /etc/lilo.
   • run ./lilo -b /dev/fd0 -i boot.b -v -v -v kernel image(s)^{15}

• reboot. LILO should now load its boot loaders from the floppy disk and then continue loading the kernel from the hard disk.

Now, your have to decide, which boot concept you want to use. Let’s assume you have a Linux partition on /dev/hda2 and you want to install your LILO boot sector there. The DOS-MBR loads the LILO boot sector.

15If you’ve already installed LILO on your system, you might not want to overwrite your old map file. Use the -m option to specify an alternate map file name.

• get a working bootimage and a rootimage. Verify that you can boot with this setup and that you can mount your Linux partition(s) with it.

• if the boot sector you want to overwrite with LILO is of any value (e.g. it’s the MBR or it contains a boot loader you might want to use if you encounter problems with LILO), you should mount your rootimage and make a backup copy of your boot sector to a file on that floppy, e.g.

dd if=/dev/hda of=/fd/boot_sector bs=512 count=1

• create a shell script /etc/lilo/install that installs and updates LILO on your hard disk, e.g.

#!/bin/sh
$ROOT/etc/lilo/lilo all necessary options -i /etc/lilo/boot.b $* \

kernel images

• Now, you can check what LILO would do if you were about to install it on your hard disk:

/etc/lilo/install -v -v -v -t

• If you need some additional boot utility (i.e. BOOTACTV), you should install that now.

• Run /etc/lilo/install to install LILO on your hard disk.

• If you have to change the active partition, use (e)fdisk or activate to do that.

• Reboot.

7.2 LILO update

When updating to a new version of LILO, the initial steps are the same as for a first time installation: extract all files, run make to build the executables and

run make install to move the files to /etc/lilo.

The old versions of boot.b and chain.b are automatically renamed to boot.old and chain.old. This is done to ensure that you can boot even if the installation procedure is not finished. boot.old and chain.old can be deleted after the map file is rebuilt.

Because the locations of boot.b and chain.b have changed and because the map file format may be different too, you have to update the boot sector and the map file. Run /etc/lilo/install to do this.

7.3 Kernel update

Whenever any of the kernel files that are accessed by LILO is moved or overwritten, the map has to be be re-built.^{16} Run /etc/lilo/install to do this.

If the setup code has changed and if you’re booting unstripped kernels, you also have to update setup.b. This should be done in /etc/lilo/install.

If you’re frequently re-compiling the kernel, you should put an invocation of /etc/lilo/install into the kernel’s top Makefile.

Example (. . ./linux/Makefile):
...
Image: boot/bootsect boot/setup tools/system tools/build
       cp tools/system system.tmp
       strip system.tmp
       tools/build boot/bootsect boot/setup system.tmp \
            $(ROOT_DEV) >/linux
       /etc/lilo/install
       rm system.tmp
       sync
...

16It is advisable to keep a secondary, stable, boot image that can be booted if you forget to update the map after a change to your usual boot image.