102.2 Install a boot manager

Weight: 2 Description: Candidates should be able to select, install and configure a boot manager.

Objectives

  • Providing alternative boot locations and backup boot options.
  • Install and configure a boot loader such as GRUB Legacy.
  • Perform basic configuration changes for GRUB 2.
  • Interact with the boot loader

Terms and Utilities

  • /boot/grub/menu.lst
  • grub-install
  • MBR
  • superblock

Boot overview

System starts from BIOS and will do a self test called POST. Then it will hand over the boot process to the first sector of master boot record (MBR).

MBR is on track (Cylinder) 0, side (Head) 0 and Sector 1 of the first disk which defines CHS.

MBR is only 512bytes so we need a smart bootloader to handle larger boot managers and even multiple systems. Some of these boot loaders are LILO, GRUB and GRUB2.

Chain Loading is when a boot loaders, loads another boot loader. This is done when a linux bootloader needs to start a Windows system.

LILO

LILO (LInux LOader) is the older of three main linux boot loaders and in new distributions it is not installed by default. Its configuration is in /etc/lilo.conf.

There is a command to generate an initial config: /usr/sbin/liloconfig.

# Originally generated by liloconfig - modified by Ian Shields

# This allows booting from any partition on disks with more than 1024
# cylinders.
lba32

# Specifies the boot device (floppy)
boot=/dev/fd0

# Specifies the device that should be mounted as root.
# If the special name CURRENT is used, the root device is set to the
# device on which the root file system is currently mounted. If the root
# has been changed with  -r , the respective device is used. If the
# variable ROOT is omitted, the root device setting contained in the
# kernel image is used. It can be changed with the rdev program.
root=/dev/sda7

# Bitmap configuration for /boot/coffee.bmp
bitmap=/boot/coffee.bmp
bmp-colors=12,,11,15,,8
bmp-table=385p,100p,1,10
bmp-timer=38,2,13,1

# Enables map compaction:
# Tries to merge read requests for adjacent sectors into a single
# read request. This drastically reduces load time and keeps the map
# smaller. Using COMPACT is especially recommended when booting from a
# floppy disk.
compact

# Install the specified file as the new boot sector.
# LILO supports built in boot sectors, you only need
# to specify the type, choose one from 'text', 'menu' or 'bitmap'.
# new: install=bmp      old: install=/boot/boot-bmp.b
# new: install=text     old: install=/boot/boot-text.b
# new: install=menu     old: install=/boot/boot-menu.b or boot.b
# default: 'menu' is default, unless you have a bitmap= line
# Note: install=bmp must be used to see the bitmap menu.
# install=menu
install=bmp

# Specifies the number of _tenths_ of a second LILO should
# wait before booting the first image.  LILO
# doesn't wait if DELAY is omitted or if DELAY is set to zero.
# delay=20

# Prompt to use certain image. If prompt is specified without timeout,
# boot will not take place unless you hit RETURN. Timeout is in tenths of
# a second.
prompt
timeout=200

# Enable large memory mode.
large-memory

# Specifies the location of the map file. If MAP is
# omitted, a file /boot/map is used.
map=/boot/map

# Specifies the VGA text mode that should be selected when
# booting. The following values are recognized (case is ignored):
#   NORMAL  select normal 80x25 text mode.
#   EXTENDED  select 80x50 text mode. The word EXTENDED can be
#     abbreviated to EXT.
#   ASK  stop and ask for user input (at boot time).
#   <number>  use the corresponding text mode. A list of available modes
#     can be obtained by booting with  vga=ask  and pressing [Enter].
vga=normal

# Defines non-standard parameters for the specified disk.
#disk=/dev/sda
#    bios=0x80

# If you are using removable USB drivers (with mass-storage)
# you will need to tell LILO to not use these devices even
# if defined in /etc/fstab and referenced in /proc/partitions.
# Adjust these lines to your devices:
#
# disk=/dev/sda inaccessible
# disk=/dev/sdb inaccessible

# These images were automagically added. You may need to edit something.

image=/boot/vmlinuz-2.6.31-14-generic
    label="Lin 2.6.31-14"
    initrd=/boot/initrd.img-2.6.31-14-generic
    read-only

image=/boot/vmlinuz-2.6.31-20-generic
    label="Lin 2.6.31-20"
    initrd=/boot/initrd.img-2.6.31-20-generic
    read-only

image=/boot/memtest86+.bin
    label="Memory Test+"
    read-only

# If you have another OS on this machine (say DOS),
# you can boot if by uncommenting the following lines
# (Of course, change /dev/sda1 to wherever your DOS partition is.)
other=/dev/sda6
        label="Fedora 8"

 other=/dev/sda1
   label="Windows XP"

