Before the kernel runs init, a boot loader starts the kernel. On occasion, you need to tell the boot loader to load different kernels or operating systems, and to start in different modes. This is especially important when trying to fix a system that has a problem that prevents a full boot. To fix such a problem, you may need single-user mode or an alternate kernel.
The boot loader loads a kernel image into memory and hands control of the CPU to the new image, possibly supplying it with some parameters. These parameters are simple text strings like -s for booting in single-user mode and root=partition for using partition as the root filesystem instead of the default. You can specify a runlevel number as a parameter to make the system boot into a runlevel other than the default.
To type in a kernel name and parameters, however, you first need to know how to get to a boot prompt. Unfortunately, there are several different boot loaders out there, and because you can control a boot loader's behavior, Linux distributions customize to their hearts' content.
The next sections tell you how to get to a boot prompt in order to enter a kernel name and parameters. If you need to know how to install a boot loader or change its configuration, see Section 10.5.
LILO (Linux Loader) has been around for almost as long as the Linux kernel. The LILO boot prompt usually ends with boot:. If your system boots with LILO, it's likely that you get a fancy screen of graphics at boot time, because this is the default for many distributions, including Red Hat Linux. If you see a screen like this, look for a part that reads "Press Control-x for text mode." If you see that message, type CONTROL-X to get to the boot prompt.
If the system defaults to text mode, look at the prompt as soon as it appears. If the prompt says LILO with nothing else, press the SHIFT key to get the rest of the boot prompt to appear. On the other hand, if you get a boot prompt immediately, you need to watch out, because the system likely will boot if you don't type anything in a certain amount of time.
Once you're at a LILO boot prompt, press the TAB key to show a list of kernel and operating system options. The default kernel name is probably something like linux. To boot this kernel with no options, enter linux. To use options, specify them after the kernel name:
linux option1 option2 ...
For example, to boot the system in single-user mode, type this:
Or, to boot linux in single-user mode with the root filesystem as /dev/hda3 instead of your normal default, type this:
linux root=/dev/hda3 -s
GRUB stands for Grand Unified Bootloader, a system that is slowly replacing LILO. GRUB has plenty of whiz-bang features, but most important is its ability to navigate filesystems, so you can read files without loading a kernel. Wiseguy Solaris and BSD administrators like to say that they have enjoyed this capability for some time.
GRUB has a menu interface that's easy enough to navigate, but if you need to boot from a different kernel, change the root partition, or supply extra kernel parameters, you should get into the mini-shell. Press c at the menu to get this prompt:
Let's say that you want to boot the kernel at /boot/vmlinuz with a root of /dev/hda3. Furthermore, your system is messed up, so you need single-user mode with the -s kernel option. Type the following at the GRUB prompt:
root (hd0,2) kernel /boot/vmlinuz root=/dev/hda3 -s boot
The root (hd0,2) line sets GRUB's idea of the current root partition — that is, the filesystem where GRUB expects to find the kernel. hd0 is the first hard drive (that is, the first disk that GRUB finds; for example, the Linux device /dev/hda if this is your first hard disk). However, 2 specifies the third partition (/dev/hda3) because GRUB partition numbers start at 0.
The word kernel sets a kernel image and its parameters. /boot/vmlinuz refers to a kernel image file on (hd0,2). Unfortunately, GRUB does not normally pass the information from the preceding root() line on to the kernel, so you should always specify root=partition as a kernel parameter.
You can combine the root and kernel lines by preceding the kernel image with the GRUB root partition. Therefore, the preceding two lines could be written as the single line kernel (hd0,2)/boot/vmlinuz root=/dev/hda3 -s.
The last line, boot, tells GRUB to load and execute the kernel image.
On certain systems (especially those with SCSI disks and stock kernels), you may need an initial RAM disk:
See Section 10.5.4 for information on why you may need an initial RAM disk.
In case you're trying to boot a partition with another boot loader (such as a Windows partition) by hand with GRUB, try the following, where partition uses the GRUB device syntax explained earlier (e.g., hd(0,1)):
rootnoverify partition makeactive chainloader +1 boot
There are many other ways to boot a kernel, including from DOS via LOADLIN or SYSLINUX, over the network, or even directly from the PC BIOS with LinuxBIOS! Most other boot loaders work like LILO, although some do not support the TAB key to list options. You may need to pay attention to boot diagnostics for this information. However, the way you enter parameters is usually identical to LILO and GRUB.
When something goes wrong with the system, an administrator's first recourse for booting quickly to a usable state is single-user mode. The idea is that the system quickly boots to a root shell instead of going through the whole mess of services. On Linux, single-user mode is usually runlevel 1. You may need to type the root password to enter single-user mode.
Common tasks in single-user mode include the following:
Checking filesystems after a system crash
Fixing problems in critical files, such as /etc/fstab, /etc/passwd, and /etc/inittab
Restoring from backups after a system crash
Don't expect too many amenities in single-user mode. You may need to set the terminal type (enter TERM=linux) to get full-screen editors to work, and the network may not be available. You can configure the network and other systems by hand if necessary, but it's a pain.
When you finish with single-user mode, you can exit the shell to see if the system starts normally. However, it's usually a good idea to reboot the system, because the transition from single-user mode to regular multi-user mode is not always perfect.
If you have a real mess on your hands, and even single-user mode doesn't work, you can try the -b kernel parameter for an emergency boot shell instead of any kind of orderly startup. This does not mount the root filesystem as read-write or give you much of anything else, so you'll probably need to do some remounting, and possibly mount the /proc filesystem before getting anything useful done. However, if things are really this broken, you might consider using a rescue CD-ROM instead of this rudimentary emergency boot shell mode. You may also be able to get an emergency boot shell by using the init=/bin/sh kernel parameter.
Finally, if you break your kernel or boot loader, you won't be able to get to single-user mode without extra help. You can often boot your system with a kernel from a bootable CD-ROM by passing the root parameter to the CD-ROM's kernel boot loader. Your system might look somewhat strange without your regular kernel, but you should still be able to move files around or perhaps even compile a new kernel to get yourself out of the jam.