# 102.2 Install a boot manager

Candidates should be able to select, install and configure a boot manager.
Key Knowledge Areas
* 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.

## Introduction

A boot loader is installed in the MBR. When a system starts, it loads what is in the MBR to RAM. Under Linux there are two main boot loaders:
* Lilo: LInux LOader.
* Grub: GRand Unified Boot Loader.
A boot loader allows you to select the image that you would like to boot from. A system can contain multiple images (operating systems).
A boot loader allows you to interactively run commands and pass parameters to the image that you will boot. The initrd is the driver that will be used to build a filesystem on RAM to mount other filesystems and execute programs.
GRUB is today's default boot loader for many distributions. When installing Windows with Linux, install Windows first and Linux second, because Windows overwrites the MBR without asking.
As explained under the boot processes above, there are two stages to a boot loader. The first stage and second stage. The first stage is the boot sector application that is responsible for loading stage2.

## Grub Boot Loader

Grub understands Linux filesystems and instead of using raw sectors to locate the Linux kernel GRUB can load from an ext2 or ext3 filesystems. GRUB is also capable of directly loading several non Linux operating systems. The GRUB boot loader has a three stages. Stage 1 has the usual job of a primary boot loader but it loads stage 1.5 which is a boot loader which understand a particular file system such as ext2/3, reiserfs etc and once loaded it loads the 2nd boot loader. The 1.5 stage boot loader is located on the first 30 kilobytes of hard disk immediately after the MBR.
Grub can be installed, either by editing the grub configuration file located at /boot/grub/grub.conf or /boot/grub/menu.lst and running grub-install or by invoking the grub shell. When referring to hard disks and partition grub uses the convention (hdx) for hard disks, irrespective of whether they are PATA or SATA disks, and (fdx) for floppy disks, where x refers to the disk number as seen by the BIOS. When a reference to a partition is need the conventions (hdx,n) or (fdx,n) is used, where n is the partition numbered from 0.
A sample of a grub configuration file is given below:
The main sections of the grub.conf/menu.lst file are:
default
* image that will boot by default (the first entry is 0)
timeout
* prompt timeout in seconds
title
* name of the image
root
* where the 2nd stage bootloader and kernel are e.g (hd0,0) is /dev/hda1
kernel
* path for the kernel starting from the previous root e.g /vmlinuz
ro
* read-only
root
* the filesystem root
initrd
* path to the initial root disk
To install the first stage MBR loader on /dev/hda with grub-install you would run the command grub-install (hd0). Alternatively grub can be installed through the grub shell but still requires the grub.conf/menu.lst file. The grub shell can be entered by typing grub. To install the boot loader you need to run the following commands in the shell:
root (hd0,0)
setup (hd0)
The first line tells grub that the /boot partition, where the configuration file is located,is on the first hard disk on partition 1, and the 2nd command tells grub to install the 1st boot loader to the MBR of the first hard disk. An advanatge of Grub is that each time the grub configuration file is updated with an new image for example, grub does not have to be reinstalled as with LILO.
GRUB 2
GRUB 2 is the next generation, a rewrite of what was formerly known as GRUB (i.e. Ver 0.9x), which has, in turn, become GRUB Legacy. GRUB Legacy is no longer being developed. GRUB 2 shares many characteristics with GRUB Legacy, but it also introduces many new changes, this includes better portability, memory management and modularity, supports non-ASCII characters, dynamic loading of modules, and more. There is three locations
The main configuration file has a new name, /boot/grub/grub.cfg, unlike menu.lst, this file can not be edited directly, typically the file is automatically generated by grub-mkconfig command or via update-grub command, which both read scripts located in the /etc/grub.d/ to build grub.cfg file.
* Sample grub.cfg file # # DO NOT EDIT THIS FILE # # It is automatically generated by grub-mkconfig using templates # from /etc/grub.d and settings from /etc/default/grub #
* BEGIN /etc/grub.d/00_header ### if [ -s $prefix/grubenv ]; then set have_grubenv=true load_env fi set default="2" if [ "${prev_saved_entry}" ]; then set saved_entry="${prev_saved_entry}" save_env saved_entry set prev_saved_entry= save_env prev_saved_entry set boot_once=true fi ### END /etc/grub.d/05_debian_theme ###
* BEGIN /etc/grub.d/30_os-prober ### menuentry 'Linux Mint 12 64-bit, 3.0.0-23-virtual (/dev/sda7)' --class linuxmint --class gnu-linux --class gnu --class os { recordfail set gfxpayload=$linux_gfx_mode insmod gzio insmod part_msdos insmod ext2 set root='(hd0,msdos7)' search --no-floppy --fs-uuid --set=root f97658d1-ca33-44fe-81fc-6239f8278a23 linux/boot/vmlinuz-3.0.0-23-virtual root=UUID=f97658d1-ca33-44fe-81fc-6239f8278a23 ro quiet splash vt.handoff=7 initrd/boot/initrd.img-3.0.0-23-virtual } menuentry "Failsafe -- openSUSE 12.1 - 3.1.0-1.2 (on /dev/sda3)" --class gnu-linux --class gnu --class os { insmod part_msdos insmod ext2 set root='(hd0,msdos1)' search --no-floppy --fs-uuid --set=root ee7d61f1-bb6b-4b95-adba-602acb6684ca linux /vmlinuz-3.1.0-1.2-desktop root=/dev/disk/by-id/ata-Hitachi_HTS725050A9A364_110227PCK404GLGZS20J-part3 showopts apm=off noresume edd=off powersaved=off nohz=off highres=off processor.max_cstate=1 nomodeset x11failsafe vga=0x317 initrd /initrd-3.1.0-1.2-desktop } ### END /etc/grub.d/30_os-prober
* BEGIN /etc/grub.d/40_custom ### # This file provides an easy way to add custom menu entries. Simply type the # menu entries you want to add after this comment. Be careful not to change # the 'exec tail' line above. ### END /etc/grub.d/40_custom ######
* Sample /etc/grub.d/ directory # ls -l /etc/grub.d/ -rwxr-xr-x 1 root root 6698 2011-10-01 14:40 00_header -rwxr-xr-x 1 root root 5522 2011-10-01 14:19 05_debian_theme -rwxr-xr-x 1 root root 1183 2011-10-23 18:05 06_mint_theme -rwxr-xr-x 1 root root 7370 2011-10-22 21:01 10_linux -rwxr-xr-x 1 root root 6518 2011-09-20 12:36 10_lupin -rwxr-xr-x 1 root root 6344 2011-10-01 14:40 20_linux_xen -rwxr-xr-x 1 root root 1588 2011-05-03 01:07 20_memtest86+ -rwxr-xr-x 1 root root 7545 2011-10-01 14:40 30_os-prober -rwxr-xr-x 1 root root 214 2011-10-01 14:40 40_custom -rwxr-xr-x 1 root root 95 2011-10-01 14:40 41_custom -rw-r--r-- 1 root root 483 2011-10-01 14:40 README
Here the numbering in the script names defines precedence in the order of execution by the command grub-update or grub-mkconfig.
Let's review the scripts:
* 00_header – is the script that loads GRUB settings from /etc/default/grub, including timeout and default boot entry.
* 05_debian_theme – defines the background, colors and themes.
* 10_linux – loads the menu entries for installed operating systems.
* 20_memtest86+ loads the memtest utility.
* 30_os-prober – is the script that will probe hard disks for other operating systems and add them to the boot menu.
* 40_custom is a template that you can use to create additional entries to be added to the boot menu.
| # If you change this file, run 'update-grub' afterwards to update # /boot/grub/grub.cfg. # For full documentation of the options in this file, see: # info -f grub -n 'Simple configuration' GRUB_DEFAULT=2 #GRUB_HIDDEN_TIMEOUT=0 GRUB_HIDDEN_TIMEOUT_QUIET=true GRUB_TIMEOUT=10 GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null | echo Debian` GRUB_CMDLINE_LINUX_DEFAULT="quiet splash" GRUB_CMDLINE_LINUX="" Uncomment to enable BadRAM filtering, modify to suit your needs # This works with Linux (no patch required) and with any kernel that obtains # the memory map information from GRUB (GNU Mach, kernel of FreeBSD ...) #GRUB_BADRAM="0x01234567,0xfefefefe,0x89abcdef,0xefefefef" Uncomment to disable graphical terminal (grub-pc only) #GRUB_TERMINAL=console The resolution used on graphical terminal # note that you can use only modes which your graphic card supports via VBE # you can see them in real GRUB with the command `vbeinfo' #GRUB_GFXMODE=640x480 Uncomment if you don't want GRUB to pass "root=UUID=xxx" parameter to Linux #GRUB_DISABLE_LINUX_UUID=true Uncomment to disable generation of recovery mode menu entries #GRUB_DISABLE_RECOVERY="true" Uncomment to get a beep at grub start #GRUB_INIT_TUNE="480 440 1" |
/etc/default/grub contains menu settings customization, such as default menu entry and boot default timeout.
New changes and features can be summarised as follows.
* grub.cfg is the main configuration
* scripts files located in /etc/grub.d/ are used to generete grub.cfg
* partition numbers in GRUB device names now start at 1, not 0.
* can read files directly from LVM and RAID devices.
* Many facilities are dynamically loaded as modules allowing flexible built of core image.
* Boot stages are no more, image files have been reorganised.
* Supports more file systems, including ext4, NTFS and HFS+.
* After adding or editing of script(s), update-grub command must be run to rebuild grub.cfg with updates.
Used files, terms and utilities:
* /boot/grub/menu.lst, grub.cfg and other variations.
* grub-install
* MBR
* superblock
Previous Chapter | Next Chapter