SourceForge VA Linux Systems
Copyright © 2000 Paul Sheer - Click here for copying permissions       Source by FTP

next up previous contents index
Next: init, mgetty and bootup Up: Rute Users Tutorial and Previous: exim and sendmail   Contents   Index

Subsections

lilo, initrd and Booting

Add comments here 
lilo stands for linux loader. LILO: is the prompt you first see after boot up, where you are usually able to choose the OS you would like to boot, and give certain boot options to the kernel. This chapter will explain how to configure lilo, kernel boot options, and get otherwise non-booting systems to boot.
The lilo package itself contains the files

 
 
 
/boot/boot.b      /boot/message     /sbin/lilo
/boot/chain.b     /boot/os2_d.b     /usr/bin/keytab-lilo
/usr/share/doc/lilo-<version>

which is not that interesting, except to know that the technical and user documentation is there if hard core details are needed.

Usage

When you first start your LINUX system, the LILO: prompt will appear where you can first enter boot options. Pressing the Tab key will give you a list of things to type. The purpose of this is to allow the booting of different LINUX installations on the same machine, or different operating systems stored in different partitions on the same disk.

Theory

Kernel boot sequence

To boot a UNIX kernel, requires it to be loaded into memory off disk and be executed. The execution of the kernel will cause it to uncompress itself, and then run34.1. The first thing the kernel does after it runs, is initialise various hardware devices. It then mounts the root file system off a previously defined partition. Once the root file-system is mounted, the kernel executes /sbin/init to begin the UNIX operating system. This is how all UNIX systems begin life.

Master Boot Record

PC's begin life with a small program in the ROM BIOS that loads the very first sector of the disk into memory, called the boot sector of the Master Boot Record or MBR. This piece of code is up to 512 bytes long and is expected to start the operating system. In the case of LINUX, the boot sector loads the file /boot/map, which contains a list of the precise location of the disk sectors that the LINUX kernel (usually the file /boot/vmlinuz) spans. It loads each of these sectors, thus reconstructing the kernel image in memory. Then it jumps to the kernel to execute it.
You may ask how it is possibly to load a file off a file-system when the file-system is not mounted. Further, the boot partition is a small and simple program, and certainly does not have support for the many possibly types of file-system that the kernel image may reside in. Actually, lilo doesn't have to support a file-system to access a file, so long as it has a list of the sectors that the file spans, and is prepared to use the BIOS interrupts34.2. If the file is never modified, that sector list will never change; this is how the /boot/map and /boot/vmlinuz files are loaded.

Booting partitions

In addition to the MBR, each primary partition has a boot sector that can boot the operating system in that partition. MSDOS (Windows) partitions have this, and hence lilo can optionally load and execute these partition boot sectors, to start a Windows installation in another partition.

Limitations