When this config file is created, we have to issue the lilo command to make the disk bootable:

# lilo -v -v
LILO version 22.8, Copyright (C) 1992-1998 Werner Almesberger
Development beyond version 21 Copyright (C) 1999-2006 John Coffman
Released 19-Feb-2007, and compiled at 10:52:38 on Aug 25 2009
Running Linux kernel 2.6.31-14-generic on i686
Ubuntu

raid_setup returns offset = 00000000  ndisk = 0
 BIOS   VolumeID   Device
Reading boot sector from /dev/fd0
pf_hard_disk_scan: ndevs=1
  0800  54085408  /dev/sda
device codes (user assigned pf) = 0
device codes (user assigned) = 0
device codes (BIOS assigned) = 1
device codes (canonical) = 1
mode = 0x03,  columns = 80,  rows = 25,  page = 0
Using BITMAP secondary loader
Calling map_insert_data
Secondary loader: 19 sectors (0x3800 dataend).
Warning: The boot sector and map file are on different disks.
bios_boot = 0x00  bios_map = 0x80  map==boot = 0  map S/N: 54085408
Mapping bitmap file /boot/coffee.bmp
Calling map_insert_file
Compaction removed 592 BIOS calls.
Bitmap: 603 sectors.
BIOS data check was okay on the last boot

Boot image: /boot/vmlinuz-2.6.31-14-generic
Setup length is 26 sectors.
Compaction removed 7452 BIOS calls.
Mapped 7601 sectors.
Mapping RAM disk /boot/initrd.img-2.6.31-14-generic
Compaction removed 14696 BIOS calls.
RAM disk: 14930 sectors.
Added Lin_2.6.31-14 *

Boot image: /boot/vmlinuz-2.6.31-20-generic
Setup length is 26 sectors.
Compaction removed 7468 BIOS calls.
Mapped 7617 sectors.
Mapping RAM disk /boot/initrd.img-2.6.31-20-generic
Compaction removed 14704 BIOS calls.
RAM disk: 14938 sectors.
Added Lin_2.6.31-20

Boot image: /boot/memtest86+.bin
Setup length is 4 sectors.
Compaction removed 243 BIOS calls.
Mapped 254 sectors.
Added Memory_Test+

Boot other: /dev/sda6, loader CHAIN
Pseudo partition start: 43198848
Compaction removed 0 BIOS calls.
Mapped 6 (4+1+1) sectors.
Added Fedora_8

Boot other: /dev/sda1, on /dev/sda, loader CHAIN
Compaction removed 0 BIOS calls.
Mapped 6 (4+1+1) sectors.
Added Windows_XP

 BIOS   VolumeID   Device
  80    54085408    0800
Writing boot sector.
/boot/boot.0200 exists - no boot sector backup copy made.
Map file size: 336896 bytes.
RAID device mask 0x0000
One warning was issued.

-v -v doubles the verbosity! You can have up to 5 -vs!

No you can boot your system from that floppy and you will get a menu to choose one of the boot options.

These are some other LILO switches:

switch meaning
-q show information about the map file. map file is located at /boot/map and contains the boot configs
-R boot the system on the next reboot only. Used for remote systems
-l list information about the Kernel
-u uninstall lilo and restore previous boot record

Please note that pressing TAB when choosing an item in LILO menu, will let you edit that item.

GRUB (version 1 or the Legacy grub)

GRUB (GRand Unified Bootloader) is a newer bootloader than LILO.

The GRUBv1 (actually 0.9) config file is in /boot/grub/grub.conf and most of the times /boot/grub/menu.lst is a symbolic link to it.

A sample grub.conf file for GRUB legacy is shown below.

# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# NOTICE:  You do not have a /boot partition.  This means that
#          all kernel and initrd paths are relative to /, eg.
#          root (hd0,5)
#          kernel /boot/vmlinuz-version ro root=/dev/sda6
#          initrd /boot/initrd-version.img
#boot=/dev/sda6
default=1
timeout=10
splashimage=(hd0,5)/boot/grub/splash.xpm.gz
#hiddenmenu
password --md5 $1$RW1VW/$4XGAklxB7/GJk0uO47Srx1
title Upgrade to Fedora 11 (Leonidas)
    kernel /boot/upgrade/vmlinuz preupgrade \ 
      repo=hd::/var/cache/yum/preupgrade stage2=\
      hd:UUID=8b4c62e7-2022-4288-8995-5eda92cd149b:/boot/upgrade/install.img \
      ks=hd:UUID=8b4c62e7-2022-4288-8995-5eda92cd149b:/boot/upgrade/ks.cfg
    initrd /boot/upgrade/initrd.img
