06 – Booting & Boot Managers
December 5, 2009 – 10:16 pmPlease note… This information no longer exists at the referenced locations. This is only a copy of what was available in 2003.
Basic Linux Training™
Booting & Boot Managers
Anita Lewis
Table of Contents
Background
After the BIOS performs the POST (Power On System Test), initializing the screen and keyboard, and testing main memory; it starts verifying the hardware, date, time, and CMOS settings. After reading the CMOS, the BIOS should recognize the first hard disk (including geometry) and start loading the operating system. Depending on the CMOS setup, if you have a CD in the tray it will take precedence, and if there is a floppy inserted then it will take precedence. Up until this point, the sequence is identical on all PCs, independent of operating system (since none has been initialized up to this point), and the PC has access only to peripheral hardware identified in the BIOS.
The BIOS then turns control over to the MBR (Master Boot Record) – a 512-byte data segment on the first hard disk – and executes the code stored in the first 446 byte segment there (the actual code and its capabilities depend on the operating system that created the MBR). The next 64 bytes has space for a partition table for up to four (primary) partitions, and the last two bytes are a special ‘magic number’ which has to be AA55 for the MBR to be valid.
The MBR contains information that determines which partition is the active partition (in other words, which one to boot) and checks (the initial 446 byte segment) whether that marked partition actually contains a valid boot sector (the final 2 byte ‘magic number’).
The interesting thing here is that SCSI drives can hold up to 15 partitions, and IDE up to 63. To get around the four partition limit, one of the four primary partitions can be replaced by an extended partition and that extended partition used as a container for multiple logical partitions. Note, however, the numbering of these logical partitions in Linux always begins at ‘five’ – regardless of how many primary partitions exists.
Boot concepts
Most of you will probably be using pre-installed Windows, and it’s probably set up to use the entire hard disk on one partition. If you intend to add another operating system you’re going to have to resize the existing partition to allow space for it, or add another hard disk. Either option will work – it mainly depends on whether you can recover enough free space on the existing hard disk, and whether you have room for another hard disk.
This presents a number of possibilities for booting:
- You can continue to use Windows as your primary operating system, continue to boot into it by default, and use a floppy disk to boot into Linux.
- You can install a small directory under Windows and boot into Linux from there using loadlin; this is known as boot chaining.
- You can install a boot manager capable of working with all the installed operating systems, or more properly all installed partition types. This will give you the option of selecting any of an arbitrary number of operating systems from a menu and defaulting to one of them after a set time if no choice has been made.
The most commonly used boot manager is lilo, but there are between 20 and 30 others you could use – grub, for example, or OS/2 has a particularly nice one. All Linux distributions will default to either lilo or grub; the latter is the newer program and has more flexibility than the former, so I would recommend it to new users for that reason.
The order of loading is important – primarily because Windows operating systems demand the first primary partition and will overwrite the MBR, The rule of thumb is install Windows first, then Linux; if you are currently dual-booting with Windows and NT/W2K, install Windows first, then NT/W2K, then Linux. This will allow a boot loader that can recognize all these operating systems to be the last one written to the MBR.
lilo
Older versions of lilo had to be installed on a partition ending below cylinder 1024; the latest versions eliminate that barrier, but there are still valid reasons to include a small (10-50 MB) separate partition for /boot (we’ll cover that in the next lesson on partitions).
When started, LILO already has access to both real mode hard disks, and is able to find all the data it needs from the raw hard drives without needing any information on partitioning. Thus, operating systems can be booted from the first as well as from the second hard drive. (You can select any of the installed systems at boot time when using LILO. Press TAB to view the options set up in /etc/lilo.conf).
One of my previous versions of /etc/lilo.conf looked like this:
boot=/dev/hda5
install=/boot/boot.b
map=/boot/map
vga=normal
lba32
prompt
delay=200
image=/vmlinuz
label=potato
root=/dev/hda8
read-only
image=/vmlinuz
label=woody
root=/dev/hda9
read-only
image=/vmlinuz
label=mandrake
root=/dev/hda7
append=" hdc=ide-scsi"
read-only
image=/vmlinuz
label=suse
root=/dev/hda15
read-only
image=/vmlinuz-new
label=potato-new
root=/dev/hda8
read-only
image=/vmlinuz-new
label=woody-new
root=/dev/hda9
read-only
image=vmlinuz-new
label=mandrake-new
root=/dev/hda7
append=" hda=ide-scsi"
read-only
image=/vmlinuz-new
label=suse-new
root=/dev/hda15
read-only
other=/dev/hda1
label=windows
table=/dev/hda
Notice the lba32 line to ignore the cylinder 1024 limit. (Obviously, your BIOS must support this, so simply adding the line to the configuration file is not a substitute for flashing your BIOS or updating it.)
The delay=200 waits 20 seconds before booting the default (the first stanza, potato on /dev/hda8); this is excessively long because I use this machine in demonstrations (a/k/a ‘show and tell‘) – a more reasonable value would be 20-50 or 2-5 seconds for most users, or just enough time to allow you to make another choice if you do not want to boot into the default OS (i.e., the one in the first stanza).
vmlinuz is a symbolic link to the kernel image vmlinuz-2.2.19; vmlinuz-new is a symlink to the newest kernel image I have installed, which happened to be vmlinuz-2.4.2. This way, I only have to update the symlinks but not edit /etc/lilo.conf or run /sbin/lilo when I upgrade the kernel versions.
With this configuration, I could boot into Debian potato or woody, Mandrake (7.1) or S.u.S.E. (7.1), all using either the 2.2.19 or 2.4.2 kernel, or Windows. (We’ll talk more about this particular partition scheme in the next lesson; it’s not especially ‘exemplary’ but it is typical for multi-boot and multi-distribution.)
Any change to /etc/lilo.conf requires running /sbin/lilo before those changes will take effect when you reboot.
Should you decide to remove lilo, you can restore your previous MBR using Linux:
/sbin/lilo -u
or from MS-DOS:
C:\> FDISK /MBR
or from OS/2 with
C:\> FDISK /NEWMBR
Before you you leave fdisk, check the partition table to make sure one of the remaining partitions is tagged ‘bootable.’
Removing a boot manager can be tricky and dangerous! Make doubly sure you can boot all the other operating systems with their respective boot floppies. Note, also, that the boot sector backup does not magically update itself if the partition has been reformatted, nor does the partition table of an MBR backup magically update itself if the disk has been repartitioned
This can lead to a complete or partial loss of your data.
grub
grub is an alternative to lilo that is becoming more popular. It is the default bootloader in some distros. My recommendation to you if you have not already had it installed in the MBR during the installation of Linux, is to try installing it on a floppy disk.
The steps are:
- Install the grub package using your package manager.
- Put a floppy in the drive. It doesn’t matter if you mount the floppy or not at this point.
# grub-install /dev/fd0
This makes the directory /boot/grub and writes GRUB to the floppy boot sector.
-
# update-grub
This will analyze your hard drive and create /boot/grub/menu.lst I found that having a separate /boot was a bit of a drawback here. I tried this on installations of Linux and menu.lst was created flawlessly on the installation where /boot was not a separate partition. For that reason, you may need to do the next step. Note: Depending on your distriburion, the file may be found in /boot/boot/grub and it may be named grub.conf
- Edit menu.lst. Look to see if update-grub found the partitions correctly. Here is the part you need to look at:
## ## End Default Options ## title Debian GNU/Linux, kernel 2.4.20 root (hd0,0) kernel /vmlinuz-2.4.20 root=/dev/hdb2 ro savedefault boot title Debian GNU/Linux, kernel 2.2.20-idepci (Course) root (hd0,0) kernel /vmlinuz-2.2.20-idepci root=/dev/hda3 ro savedefault boot
The above is set to boot two installs of Debian on one of my hard drives. The titles are descriptions that were automatically given by update-grub. I added (Course) to one of them. Next is (root) . This is not the / partition. For these installs I am using the same separate /boot partition. update-grub initially had (hd1,1) there, and that was wrong. /boot is actually on /dev/hda1.
This leads us to the nomenclature grub uses for partitions. hd stands for hard drive. The number after it indicates which drive where 0 is the first, just as a is the first in the usual Linux drive nomenclature. The second number indicates the partition. The first partition is 0 instead of 1 like we have learned for Linux.
The next line talks about the kernel. First we have its name. It is found in /boot and the name begins with a /, because until that kernel is found, root really is /boot. When the kernel is found and booted, then it is going to want to know where the root for your system is going to be. You tell it on that same line and you tell it in Linux nomenclature, because the one in charge now is Linux. GRUB has done it’s job. As you can see above, there are two different kernels and two different root partitions. I did not have to edit this line.
This is the basic idea of installing grub. There are more options and parameters that you may need to read about for your system. You may need to boot Windows. This is the example listed in my menu.lst. I’m not booting it on this computer; so I don’t know how it works. In this case, the root would be correct, because the kernel of Windows would be on that first drive and first partition.
title Windows 95/98/NT/2000 root (hd0,0) makeactive chainloader +1
- Copy menu.lst to the floppy.
mount -t ext2 /dev/fd0 /mnt cd /boot/grub cp menu.lst /mnt umount /mnt
- Leave the floppy in and reboot. If bad things happen and it doesn’t boot, just remove the floppy and boot in whatever way you did before. You have not destroyed your MBR. By the way, you can install LILO on a floppy in a similar way by editing /etc/lilo.conf and replacing /dev/hdx with /dev/fd0 in the line which has: boot=
loadlin
Historically, new users have had a lot of trouble getting lilo to work, and have had to resort to booting into Linux from a floppy (which is terribly slow given that the floppy drive works at 360 RPM, while common hard drives work at 5400 or 7200 RPM). In those instances, a better solution is to create a small directory C:\loadlin and copy loadlin.exe (which is available on your CD under /dosutils (or some variation) and run the executable. You’ll need to copy the kernel image and you may have to edit the batch file to point to the partition containing the Linux root file-system. All the details are in the documentation that will be installed in C:\loadlin.
init
init is responsible for correctly initializing processes started at boot.
Here is the default /etc/inittab from Debian (the run-levels and where those configuration files are located will vary from one distribution to another):
# /etc/inittab: init(8) configuration. # $Id: BltBooting.txt,v 1.12 2003/09/18 10:15:08 HenryWhite Exp basiclin $ # The default runlevel. id:2:initdefault: # Boot-time system configuration/initialization script. # This is run first except when booting in emergency (-b) mode. si::sysinit:/etc/init.d/rcS # What to do in single-user mode. ~~:S:wait:/sbin/sulogin # /etc/init.d executes the S and K scripts upon change # of runlevel. # # Runlevel 0 is halt. # Runlevel 1 is single-user. # Runlevels 2-5 are multi-user. # Runlevel 6 is reboot. l0:0:wait:/etc/init.d/rc 0 l1:1:wait:/etc/init.d/rc 1 l2:2:wait:/etc/init.d/rc 2 l3:3:wait:/etc/init.d/rc 3 l4:4:wait:/etc/init.d/rc 4 l5:5:wait:/etc/init.d/rc 5 l6:6:wait:/etc/init.d/rc 6 # What to do when CTRL-ALT-DEL is pressed. ca:12345:ctrlaltdel:/sbin/shutdown -t1 -a -r now # Action on special keypress (ALT-UpArrow). kb::kbrequest:/bin/echo "Keyboard Request--edit /etc/inittab to let this work." # What to do when the power fails/returns. pf::powerwait:/etc/init.d/powerfail start pn::powerfailnow:/etc/init.d/powerfail now po::powerokwait:/etc/init.d/powerfail stop # /sbin/getty invocations for the runlevels. # # The "id" field MUST be the same as the last # characters of the device (after "tty"). # # Format: # <id>:<runlevels>:<action>:<process> # This line is special for the Debian installation system. # This file will be replaced when installation completes. 1:2345:respawn:/bin/login root </dev/tty1 >/dev/tty1 2>&1 # 1:23:respawn:/sbin/getty 38400 tty1 2:23:respawn:/sbin/getty 38400 tty2 3:23:respawn:/sbin/getty 38400 tty3 4:23:respawn:/sbin/getty 38400 tty4 5:23:respawn:/sbin/getty 38400 tty5 6:23:respawn:/sbin/getty 38400 tty6 # Example how to put a getty on a serial line (for a terminal) # #T0:23:respawn:/bin/login root </dev/ttyS0 >/dev/ttyS0 2>&1 #T1:23:respawn:/bin/login root </dev/ttyS1 >/dev/ttyS1 2>&1 # T0:23:respawn:/sbin/getty -L ttyS0 9600 vt100 # T1:23:respawn:/sbin/getty -L ttyS1 9600 vt100 # Example how to put a getty on a modem line. # #T3:23:respawn:/sbin/mgetty -x0 -s 57600 ttyS3
To get any real meaning out this, though, you would have to consult the individual files in /etc/init.d/. Rather than do that, check them on your system beginning with /etc/inittab.
Be extremely careful with these files! It doesn’t take much to create an instant FUBAR – and if this file is not kosher you *will* not be able to reboot properly, and you may not be able to boot at all!
Assignments
Certainly not a ‘requirement’ but it may help you to learn and understand the various configuration files if you printed them out and add your personal notes and comments there. Do make a separate backup of /etc to floppy – or copy that directory to some other partition.
Terms and Concepts:
- BIOS
- CMOS
- MBR
- POST (Power On System Test)
- boot chaining
- boot manager
- boot partition
- boot sector
- hardware geometry
- respawn
- runlevel
- /etc/inittab
- /etc/lilo.conf
- /etc/init.d/
- /sbin/getty
- /sbin/lilo
- grub
- init
- lilo
Online:
- http://www.boot-manager.de/english/ – Bootmanager
- http://www.wwnet.net/~stevelim/booting.html – Multi-Booting with LILO
- Multi-booting Solaris
- lilo man page
- There is also a wealth of information at:
http://www.linuxdoc.org/ – The Linux Documentation Project which should habitually be your first stop for documentation.
Copyright © 1997-2002 Henry White. Copyright © 2002-2003 Carmela Carter. Copyright © 2003 Anita Lewis. All Rights Reserved.
Reproduction or redistribution without prior written consent is strictly prohibited. Address comments and inquiries to info@basiclinux.net.
Sorry, comments for this entry are closed at this time.