There are several limitations that BIOS's have inherited, due to lack of foresight of their designers. Firstly, some BIOS's do not support more than one IDE34.3. I myself have not come across this as a problem.
The second limitation is most important to note. As explained, lilo uses BIOS functions to access the IDE drive, but the BIOS of a PC is limited to accessing the first 1024 cylinders of the disk. Hence whatever LILO reads, it must reside within the first 1024 cylinders (the first 500 Megabytes of disk space). Here is the list of things whose sectors are required to be within this space:
1.
/boot/vmlinuz,
2.
Various lilo files /boot/*.b.
3.
Any non-LINUX partition boot sector you would like to boot.
However a LINUX root partition can reside anywhere, because the boot sector program never reads this partition except for the abovementioned files: a scenario where the /boot/ directory is a small partition below the 500 Megabyte boundary, and the / partition is above the 500 Megabyte boundary, is quite common.

lilo.conf and the lilo command

To ``do a lilo'' requires you run the lilo command as root, with a correct /etc/lilo.conf file. The lilo.conf file will doubtless have been set up by your distribution (check yours). A typical lilo.conf file that allows booting of a Windows partition and two LINUX partitions, is as follows:

 
 
 
 
5 
 
 
 
 
10 
 
 
 
 
15 
 
 
 
boot=/dev/hda
prompt
timeout = 50
compact
vga = extended
lock
append = ether=9,0x300,0xd0000,0xd4000,eth0
image = /boot/vmlinuz-2.2.17
        label = linux
        root = /dev/hda5
        read-only
image = /boot/vmlinuz-2.0.38
        label = linux-old
        root = /dev/hda6
        read-only
other = /dev/hda2
        label = win
        table = /dev/hda

Running lilo will install into the MBR a boot loader, that understands where to get the /boot/map file, which in turn understands where to get the /boot/vmlinuz-2.2.12-20 file. It will give some output like:

 
 
 
Added linux *
Added linux-old
Added win

It also backs up your existing MBR if this has not previously been done into a file /boot/boot.0300 (where 0300 refers to the devices major and minor number).

Let's go through the options:
boot
This tells the device to boot. It will most always be /dev/hda or /dev/sda.
prompt
This tell the loader to give you a prompt, asking which OS you would like to boot.
timeout
How many tenths of a seconds to display the prompt (after which the first image is booted).
compact
String adjacent sector reads together. This makes the kernel load much faster.
vga
We would like $80\times{}50$ text mode. Your startup scripts may reset this to $80\times{}25$ -- search /etc/rc.d recursively for any file containing ``textmode''.
lock
Always default to boot the last OS booted34.4.
append
This is a kernel boot option. Kernel boot options are central to lilo and kernel modules, but will be discussed in Chapter 44.5. They are mostly not needed in simple installations.
image
A LINUX kernel to boot.
label
The text to type at the boot prompt to get this kernel to boot.
root
The root file-system that the kernel must mount.
read-only
The root file-system must be mounted read only to start.
other
Some other operating system to boot: in this case a Windows partition.
table
Partition table info to be passed to the partition boot sector.
Further other = partitions may follow, and many image = kernel images are allowed.
The above lilo.conf file assumed a partition scheme as follows:
/dev/hda1
10 Megabyte ext2 partition to be mounted on /boot.
/dev/hda2
Windows 98 partition over 500 Megabytes in size.bootingWindows 98
/dev/hda3
Extended partition.
/dev/hda4
Unused primary partition.
/dev/hda5
ext2 root file-system.
/dev/hda6
second ext2 root file-system containing an older distribution.
/dev/hda?
LINUX swap, /home etc. partitions.

Creating boot floppy disks

This is easy. We require a floppy disk containing the kernel image, to boot and then immediately mount a particular partition as root. This is required for a system where LILO is broken or absent. To boot the first ext2 partition of the above setup, insert a new floppy into a working LINUX system, and overwrite it with the following:

 
 
dd if=/boot/vmlinuz-2.2.17 of=/dev/fd0
rdev /dev/fd0 /dev/hda5

Then simply boot the floppy. The above merely requires a second LINUX installation. Without even this, you will have to download the RAWRITE.EXE utility and a raw boot disk image to create the floppy from a DOS prompt.

SCSI installation complications and initrd

Some of the following may be difficult to understand without knowledge of kernel modules explained in Chapter 44. You may like to come back to it later.
Consider a system with zero IDE disks and one SCSI disk containing a LINUX installation. There are BIOS interrupts to read the SCSI disk, just like there were for the IDE, so LILO can happily access a kernel image somewhere inside the SCSI partition. However, the kernel is going to be lost without a kernel module34.5 that understands the particular SCSI driver. So though the kernel can load and execute, it won't be able to mount its root file-system without loading a SCSI module first. But the module itself resides in root file-system in /lib/modules/. This is a tricky situation to solve and is done in one of two ways: either (a) using a kernel with a pre-enabled SCSI support; or (b) using what is known as an initrd preliminary root file-system image.
The first method is what I recommend. Its a straight forward (though time consuming) procedure to create a kernel that has SCSI support for your SCSI card builtin (and not in a separate module). Builtin SCSI and network drivers will also auto-detect cards most of the time allowing immediate access to the device-- they will work without being given any options34.6 and, most importantly, without you having to read up how to configure them. This is known as compiled in support for a hardware driver (as apposed to module support for the driver). The resulting kernel image will be larger by an amount equal to the size of module. Chapter 44 discusses such kernel compiles.
The second method is faster but more tricky. LINUX has support for what is known as an initrd image (initial rAM disk image). This is a small 1.5 Megabyte file-system that is loaded by LILO, and mounted by the kernel instead of the real file-system. The kernel mounts this file-system as a RAM disk, executes the file /linuxrc, and then only mounts the real file-system.

Creating an initrd image

Start by creating a small file-system. Make a directory  /initrd and copy the following files into it.

 
 
 
 
5 
 
 
 
 
10 
 
 
 
 
15 
 
 
drwxr-xr-x    7 root     root         1024 Sep 14 20:12 initrd/
drwxr-xr-x    2 root     root         1024 Sep 14 20:12 initrd/bin/
-rwxr-xr-x    1 root     root       436328 Sep 14 20:12 initrd/bin/insmod
-rwxr-xr-x    1 root     root       424680 Sep 14 20:12 initrd/bin/sash
drwxr-xr-x    2 root     root         1024 Sep 14 20:12 initrd/dev/
crw-r--r--    1 root     root       5,   1 Sep 14 20:12 initrd/dev/console
crw-r--r--    1 root     root       1,   3 Sep 14 20:12 initrd/dev/null
brw-r--r--    1 root     root       1,   1 Sep 14 20:12 initrd/dev/ram
crw-r--r--    1 root     root       4,   0 Sep 14 20:12 initrd/dev/systty
crw-r--r--    1 root     root       4,   1 Sep 14 20:12 initrd/dev/tty1
crw-r--r--    1 root     root       4,   1 Sep 14 20:12 initrd/dev/tty2
crw-r--r--    1 root     root       4,   1 Sep 14 20:12 initrd/dev/tty3
crw-r--r--    1 root     root       4,   1 Sep 14 20:12 initrd/dev/tty4
drwxr-xr-x    2 root     root         1024 Sep 14 20:12 initrd/etc/
drwxr-xr-x    2 root     root         1024 Sep 14 20:12 initrd/lib/
-rwxr-xr-x    1 root     root           76 Sep 14 20:12 initrd/linuxrc
drwxr-xr-x    2 root     root         1024 Sep 14 20:12 initrd/loopfs/

On my system the file initrd/bin/insmod is the statically linked34.7 version in /sbin/insmod.static from the modutils-2.3.13 package. initrd/bin/sash is a statically linked shell from the sash-3.4 package.
Now copy into the initrd/lib/ directory the SCSI modules you require. Taking the example that we have an Adaptec AIC-7850 SCSI adaptor, we would require the aic7xxx.o module from /lib/modules/<version>/scsi/aic7xxx.o. Then place it in the initrd/lib/ directory.

 
-rw-r--r--    1 root     root       129448 Sep 27  1999 initrd/lib/aic7xxx.o

The file initrd/linuxrc should contain a script to load all the modules needed for the kernel to access the SCSI partition. In this case, just the aic7xxx module34.8:

 
 
 
 
5 
 
#!/bin/sash

aliasall

echo "Loading aic7xxx module"
insmod /lib/aic7xxx.o 

Now double check all your permissions and create a file-system image similar to that done in Section 22.8:

 
 
 
 
5 
 
 
 
dd if=/dev/zero of=~/file-inird count=1500 bs=1024
losetup /dev/loop0 ~/file-inird
mke2fs /dev/loop0
mkdir ~/mnt
mount /dev/loop0 ~/mnt
cp -a initrd/* ~/mnt/
umount ~/mnt
losetup -d /dev/loop0

Finally, gzip the file-system to an appropriately named file:

 
gzip -c ~/file-inird > initrd-<kernel-version>

Modifying lilo.conf for initrd

Your lilo.conf file can be changed slightly to force use of an initrd file-system. Simply add the initrd option. For example:

 
 
 
 
5 
 
 
 
 
10 
 
boot=/dev/sda
prompt
timeout = 50
compact
vga = extended
linear
image = /boot/vmlinuz-2.2.17
        initrd = /boot/initrd-2.2.17
        label = linux
        root = /dev/sda1
        read-only

Notice the use of the linear option. This is a BIOS trick that you can read about in lilo5. It is often necessary, but can make SCSI disks non-portible to different BIOS's (meaning that you will have to rerun lilo if you move the disk to a different computer).

Using mkinitrd

Now that you have learned the manual method of create an initrd image, you can read the mkinitrd man page. It creates an image in a single command.

next up previous contents index
Next: init, mgetty and bootup Up: Rute Users Tutorial and Previous: exim and sendmail   Contents   Index
Paul Sheer 2000-10-07