Network, Accounts, Printing…
8.8. Configuring the Bootloader
It is probably already functional, but it is always good to know how to configure and install the bootloader in case it disappears from the Master Boot Record. This can occur after installation of another operating system, such as Windows. The following information can also help you to modify the bootloader configuration if needed.
160 The Debian Administrator's Handbook
BACK TO BASICS Master boot record
The Master Boot Record (MBR) occupies the first 512 bytes of the first hard disk, and is the first thing loaded by the BIOS to hand over control to a pro-gram capable of booting the desired operating system. In general, a boot-loader is installed in the MBR, removing its previous content.
8.8.1.Identifying the Disks
CULTURE udev, devfs and/dev/
The/dev/directory traditionally houses so-called “special” files, intended to represent system peripherals (see sidebar “Device access permissions” (page 158))./dev/hda1thus always corresponds to the first partition of the the first IDE hard drive. This static structure does not allow dynamic seing of “ma-jor” and “minor” numbers for these files, which forces kernel developers to limit their number, since a priori assignment of the identifiers prohibits adding more once these conventions are established.
To take into account the characteristics of more and more dynamic, modern computers, the kernel has, at some time, offered an implementation of/dev/
by a virtual filesystem called defvs. In some cases, this makes it easier to find files, since the naming convention uses a hierarchal structure: the first parti-tion of the master hard drive on the first IDE bus was then represented by the file,/dev/ide/host0/bus0/target0/lun0/part1. Not only were these nam-ing conventions not very intuitive, but they were also hard-coded into the kernel which presented problems for hot-pluggable drives because the corre-sponding special file name would vary.
The current solution is the second incarnation of the process, udev, with which the kernel delegates the choice of the device file names to be created to a program in user space. This program (udevd) can then have all of the flexibility of user space to decide what actions to take, naming of peripherals, etc.
Withudev(user-space/dev/), a filesystem is stored in RAM and generated automatically byudevd(and it hides the content of any/dev/that may be stored on-disk).udevdcollaborates with the kernel's hotplug sub-system (see Section 9.11, “Hot Plugging: hotplug” (page213)) to detect the appearance (hotplugging) of devices, then dynamically creates the corresponding special files in/dev/. The content of/dev/is, thus, lost on each reboot, butudev
recreates it systematically.
This mechanism allows the machine to dynamically choose the file name. You can thus keep the same name for a given device, regardless of the connector used or the connection order, which is especially useful when you use various USB peripherals. The partition system on the first IDE hard drive can then be called/dev/hda1for backwards compatibility, or/dev/root-partitionif you prefer, or even both at the same time sinceudevdcan be configured to auto-matically create a symbolic link. Furthermore,/dev/no longer contains useful files at this time. Previously, some kernel modules did not automatically load when you tried to access the corresponding peripheral; henceforth, the pe-ripheral's special file no longer exists prior to loading the module, which is no big deal, since most modules are loaded on boot thanks to automatic hard-ware detection. But for undetectable peripherals (such as older disk drives or PS/2 mice), this doesn't work. Consider adding the modules, floppy, psmouse and mousedev to/etc/modulesin order to force loading them on boot.
Configuration of the bootloader must identify the different hard drives and their partitions.
Linux uses a special filesystem (in “block” mode) stored in the/dev/directory, for this purpose.
Historically,/dev/hdawas the master disk on the first IDE controller, and/dev/hdbits first slave,/dev/hdcand/dev/hddbeing, respectively, the master and slave disks on the second IDE controller, and so on down for any others./dev/sdacorresponded to the first SCSI drive,/dev/
sdbbeing the second, etc. This naming scheme has been unified with the Linux kernel present in Squeeze, and all hard drives (IDE/PATA, SATA, SCSI, USB, IEEE 1394) are now represented by
/dev/sd*.
Each partition is represented by its number on the disk on which it resides: for instance,/dev/
sda1is the first partition on the first disk, and/dev/sdb3is the third partition on the second disk.
The PC architecture (or “i386”) is limited to four “primary” partitions per disk. To go beyond this limitation, one of them must be created as an “extended” partition, and it can then contain additional “secondary” partitions. These secondary partitions must be numbered from 5. Thus the first secondary partition could be/dev/sda5, followed by/dev/sda6, etc.
It is not always easy to remember what disk is connected to which SATA controller, or in third position in the SCSI chain, especially since the naming of hotplugged hard drives (which in-cludes among others most SATA disks and external disks) can change from one boot to another.
Fortunately,udevcreates, in addition to/dev/sd*, symbolic links with a fixed name, which you could then use if you wished to identify a hard drive in a non-ambiguous manner. These sym-bolic links are stored in/dev/disk/by-id. On a machine with two physical disks, for example, one could find the following:
mirexpress:/dev/disk/by-id# ls -l total 0
lrwxrwxrwx 1 root root 9 23 jul. 08:58 ata-STM3500418AS_9VM3L3KP -> ../../
å sda
lrwxrwxrwx 1 root root 10 23 jul. 08:58 ata-STM3500418AS_9VM3L3KP-part1 ->
å ../../sda1
lrwxrwxrwx 1 root root 10 23 jul. 08:58 ata-STM3500418AS_9VM3L3KP-part2 ->
å ../../sda2
[...]
lrwxrwxrwx 1 root root 9 23 jul. 08:58
ata-WDC_WD5001AALS-00L3B2_WD-å WCAT00241697 -> ../../sdb
lrwxrwxrwx 1 root root 10 23 jul. 08:58
ata-WDC_WD5001AALS-00L3B2_WD-å WCAT00241697-part1 -> ../../sdb1
lrwxrwxrwx 1 root root 10 23 jul. 08:58
ata-WDC_WD5001AALS-00L3B2_WD-å WCAT00241697-part2 -> ../../sdb2 [...]
lrwxrwxrwx 1 root root 9 23 jul. 08:58 scsi-SATA_STM3500418AS_9VM3L3KP ->
å ../../sda
lrwxrwxrwx 1 root root 10 23 jul. 08:58 scsi-SATA_STM3500418AS_9VM3L3KP-part1
å -> ../../sda1
162 The Debian Administrator's Handbook
lrwxrwxrwx 1 root root 10 23 jul. 08:58 scsi-SATA_STM3500418AS_9VM3L3KP-part2
å -> ../../sda2 [...]
lrwxrwxrwx 1 root root 9 23 jul. 08:58
scsi-SATA_WDC_WD5001AALS-_WD-å WCAT00241697 -> ../../sdb
lrwxrwxrwx 1 root root 10 23 jul. 08:58
scsi-SATA_WDC_WD5001AALS-_WD-å WCAT00241697-part1 -> ../../sdb1
lrwxrwxrwx 1 root root 10 23 jul. 08:58
scsi-SATA_WDC_WD5001AALS-_WD-å WCAT00241697-part2 -> ../../sdb2 [...]
lrwxrwxrwx 1 root root 9 23 jul. 16:48 usb-LaCie_iamaKey_3ed00e26ccc11a-0:0
å -> ../../sdc
lrwxrwxrwx 1 root root 10 23 jul. 16:48
usb-LaCie_iamaKey_3ed00e26ccc11a-0:0-å part1 -> ../../sdc1
lrwxrwxrwx 1 root root 10 23 jul. 16:48
usb-LaCie_iamaKey_3ed00e26ccc11a-0:0-å part2 -> ../../sdc2 [...]
lrwxrwxrwx 1 root root 9 23 jul. 08:58 wwn-0x5000c50015c4842f -> ../../sda lrwxrwxrwx 1 root root 10 23 jul. 08:58 wwn-0x5000c50015c4842f-part1 ->
å ../../sda1 [...]
mirexpress:/dev/disk/by-id#
Note that some disks are listed several times (because they behave simultaneously as ATA disks and SCSI disks), but the relevant information is mainly in the model and serial numbers of the disks, from which you can find the peripheral file.
The example configuration files given in the following sections are based on the same setup: a single master IDE disk, where the first partition is an old Windows installation and the second contains Debian GNU/Linux.
8.8.2.Configuring LILO
LILO (LInux LOader) is the oldest bootloader — solid but rustic. It writes the physical address of the kernel to boot on the MBR, which is why each update to LILO (or its configuration file) must be followed by the commandlilo. Forgetting to do so will render a system unable to boot if the old kernel was removed or replaced as the new one will not be in the same location on the disk.
LILO's configuration file is/etc/lilo.conf; a simple file for standard configuration is illus-trated in the example below.
# The disk on which LILO should be installed.
# By indicating the disk and not a partition.
# you order LILO to be installed on the MBR.
boot=/dev/sda
# the partition that contains Debian root=/dev/sda2
# the item to be loaded by defaul default=Linux
# the most recent kernel image image=/vmlinuz
label=Linux
initrd=/initrd.img read-only
# Old kernel (if the newly installed kernel doesn't boot) image=/vmlinuz.old
label=LinuxOLD
initrd=/initrd.img.old read-only
optional
# only for Linux/Windows dual boot other=/dev/sda1
label=Windows
Example 8.3 LILO configuration file
8.8.3.GRUB 2 Configuration
GRUB (GRand Unified Bootloader) is more recent. It is not necessary to invoke it after each update of the kernel; GRUB knows how to read the filesystems and find the position of the kernel on the disk by itself. To install it on the MBR of the first disk, simply typegrub-install /dev/
sda.
NOTE GRUB and GRUB 2
Squeeze contains both GRUB version 2 and version 1 (also called “GRUB Legacy”). The grub package installs version 2 (through the package depen-dency system), and offers automatic migration during upgrades from Lenny.
GRUB 1 is still available in the package grub-legacy.
NOTE Disk names for GRUB
GRUB can only identify hard drives based on information provided by the BIOS. (hd0) corresponds to the first disk thus detected, (hd1) the second, etc.
In most cases, this order corresponds exactly to the usual order of disks under Linux, but problems can occur when you associate SCSI and IDE disks. GRUB
164 The Debian Administrator's Handbook
stores correspondences that it detects in the file/boot/grub/device.map. If you find errors there (because you know that your BIOS detects drives in a different order), correct them manually and rungrub-installagain.
Partitions also have a specific name in GRUB. When you use “classical” par-titions in MS-DOS format, the first partition on the first disk is labeled, (hd0,msdos1), the second (hd0,msdos2), etc.
GRUB 2 configuration is stored in/boot/grub/grub.cfg, but this file (in Debian) is generated from others. Be careful not to modify it by hand, since such local modifications will be lost the next timeupdate-grubis run (which may occur upon update of various packages). The most common modifications of the/boot/grub/grub.cfgfile (to add command line param-eters to the kernel or change the duration that the menu is displayed, for example) are made through the variables in/etc/default/grub. To add entries to the menu, you can either create a/boot/grub/custom.cfgfile or modify the/etc/grub.d/50_customfile. For more complex configurations, you can modify other files in/etc/grub.d, or add to them; these scripts should return configuration snippets, possibly by making use of external programs. These scripts are the ones that will update the list of kernels to boot: 10_linuxtakes into consideration the in-stalled Linux kernels;20_linuxtakes into account Xen virtual systems, and30_os-proberlists other operating systems (Windows, Mac OSX, Hurd).
8.8.4.GRUB Legacy Configuration
Version 1 of GRUB can also read filesystems. It is installed using thegrub-install /dev/sda
command.
NOTE Disk names for GRUB Legacy
GRUB Legacy uses the same system for naming disks as GRUB 2, and the same/boot/grub/device.mapfile. On the other hand, it names partitions a lile differently: the first partition on the first disk is labeled (hd0,0), the second (hd0,1), etc.
GRUB's configuration is in the/boot/grub/menu.lstfile (see example).
# Boot automatically after 30 seconds timeout 30
# Boot first entry by default default 0
# If that fails, try the second fallback 1
# Last kernel installed title GNU/Linux
root (hd0,1)
kernel /vmlinuz root=/dev/sda2 initrd /initrd.img
# Old kernel (if the most recent doesn't boot) title GNU/Linux OLD
root (hd0,1)
kernel /vmlinuz.old root=/dev/sda2 initrd /initrd.img.old
# Only for dual boot, Linux/Windows title Microsoft Windows
rootnoverify (hd0,0) makeactive
chainloader +1
Example 8.4 GRUB configuration file
8.8.5.For Macintosh Computers (PowerPC): Configuring Yaboot
Yaboot is the bootloader used by old Macintosh computers using PowerPC processors. They do not boot like PCs, but rely on a “bootstrap” partition, from which the BIOS (or OpenFirmware) executes the loader, and on which theybinprogram installsyabootand its configuration file.
You will only need to run this command again if the/etc/yaboot.confis modified (it is dupli-cated on the bootstrap partition, andyabootknows how to find the position of the kernels on the disks).
Before executingybin, you must first have a valid/etc/yaboot.conf. The following is an ex-ample of a minimal configuration.
# bootstrap partition boot=/dev/sda2
# the disk device=hd:
# the Linux partition partition=3
root=/dev/sda3
# boot after 3 seconds of inactivity
# (timeout is in tenths of seconds) timeout=30
install=/usr/lib/yaboot/yaboot magicboot=/usr/lib/yaboot/ofboot enablecdboot
166 The Debian Administrator's Handbook
# last kernel installed image=/vmlinux
label=linux
initrd=/initrd.img read-only
# old kernel image=/vmlinux.old
label=old
initrd=/initrd.img.old read-only
# only for Linux/Mac OSX dual-boot macosx=/dev/sda5
# bsd=/dev/sdaX and macos=/dev/sdaX
# are also possible
Example 8.5 Yaboot configuration file