9.3 Using LILO with Disk and CompactFlash Devices

Because there is already ample documentation on the installation, configuration, and use of LILO, I will cover only its specific use in embedded PC-like systems. Specifically, I will provide the instructions to use on the host to install LILO on a storage device meant to be used in the target.

The installation of LILO on a target's storage device requires the use of the removable storage setup as explained in Chapter 2. In this scenario, the target's storage device is removed from the target and connected to the host's own hardware to be programmed. Hence, the target's storage device is controlled by the host's operating system like any other host device. The target's storage device is therefore seen as an extra storage device for the host. It can be seen, for example, as a secondary IDE disk (/dev/hdb) or as a primary SCSI disk (/dev/sda). Regardless of the way it is seen by the host's kernel, LILO needs to be used in a specific way to install itself on this secondary storage and not on the host's boot media, as is the default.

As we discussed in Chapter 8, CF devices are quite peculiar in this regard, because they can be seen on the host as a SCSI disk (/dev/sdX) when accessed through a USB CF reader, while being seen on the target as an IDE disk (/dev/hdX) when accessed through a CF-to-IDE or CF-to-PCMCIA adapter. The configuration file example I provide below takes care of this issue by using the appropriate BIOS and kernel flags so that the disk seen as a SCSI disk on the host can boot normally as an IDE disk once put back in the target.

In the following, I assume that the storage device where LILO will be installed is accessible on your host, and that you are using LILO Version 22.3 or later. If you are using an earlier version, an important command will fail, as I will explain shortly. Follow these steps to install LILO on a secondary IDE or SCSI storage device on your host:

  1. Create appropriate /dev entries in your target's root filesystem for the storage device where LILO is to be installed. This is not the storage device as it will be accessed once in your target. Rather, this is the storage device entry used by the host to access the designated storage device. If, for example, you want to install LILO on /dev/sda (usually the first SCSI hard disk in your system), there must be a /dev/sda entry on your target's root filesystem. It is very likely that this entry does not correspond to a valid device on your target. Indeed, it is possible that the disk accessed as /dev/sda on the host may be accessed as /dev/hda once on the target. Nevertheless, you must create the /dev/sda entry in your target's root filesystem for LILO to use when running on the host. The reasons for this will soon become evident. For more information on the relationship between /dev entries and the actual physical storage devices, see Chapter 3 of Running Linux.

  2. Create a LILO configuration file on your target root filesystem. To avoid damaging your host's configuration when installing LILO on the target's storage device, put your LILO configuration in /etc/target.lilo.conf on your target's root filesystem instead of the usual /etc/lilo.conf. Hence, if you accidentally issue a LILO command that modifies your host, the tool will complain about a missing file and no damage will be done to your host.

    Here is a sample /etc/target.lilo.conf to boot my DAQ module from a CF card:

    boot = /dev/sda
    disk = /dev/sda
      bios = 0x80
    image = /boot/bzImage-2.4.18
      root = /dev/sda1
      append = "root=/dev/hda1"
      label = Linux

    In this case, the CF card is accessed through a USB CF reader and is visible on my host as a SCSI disk through /dev/sda. On the target, however, it will be accessed through a CF-to-IDE adapter and will be visible as an IDE drive through /dev/hda. If you use a normal LILO configuration file to configure LILO, it would guess the BIOS ID of the disk it is operating on, and would use that ID at startup to make access requests to the BIOS. Since, in this case, it is operating on a SCSI disk, it would assume a SCSI BIOS ID and would make access requests for such a disk. Since no such disk exists on the target, the BIOS would return an error and LILO would fail to boot. The trick in the configuration file above lies in the bios = 0x80 line. This informs LILO that it is booting from the disk with BIOS ID 0x80, which is the first IDE drive in the system. Because of the confusion between SCSI and IDE, I must also append a root=/dev/hda1 option to the kernel's boot parameters. Otherwise, the kernel would fail to find its root filesystem and crash while trying to mount it.[5]

    [5] Normally, you shouldn't need to append a root= option to the kernel's boot parameters if you already have a root line in your image description. In this case, however, the software involved takes for granted that disks cannot change types, and fails to configure the boot process properly without the double declaration.

    Alternatively, if you want to install LILO on /dev/hdb, replace the /dev/sda entries above with /dev/hdb. In this case, you won't need to append the root=/dev/hda1 option to the kernel's boot instructions, because the disk appears as IDE both on the host and the target.

    When LILO is run with the configuration file above, it opens the host's /dev/sda device and installs itself there. Because this configuration file is located in ${PRJROOT}/rootfs/etc/target.lilo.conf instead of /etc/lilo.conf, special options must be used with LILO to provide it with the location of this alternative configuration file. I will present the complete LILO command line to use in this configuration shortly.

    For a complete discussion of how LILO is installed on an alternative storage device, see the Installing hdc to Boot as hda and Using bios= section in the LILO mini-HOWTO provided by the LDP.

  3. If necessary, partition the storage device using fdisk.

  4. Create filesystems on the storage device for the filesystem types you selected using the appropriate filesystem creation tools. For an ext2 filesystem, for example, use mke2fs.

  5. Mount the root filesystem partition on an appropriate directory in /mnt.

  6. Copy the root filesystem to its designated partition using cp -a. The root filesystem must contain the kernel image referenced by the /etc/target.lilo.conf file created earlier, /boot/bzImage-2.4.18 in this case.

  7. Install LILO on the storage device. For my DAQ module's storage device, for example, which is mounted as /mnt/cf on my host, I use the following command:

    # lilo -r /mnt/cf -C etc/target.lilo.conf
    Warning: etc/target.lilo.conf should be owned by root
    Warning: LBA32 addressing assumed
    Added Linux *

    This command instructs lilo to use the chroot( ) system call to change its root directory to /mnt/cf directory and to use the etc/target.lilo.conf configuration file found in that directory. The command programs the devices specified in the target.lilo.conf configuration file. The /dev entries specified in the configuration file are located starting from the root directory entry, /mnt/cf. If /dev/sda must be programmed, for example, LILO attempts to open and program /mnt/cf/dev/sda.

    If you had forgotten to create the /dev entries specified in target.lilo.conf on your target's root filesystem, this command will fail. It will also fail if there is no /tmp directory on your target's root filesystem. Furthermore, if you are using a LILO version earlier than 22.3, the command will report the following error and fail:

    Fatal: open /boot/boot.b: No such file or directory

    This error message is due to the fact that, prior to Version 22.3, LILO's components were separated across different files, some of which were .b files. Since 22.3, all .b files are part of the lilo binary.

  8. Unmount the root filesystem partition.

You can now remove the storage device from your host, either by shutting down the host and removing the hard disk or by removing the CF card from the CF reader, instaling it in your target, and booting it.

A Word on Using LILO with DiskOnChip Devices

To boot from a DOC device, LILO must be patched, since it doesn't support the DOC by default. Both the Linux tools package provided by M-Systems and the MTD package provide a patch for LILO. In light of the common experience of many individuals on the MTD mailing list and the fact that GRUB is the bootloader receiving most of the MTD development team's attention, however, I strongly recommend that you use GRUB instead of LILO for booting from a DOC device. If you still would like to use LILO, look at the relevant entries in the MTD mailing list archive or, if you fail to find what you need in the archive, ask the mailing list for guidance.

    Evaluation has Иѕ»ДДБЪАБexpired.