title Fedora (2.6.26.8-57.fc8)
    root (hd0,5)
    kernel /boot/vmlinuz-2.6.26.8-57.fc8 ro root=LABEL=FEDORA8 rhgb quiet
    initrd /boot/initrd-2.6.26.8-57.fc8.img
title Fedora (2.6.26.6-49.fc8)
    root (hd0,5)
    kernel /boot/vmlinuz-2.6.26.6-49.fc8 ro root=LABEL=FEDORA8 rhgb quiet
    initrd /boot/initrd-2.6.26.6-49.fc8.img
title GRUB Menu
    rootnoverify (hd0,1)
    chainloader +1
title Windows
    rootnoverify (hd0,0)
    chainloader +1

As you can see the first part tells grub how it should behave and the second part is describing boot options (OSs).

There are options in this file:

command meaning
# comment
default the default system to boot; starts from 0
timeout how long to wait before autobooting
splashimage background image
password Security is important! will ask this password
title Name of the entery
root The partion to boot. Counting starts from 0. root(hd0,2) is the 3rd partion on the first disk
kernel which kernel image should be loaded
initrd the name of the initial RAM disk. Modules needed by the kernel before the file system is mounted
savedefault remember the last booted item
chainloader another file will act as stage 1 loader. Used for booting Windows systems

GRUB (legacy) commands

After creating the configuration, you need to install the grub on a disk do this with one of these command forms:

# grub-install /dev/fd0
# grub-install '(fd0)'

As other boot managers, you can install grub on a CD, floppy, MBR (/dev/sda, /dev/sdb, ..) or a partition (/dev/sdb2, /dev/sda6, ..).

If you needed to change or reconfigure anything during the startup, just press the e on that item and you'll get an interactive editing environment. Press Enter when done and b for boot.

GRUB2

This is the most common boot loader these days. Its main config file is /boot/grub/grub.cfg and can be created by grub-mkconfig > /boot/grub/grub.cfg. Grub also is highly dependent on a core.img file in /boot/grub.

When you run grub-install /dev/sda, grub2 builds a core image, build a configuration file and install GRUB 2 in your MBR.

These steps can be done separately:

$ grub-install --help
Usage: grub-install [OPTION] install_device
Install GRUB on your drive.

  -h, --help              print this message and exit
  -v, --version           print the version information and exit
  --modules=MODULES       pre-load specified modules MODULES
  --root-directory=DIR    install GRUB images under the directory DIR
                          instead of the root directory
  --grub-setup=FILE       use FILE as grub-setup
  --grub-mkimage=FILE     use FILE as grub-mkimage
  --grub-mkdevicemap=FILE use FILE as grub-mkdevicemap
  --grub-probe=FILE       use FILE as grub-probe
  --no-floppy             do not probe any floppy drive
  --recheck               probe a device map even if it already exists
  --force                 install even if problems are detected
  --disk-module=MODULE    disk module to use

INSTALL_DEVICE can be a GRUB device name or a system device filename.

grub-install copies GRUB images into the DIR/boot directory specified by
--root-directory, and uses grub-setup to install grub into the boot
sector.

Report bugs to <[email protected]>.

There is a command called update-grub as a frontend to grub-mkconfig which looks into the /etc/default/grub and creates a grub.cfg file.

Here is a sample of grub2 configuration file:

### BEGIN /etc/grub.d/05_debian_theme ###                               
set menu_color_normal=white/black
set menu_color_highlight=black/white
### END /etc/grub.d/05_debian_theme ###                                 

### BEGIN /etc/grub.d/10_linux ###                                      
menuentry "Ubuntu, Linux 2.6.31-20-generic" {
        recordfail=1
        if [ -n ${have_grubenv} ]; then save_env recordfail; fi
        set quiet=1
        insmod ext2
        set root=(hd0,7)
        search --no-floppy --fs-uuid --set 8954fa66-e11f-42dc-91f0-b4aa480fa103
        linux   /boot/vmlinuz-2.6.31-20-generic \
          root=UUID=8954fa66-e11f-42dc-91f0-b4aa480fa103 ro   quiet splash
        initrd  /boot/initrd.img-2.6.31-20-generic
}
menuentry "Ubuntu, Linux 2.6.31-20-generic (recovery mode)" {
        recordfail=1
        if [ -n ${have_grubenv} ]; then save_env recordfail; fi
        insmod ext2
        set root=(hd0,7)
        search --no-floppy --fs-uuid --set 8954fa66-e11f-42dc-91f0-b4aa480fa103
        linux   /boot/vmlinuz-2.6.31-20-generic 
         root=UUID=8954fa66-e11f-42dc-91f0-b4aa480fa103 ro single
        initrd  /boot/initrd.img-2.6.31-20-generic
}

.

.

.

.

.

.

.

.

.

.

results matching ""

    No results matching ""