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 the floppy is booted on the system.[22] The kernel image is usually compressed, using the same algorithm as the gzip compression program (more on this in the section "Section 7.4.2, "Building the Kernel"" in Chapter 7, "Upgrading Software and the Kernel" ). 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.
[22]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 about LILO.
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 of these parameters may be modified using the rdev command, which we'll discuss later in the section.
After the kernel has started, it attempts to mount a filesystem on the root device hard-coded in the kernel image itself. This will serve as the root filesystem--that is, the filesystem on /. The section "Section 6.1, "Managing Filesystems"" in Chapter 6, "Managing Filesystems, Swap, and Devices" 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, "What to Do in an Emergency"" in Chapter 8, "Other Administrative Tasks".)
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).
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, OS/2's or Windows NT's boot managers are 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.
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.[23] This is not a universal convention, however; other Linux systems store the kernel in /vmlinuz or /vmlinux, 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 usually a good idea to do this anyway; you can "customize" the kernel to only include those drivers for your particular hardware. See the section "Section 7.4.2, "Building the Kernel"" in Chapter 7, "Upgrading Software and the Kernel" for details.
[23]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 the sections "Section 3.1.2, "Drives and Partitions Under Linux"" and "Section 3.1.3, "Creating Linux Partitions"" in Chapter 3, "Installation and Initial Configuration".
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:
If this is incorrect, and the Linux root filesystem is actually on /dev/hda3, we should use the following command:courgette:/# rdev /boot/vmlinuz Root device /dev/hda1
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.courgette:/# rdev /boot/vmlinuz /dev/hda3 courgette:/#
Now you're ready to create the boot floppy. For best results, use a brand-new, formatted floppy. You can format the floppy under MS-DOS or using fdformat under Linux;[24] 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, "Managing Filesystems"" in Chapter 6, "Managing Filesystems, Swap, and Devices" for more on using floppies.)
[24]The Debian distribution doesn'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:
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.courgette:/# dd if=/boot/vmlinuz of=/dev/fd0 bs=8192
Your boot floppy should now be ready to go. You can shut down the system (see the section "Section 5.5, "Shutting Down the System"" 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 the section "Section 8.6, "What to Do in an Emergency"" in Chapter 8, "Other Administrative Tasks", 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 MS-DOS--and allow you to select between them at boot time.
However, both OS/2 and Windows NT 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 OS/2 or Windows NT) takes care of executing LILO from there when you wish to boot Linux.
As we'll see, however, both the OS/2 and Windows NT 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.
Use of LILO with Windows 95/98, on the other hand, is quite simple. You simply configure LILO to boot Windows 95/98 as you would configure it to boot MS-DOS (see the next section). However, if you install Windows 95/98 after installing LILO, you need to reinstall LILO (as the Windows 95/98 installation procedure overwrites the MBR of your primary hard drive). Just be sure you have a Linux boot floppy on hand so 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:
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. (Debian users should always do this.) We'll talk about this in more detail later.boot = /dev/hda compact install = /boot/boot.b map = /boot/map
The compact line tells LILO to perform some optimization; always use this unless you are seriously hacking on your LILO configuration.[25] 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. 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.
[25]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:
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.# 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
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 have multiple Linux kernels you wish to boot--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 MS-DOS or Windows 95/98 would look like the following:
You would use an identical stanza to boot OS/2 from LILO (using a different label line, of course).# Stanza for MSDOS/Win 95/Win 98 partition on /dev/hda1. other = /dev/hda1 # Location of partition table = /dev/hda # Location of partition table for /dev/hda2 label = msdos # Name of OS (for boot menu)
If you wish to boot an MS-DOS or Windows 95/98 partition located on the second drive, you should add the line:
to the MS-DOS other stanza. For OS/2 partitions on the second drive, add the line:loader = /boot/any_d.b
loader = /boot/os2_d.b
There are many more options 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:
as root. This should display information such as the following:/sbin/lilo
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.courgette:/# /sbin/lilo Added linux Added msdos courgette:/#
Once this is done, you're ready to shut down your system (again, see the section "Section 5.5, "Shutting Down the System"" 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 Control key or simply press the Scroll Lock key while the system boots. This should present you with a LILO boot prompt:
Here, you can press Tab to get a list of available boot options:boot:
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 msdos causes MS-DOS to boot from /dev/hda1, as we specified in the lilo.conf file.boot: tab-key linux msdos
If you're using the OS/2 or Windows NT 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 boot loader, 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:
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 extended or logical partitions). This restriction applies 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 MS-DOS. When booting the system, the BIOS will read the boot record of the first "active" partition to start Linux.boot = /dev/hda2
If you are using OS/2's or Windows NT'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.
LILO is known to work with OS/2's Boot Manager, but getting things to work well is not always easy. The problem is that OS/2 Boot Manager won't even recognize your partitions created with Linux fdisk. The way around this problem is to use OS/2's fdisk to give the Linux partitions (created using Linux fdisk) a name. Another workaround is to create the Linux partitions using OS/2's fdisk and format them (say, as an MS-DOS FAT partition) first. Now OS/2 will recognize the partitions, and you can use the Linux fdisk command to set the types of the partitions to Linux native and Linux swap, as described in the section "Section 3.1.3, "Creating Linux Partitions"" in Chapter 3, "Installation and Initial Configuration". You can then install Linux on these partitions and install LILO on the boot record of your Linux root partition. Hopefully, all will be well.
Why are we telling you this now? Because OS/2's Boot Manager is broken with respect to booting operating systems it doesn't know about. Instead of using OS/2 Boot Manager, you can install LILO on the MBR of your drive and have it boot OS/2, using an other stanza in the /etc/lilo.conf file as you would with MS-DOS. Another option is to simply boot Linux from floppy--or, even better, not to use OS/2 at all. But let's not get carried away.
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:
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 the section "Section 3.1.1, "Booting Linux"" in Chapter 3, "Installation and Initial Configuration". 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:hd=cylinders,heads,sectors
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"
In this case, we specify the geometry for the first and second hard drives, respectively.append = "hd=683,16,38 hd=64,32,202"
Note that you need to use such boot options only if the kernel doesn't detect your hardware at boot time. 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 boot-time options available. Most of them deal with hardware detection, which has already been discussed in Chapter 3, "Installation and Initial Configuration". However, the following additional options may also be useful to you:
Boot the system in single-user mode; skip all of the system configuration and start a root shell on the console. See the section "Section 8.6, "What to Do in an Emergency"" in Chapter 8, "Other Administrative Tasks" for hints on using this.
Mounts the named partition as the Linux root filesystem. This overrides any value given in /etc/lilo.conf.
Mounts the root filesystem as read-only. This is usually done in order to run fsck; see the section "Section 6.1.5, "Checking and Repairing Filesystems"" in Chapter 6, "Managing Filesystems, Swap, and Devices".
Specifies a size, in bytes, for the ramdisk device. This overrides any value in /etc/lilo.conf. Most users need not worry about using the ramdisk; it's useful primarily for installation.
Sets the VGA display mode. This overrides any value in /etc/lilo.conf. Valid modes are normal, extended, ask, or an integer. This option is equivalent to the vga = values used in lilo.conf; see the section "Section 5.2.2.1, "The /etc/lilo.conf file"" earlier in this chapter.
Tells the kernel how much RAM you have. If you have 64 MB or less, the kernel can get this information from the BIOS, but if you use an older kernel and you have more, you will have to tell the kernel the exact amount, or it will only use the first 64 MB. For example, if you have 128 MB, specify mem=128m. Fortunately, this is no longer necessary with newer kernels.
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 of the configuration options available. On many Linux systems this documentation can be found in /usr/src/lilo; on Debian systems, it is in /usr/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 MS-DOS FDISK. The command:
runs FDISK and overwrites the MBR with a valid MS-DOS boot record.FDISK /MBR
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:
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.dd if=/boot/boot.0300 of=/dev/hda bs=446 count=1
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. Only use this method 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 © 2001 O'Reilly & Associates. All rights reserved.
This HTML Help has been published using the chm2web software. |