Linux boot managers
A boot loader/manager's primary role is to locate, load and start a selected kernel. They allow for kernel selection and passing of user params to the kernel.
There are two in general use on linux:
- LILO (LInux Loader)
default kernel parameters in /etc/lilo.conf
- GRUB (GRand Unified Bootloader)
default kernel parameters in /boot/grub/grub.conf or /boot/grub/menu.lst
Distributions may vary in the way these are implemented.
LILO requires the lilo command to be run after any changes to it's configuration file, GRUB does not. GRUB may need to be reinstalled if the partition table is altered.
A two stage boot loader
- The first stage is loaded and run by the BIOS, the second stage is
- A map installer utility - the lilo interactive command
Example lilo configuration - /etc/lilo.conf
boot=/dev/sda # Name of disk to boot from, install itself onto
map=/boot/map # Location of map file
install=/boot/boot.b # Use this file as new boot sector, contains
# bootstrap code
compact # Allows lilo faster access to disk, may need
# to remove on old disks
prompt # Boot loader will prompt user, or use
# 'Shift & CTRl or ALT'
timeout=30 # Waits (0.1sec) for user input before continuing
default=linux # Set image/OS with this label as the default
message="Hi" # Optional message to display before the LILO
# prompt, less than 64KB
#message=/boot/message2 # Message parameter may refer to a text file or a
# specially created file in PCX format. If no message
# parameter then a terse prompt is displayed - LILO:
lba32 # Optional - lba32 instead of Linear Sector addressing
password="cleartxt" # Optional - password required to boot. Clear text
restricted # Optional - password required when passing parameters
# to kernel
image=/vmlinuz-2.6.24-23 # Default image to load. (/boot is a separate partition)
label=linux # Label displayed to user
alias=shrike # Optional alias
initrd=/initrd.img-2.6.24-23 # Optional - ram disk. (/boot is a separate partition)
root=/dev/sda2 # Partition that contains the linux image to boot
read-only # Mount root filesystem as read-only, is changed later
append="vga=0x317" # Optional parameters to pass to kernel
other=/dev/sda1 # Like 'image' but refers to partition of non-linux OS
label=win2k # Label to display in OS selection screen
LILO interactive command
-q Query current config
-u Uninstall and restore previous boot record
-C use specified config file
LILO will install itself to wherever the 'boot=' directive in '/etc/lilo.conf' points to.
lilo.conf boot directive examples
boot=/dev/fd0 (LILO will be installed to the diskette in floppy drive fd0)
boot=/dev/hda (LILO will be installed into the MBR of the first ide disk drive)
boot=/dev/sda (LILO will be installed into the MBR of the first scsi disk drive)
A three stage boot loader, Stages 1, 1.5 and 2. It consists of a text based configuration file, usually /boot/grub/menu.lst. This file may well be a symlink to /boot/grub/grub.conf.
Example grub configuration
- Provides a menu interface instead of LILO's prompt
- It can use a password encrypted with the MD5 algorithm as opposed to the plain text password of LILO
- Changes made to the GRUB configuration file do not require GRUB to be reinstalled.
- Does not require a partition to be mounted in order to configure a boot entry for it.
- If you want a different background image for GRUB, you are limited to 14 colours.
- The grub interactive command behaves as a small shell. It provides several commands that allow you to do things such as edit the commands before they are executed, find and load a configuration file, display files using the cat command ...
default saved # 0=>first OS listed,
# 1=>second and so on
timeout 10 # Wait (0.1 sec) for user input
#splashimage (hd0,1)/grub/splash.xpm.gz # Optional splash image to use
#password --md5 $1$gLhU0/$a....Uoe/ # Optional md5 encrypted password
#password topsecret # Or plain text
title Windows 2000 # Title of first OS
root (hd0,0) # Use the boot record here
makeactive # Activate a non-linux boot partition
chainloader +1 # Non-linux OS, load file in 1st. sector
title kernel 2.6.24-27 # Title of second OS
root (hd0,1) # Use the boot record here
kernel /vmlinuz-2.6.24-27 root=/dev/sda5 ro # Kernel image and any parameters
initrd /initrd.img-2.6.24-27 # Ram disk image to load
savedefault # Default OS if 'default saved' exists
title kernel 2.6.24-27 (Recovery) # Title of third OS
kernel /vmlinuz-2.6.24-27 root=/dev/sda5 ro vga=0x317 single
Grub install script
Installs GRUB on a drive. It copies GRUB images into the [DIR]/boot directory specified by '--root-directory' option and uses the grub shell to install grub into the boot sector.
grub-install [option] install_device
install_device Can be a GRUB device name or a system device filename
--root-directory=DIR Install GRUB images under the directory DIR instead of the root directory
--grub-shell=FILE Use FILE as the grub shell
--no-floppy Do not probe any floppy drive
--force-lba Force GRUB to use LBA mode even for a buggy BIOS
--recheck Probe a device map even if it already exists
Install in MBR of first hard disk
$ grub-install /dev/sda
$ grub-install '(hd0)'
Install to floppy
$ umount /dev/fd0
$ grub-install '(fd0)'
$ grub-install /dev/fd0
Install to second partition of second disk
$ umount /dev/sdb
$ grub-install '(hd1,1)'
$ grub-install /dev/sdb2
Check device.map - grub-install
# grub-install --recheck /dev/sda
Probing devices to guess BIOS drives. This may take a long time.
Searching for GRUB installation directory ... found: /boot/grub
'grub-install' looks for '/boot/grub/device.map'. If file does not exist GRUB guesses.
The grub shell
--config-file=FILE Specify stage2 config_file [default=/boot/grub/menu.lst]
--device-map=FILE Use the device map file FILE
--no-config-file Do not use the config file
--read-only Do not write anything to devices
Install in MBR of first hard disk
grub> root (hd0,0)
grub> setup (hd0)
Install to floppy
grub> root (fd0)
grub> setup (fd0)
Generate a menu.lst file
Program to generate GRUB's menu.lst file.
- Looks in /boot for all files which start with "vmlinuz-". Treats these as kernels and creates a menu entry for each.
- Adds initrd lines for ramdisk images found with the same version as kernels found e.g. /boot/vmlinuz-2.4.5 and /boot/initrd-2.4.5
- Creates the initial 'menu.lst' if none exists, after prompting the user.
- After 'update-grub' has been run for the first time, the user is required to edit the generated 'menu.lst'.
# update-grub [-y]
Default update-grub settings - /boot/grub/menu.lst
# kopt=root=/dev/hda1 ro # Options passed to the linux kernel as
# parameters - everything after "kopt="
# groot=(hd0,1) # Grub device from which to load kernel
# alternative=true # Create the alternative boot options in
# the menu entries. 'false' - do not create
# lockalternative=true # Lock the alternative boot options
# lockold=true # Lock the old kernels. 'false' - do not lock
# altoptions=(recovery option) single # Controls what is used for the alternative
# boot options, multiple 'altoptions lines'
# are allowed. Format:
# altoptions=(desc.) kernel cmd-line options
# Desc. is placed in '()', the kernel
# command line options follow
# updatedefault=true # Should grub update the default entry to keep
# booting the same kernel even if a new one is
# installed. 'false' - do not update
Grub2 is the later version of grub, big changes. Most modern Linux systems will be using this. It supports EFI boot.
Grub2 enters recovery mode when it cannot find anything - one thing that will cause this to happen, when labels (UUID) are not being used, is removing partitions that cause the remaining partitions to be re-ordered. When this happens you need to tell grub where it's files are then have it go ahead as normal.
Recover from rearranged partitions - tell grub where everything is
grub recovery> set prefix=(hd0,X)/boot/grub # where X is the partition number where
# /boot/grub resides. If /dev/sda5 then X=5
grub recovery> set root=(hd0,X) # Where root partition resides
grub recovery> insmod normal
grub recovery> normal # Causes grub to continue as normal
This just gets you booted, you still need to ensure that grub is aware of the rearranged partitions. Once the system has booted, open a terminal
Update grub with new partition info
# update-grub # Re-creates all the grub config files
# grub-install /dev/sda # Re-installs grub in MBR of first disk
Run update-grub script 'automagically'
When certain things happen 'update-grub' will be run automatically depending on the configuration in this file.
Example configuration - kernel-img.conf
do_symlinks = yes
relative_links = yes
do_bootloader = no
do_bootfloppy = no
do_initrd = yes
link_in_boot = no
postinst_hook = update-grub
postrm_hook = update-grub
'update-grub' is a stub for 'grub-mkconfig -o /boot/grub/grub.cfg'