There are several ways of booting Linux on your system. The most common methods involve booting from the hard drive or using a boot floppy. In many cases, the installation procedure will have configured one or both of these for you; in any case, it's important to understand how to configure booting for yourself.
Traditionally, a Linux boot floppy simply contains a kernel image, which is loaded into memory when you insert the floppy and start the system.[12]
[12]A Linux boot floppy may instead contain a LILO boot record, which causes the system to boot a kernel from the hard drive. We'll discuss this in the next section, when we talk more about LILO.
Many Linux distributions create a boot floppy for you in this way when installing the system. Using a boot floppy is an easy way to boot Linux if you don't want to bother booting from the hard drive. (For example, Windows NT/2000's boot manager is somewhat difficult to configure for booting Linux. We'll talk about this in the next section.) Once the kernel has booted from the floppy, you are free to use the floppy drive for other purposes.
We'll include some technical information here in order to explain the boot process, but rest assured that in most cases, you can just insert the floppy disk, and booting works. Reading the following paragraphs will help you understanding your system, though.
The kernel image is usually compressed, using the same algorithm as the gzip or the bzip2 compression programs (more on this in Section 7.4.2 in Chapter 7 ). Compression allows the kernel, which may be a megabyte or more in size, to require only a few hundred kilobytes of disk space. Part of the kernel code is not compressed: this part contains the routines necessary to uncompress the kernel from the disk image and load it into memory. Therefore, the kernel actually "bootstraps" itself at boot time by uncompressing into memory.
A number of parameters are stored in the kernel image. Among these parameters is the name of the device to use as the root filesystem once the kernel boots. Another parameter is the text mode to use for the system console. All these parameters may be modified using the rdev command, which we'll discuss later in this section.
After the kernel has started, it attempts to mount a filesystem on the root device hardcoded in the kernel image itself. This will serve as the root filesystem — that is, the filesystem on /. Section 6.1 in Chapter 6 discusses filesystems in more detail; all that you need to know for now is that the kernel image must contain the name of your root filesystem device. If the kernel can't mount a filesystem on this device, it gives up, issuing a kernel "panic" message. (Essentially, a kernel panic is a fatal error signaled by the kernel itself. A panic will occur whenever the kernel is terminally confused and can't continue with execution. For example, if there is a bug in the kernel itself, a panic might occur when it attempts to access memory that doesn't exist. We'll talk about kernel panics more in the section Section 8.6 in Chapter 8.)
The root device stored in the kernel image is that of your root filesystem on the hard drive. This means that once the kernel boots, it mounts a hard-drive partition as the root filesystem, and all control transfers to the hard drive. Once the kernel is loaded into memory, it stays there — the boot floppy need not be accessed again (until you reboot the system, of course).
Given a kernel image, you can create your own boot floppy. On many Linux systems, the kernel itself is stored in the file /boot/vmlinuz.[13] This is not a universal convention, however; other Linux systems store the kernel in /vmlinuz or /vmlinux, and still others in a file such as /Image. (If you have multiple kernel images, you can use LILO to select which one to boot. See the next section.) Note that newly installed Linux systems may not have a kernel image on the hard drive if a boot floppy was created for you. In any case, you can build your own kernel. It's often a good idea to do this anyway; you can "customize" the kernel to include only those drivers for your particular hardware. See Section 7.4.2 in Chapter 7 for details.
[13]Why the silly filename? On many Unix systems, the kernel is stored in a file named /vmunix where vm stands for "virtual memory." Naturally, Linux has to be different and names its kernel images vmlinux, and places them in the directory /boot to get them out of the root directory. The name vmlinuz was adopted to differentiate compressed kernel images from uncompressed images. Actually, the name and location of the kernel don't matter a bit, as long as you have either a boot floppy containing a kernel, or LILO knows how to find the kernel image.
All right. Let's say that you have a kernel image in the file /boot/vmlinuz. To create a boot floppy, the first step is to use rdev to set the root device to that of your Linux root filesystem. (If you built the kernel yourself, this should be already set to the correct value, but it can't hurt to check with rdev.) We discussed how to create the root device in Section 3.1.2 and Section 3.1.3 in Chapter 3.
As root, use rdev -h to print a usage message. As you will see, there are many supported options, allowing you to specify the root device (our task here), the swap device, ramdisk size, and so on. For the most part, you needn't concern yourself with these options now.
If we use the command rdev /boot/vmlinuz, the root device encoded in the kernel found in /boot/vmlinuz will be printed:
courgette:/# rdev /boot/vmlinuz Root device /dev/hda1
If this is incorrect, and the Linux root filesystem is actually on /dev/hda3, we should use the following command:
courgette:/# rdev /boot/vmlinuz /dev/hda3 courgette:/#
rdev is the strong, silent type; nothing is printed when you set the root device, so run rdev /boot/vmlinuz again to check that it is set correctly.
Now you're ready to create the boot floppy. For best results, use a brand-new, formatted floppy. You can format the floppy under Windows or using fdformat under Linux;[14] this will lay down the sector and track information so that the system can auto-detect the size of the floppy. (See the section Section 6.1 in Chapter 6 for more on using floppies.)
[14]Some versions of the Debian distribution don't have an fdformat command; use the aptly named superformat instead.
To create the boot floppy, use dd to copy the kernel image to it, as in:
courgette:/# dd if=/boot/vmlinuz of=/dev/fd0 bs=8192
If you're interested in dd, the manual page will be illustrative; in brief, this copies the input file (if option) named /boot/vmlinuz to the output file (of option) named /dev/fd0 (the first floppy device), using a block size (bs) of 8192 bytes. Of course, the plebian cp can be used as well, but we Unix sysadmins love to use cryptic commands to complete relatively simple tasks. That's what separates us from mortal users.
Your boot floppy should now be ready to go. You can shut down the system (see Section 5.5 later in this chapter) and boot with the floppy, and if all goes well, your Linux system should boot as it usually does. It might be a good idea to make an extra boot floppy as a spare, and in Section 8.6 in Chapter 8, we describe methods by which boot floppies can be used to recover from disaster.
LILO is a general-purpose boot manager that can boot whatever operating systems you have installed on your machine, including Linux. There are dozens of ways to configure LILO. Here, we're going to discuss the two most common methods: installing LILO on the master boot record of your hard drive and installing LILO as a secondary boot loader for Linux only.
LILO is the most common way to boot Linux from the hard drive. (By the expression "boot from the hard drive," we mean that the kernel itself is stored on the hard drive and no boot floppy is required, but remember that even when you use a boot floppy, control is transferred to the hard drive once the kernel is loaded into memory.) If LILO is installed on your drive's master boot record, or MBR, it is the first code to run when the hard drive is booted. LILO can then boot other operating systems — such as Linux or Windows — and allow you to select between them at boot time.
TIP: It should be mentioned here that LILO is not the only boot manager available for booting Linux. There are alternatives like grub (Grand Unified Bootloader) that work just as well. However, because most distributions use LILO, this is also what we will cover here.
However, Windows NT and later versions of Windows have boot managers of their own that occupy the MBR. If you are using one of these systems, in order to boot Linux from the hard drive, you may have to install LILO as the "secondary" boot loader for Linux only. In this case, LILO is installed on the boot record for just your Linux root partition, and the boot manager software (for Windows NT/2000) takes care of executing LILO from there when you wish to boot Linux.
As we'll see, however, the Windows NT/2000 boot managers are somewhat uncooperative when it comes to booting LILO. This is a poor design decision, and if you must absolutely use one of these boot managers, it might be easier to boot Linux from floppy instead. Read on. Or, if you really want to go with Linux all the way, you can use LILO to boot Windows NT/2000 and dump the Windows boot managers completely.
Use of LILO with Windows 95/98/ME/2000 is quite simple. You just configure LILO to boot Windows 95/98/ME/2000 (see the next section). However, if you install Windows 95/98/ME/2000 after installing LILO, you need to reinstall LILO (as the Windows 95/98/ME/2000 installation procedure overwrites the MBR of your primary hard drive). Just be sure you have a Linux boot floppy on hand so that you can boot Linux and rerun LILO.
Before proceeding you should note that a number of Linux distributions are capable of configuring and installing LILO when you first install the Linux software. However, it's often best to configure LILO yourself, just to ensure that everything is done correctly.
The first step in configuring LILO is to set up the LILO configuration file, which is often stored in /etc/lilo.conf. (On other systems, the file may be found in /boot/lilo.conf or /etc/lilo/config.)
We are going to walk through a sample lilo.conf file. You can use this file as a base for your own lilo.conf and edit it for your own system.
The first section of this file sets up some basic parameters:
boot = /dev/hda compact install = /boot/boot.b map = /boot/map
The boot line sets the name of the device where LILO should install itself in the boot record. In this case, we want to install LILO in the master boot record of /dev/hda, the first non-SCSI hard drive. If you're booting from a SCSI hard drive, use a device name such as /dev/sda instead. If you give a partition device name (such as /dev/hda2), instead of a drive device, LILO will be installed as a secondary boot loader on the named partition. We'll talk about this in more detail later.
The compact line tells LILO to perform some optimization; always use this unless you are seriously hacking on your LILO configuration.[15] Likewise, always use the install and map lines as shown. install names the file containing the boot sector to use on the MBR, and map specifies the "map file" that LILO creates when installed. On many distributions (like SuSE), these files should be in the directory /boot, although on other systems they may be found in /etc/lilo. /boot/map won't be created until you install LILO for the first time.
[15]In some cases, you will need the linear option, which should not be used together with compact. See the LILO documentation for more information.
Now, for each operating system you wish LILO to boot, add a stanza to /etc/lilo.conf. For example, a Linux stanza might look like this:
# Stanza for Linux with root partition on /dev/hda2. image = /boot/vmlinuz # Location of kernel label = linux # Name of OS (for the LILO boot menu) root = /dev/hda2 # Location of root partition vga = ask # Ask for VGA text mode at boot time
The image line specifies the name of the kernel image. Subfields include label, which gives this stanza a name to use with the LILO boot menu (more on this later); root, which specifies the Linux root partition; and vga, which specifies the VGA text mode to use for the system console.
Valid modes for vga are normal (for standard 80x25 display), extended (for extended text mode, usually 132x44 or 132x60), ask (to be prompted for a mode at boot time), or an integer (such as 1, 2, or 3). The integer corresponds to the number of the mode you select when using ask. The exact text modes available depend on your video card; use vga = ask to get a list.
If you wish to boot multiple Linux kernels — for example, if you're doing some kernel debugging — you can add an image stanza for each one. The only required subfield of the image stanza is label. If you don't specify root or vga, the defaults coded into the kernel image itself using rdev will be used. If you do specify root or vga, these override the values you may have set using rdev. Therefore, if you are booting Linux using LILO, there's no need to use rdev; the LILO configuration file sets these boot parameters for you.
A stanza for booting Windows 95/98/ME/2000 would look like the following:
# Stanza for Win 95/Win 98/Win ME/Win 2000 partition on /dev/hda1. other = /dev/hda1 # Location of partition table = /dev/hda # Location of partition table for /dev/hda2 label = windows # Name of OS (for boot menu)
If you wish to boot a Windows 95/98/ME/2000 partition located on the second drive, you should add the line:
loader = /boot/any_d.b
to the Windows other stanza.
Many more options are available for LILO configuration. The LILO distribution itself (found on most Linux FTP sites and distributions) includes an extensive manual describing them all. The previous examples should suffice for most systems, however.
Once you have your /etc/lilo.conf ready, you can run the command:
/sbin/lilo
as root. This should display information, such as the following:
courgette:/# /sbin/lilo Added linux Added windows courgette:/#
Using the -v option with lilo prints more diagnostic information should something go wrong; also, using the -C option allows you to specify a configuration file other than /etc/lilo.conf.
Once this is done, you're ready to shut down your system (again, see Section 5.5 later in this chapter for details), reboot, and try it out. The first operating system stanza listed in /etc/lilo.conf will be booted by default. To select one of the other kernels or operating systems listed in /etc/lilo.conf, hold down the Shift or Ctrl key or simply press the Scroll Lock key while the system boots. This should present you with a LILO boot prompt:
boot:
Here, you can press Tab to get a list of available boot options:
boot: tab-key linux windows
These are the names given with label lines in /etc/lilo.conf. Enter the appropriate label, and that operating system will boot. In this case, entering windows causes Windows to boot from /dev/hda1, as we specified in the lilo.conf file.
It should be noted here that some distributions add a fancy GUI to LILO (typically, this involves a Tux, the Linux penguin, in the background). However, configuring these should be no different from configuring the plain, old text-mode LILO.
If you're using the Windows NT/2000 boot manager, installing the Debian distribution of Linux, or don't want LILO to inhabit the master boot record of your drive, you can configure LILO as a secondary bootloader, which will live on the boot record of just your Linux root partition.
To do this, simply change the boot = ... line of /etc / lilo.conf to the name of the Linux root partition. For example:
boot = /dev/hda2
will install LILO on the boot record of /dev/hda2, to boot Linux only. Note that this works only for primary partitions on the hard drive (not for extended or logical partitions). This restriction does not apply to the Debian distribution, however, where the MBR can boot an operating system from a boot sector in an extended (but not logical) partition. In order to boot Linux in this way, the Linux root partition should be marked as "active" in the partition table. This can be done using fdisk under Linux or Windows. When booting the system, the BIOS will read the boot record of the first "active" partition to start Linux.
If you are using Windows NT/2000's boot manager, you should install LILO in this way, and then tell the boot manager to boot another operating system from that partition on your hard drive. The method for doing this depends on the boot manager in question; see your documentation for details.
When you first installed Linux, more than likely you booted either from a floppy or a CD-ROM, which gave you the now-familiar LILO boot prompt. At this prompt you can enter several boot time options, such as:
hd=cylinders,heads,sectors
to specify the hard-drive geometry. Each time you boot Linux, it may be necessary to specify these parameters in order for your hardware to be detected correctly, as described in Section 3.1.1 in Chapter 3. If you are using LILO to boot Linux from the hard drive, you can specify these parameters in /etc/lilo.conf instead of entering them at the boot prompt each time. To the Linux stanza of the lilo.conf file, just add a line, such as:
append = "hd=683,16,38"
This causes the system to behave as though hd=683,16,38 were entered at the LILO boot prompt. If you wish to specify multiple boot options, you can do so with a single append line, as in:
append = "hd=683,16,38 hd=64,32,202"
In this case, we specify the geometry for the first and second hard drives, respectively.
Note that you need to use such boot options only if the kernel doesn't detect your hardware at boot time, which is unlikely unless you have very old or very uncommon hardware. You should already know if this is necessary, based on your experiences with installing Linux; in general, you should have to use an append line in lilo.conf only if you had to specify these boot options when first booting the Linux installation media.
There are a number of other boottime options. Most of them deal with hardware detection, which has already been discussed in Chapter 3. However, the following additional options may also be useful to you:
Any of these options can be entered by hand at the LILO boot prompt or specified with the append option in /etc/lilo.conf.
LILO includes complete documentation that describes all the configuration options available. On many Linux systems this documentation can be found in /usr/src/lilo; on Debian systems, it is in /usr/share/doc/lilo/Manual.txt.gz. If you can't seem to find anything, grab the LILO distribution from one of the Linux archive sites, or ask your Linux vendor to provide the sources and documentation for LILO. This documentation includes a manual that describes all the concepts of booting and using LILO in detail, as well as a README file that contains excerpts from this manual, formatted as plain text.
If you have LILO installed on your MBR, the easiest way to remove it is to use Windows fdisk. The command:
FDISK /MBR
runs fdisk and overwrites the MBR with a valid Windows boot record.
LILO saves backup copies of your original boot record in the files /boot/boot.0300 (for IDE drives) and /boot/boot.0800 (for SCSI drives). These files contain the MBR of the drive before LILO was installed. You can use the dd command to replace the boot record on the drive with this backup copy. For example:
dd if=/boot/boot.0300 of=/dev/hda bs=446 count=1
copies the first 446 bytes of the file /boot/boot.0300 to /dev/hda. Even though the files are 512 bytes in size, only the first 446 bytes should be copied back to the MBR.
Be very careful when using this command! This is one of those cases where blindly executing commands you find in a book can cause real trouble if you're not sure what you're doing. Use this method only as a last resort and only if you're certain that the files /boot/boot.0300 or /boot/boot.0800 contain the boot record you want. Many distributions of Linux come installed with bogus versions of these two files; you might need to delete them before you install LILO.
The LILO documentation contains further hints for removing LILO and debugging your LILO configuration.
Copyright © 2003 O'Reilly & Associates. All rights reserved.