102.2 Install a boot manager edit
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.
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 edit
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:
default=0 timeout=10 splashimage=(hd0,0)/grub/splash.xpm.gz title Linux (2.4.18-14) root (hd0,0) kernel /vmlinuz-2.4.18-14 ro root=/dev/hda5 initrd /initrd-2.4.18-14.img
The main sections of the grub.conf/menu.lst file are:
- image that will boot by default (the first entry is 0)
- prompt timeout in seconds
- name of the image
- where the 2nd stage bootloader and kernel are e.g (hd0,0) is /dev/hda1
- path for the kernel starting from the previous root e.g /vmlinuz
- the filesystem root
- 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:
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 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
|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
# For full documentation of the options in this file, see:
# info -f grub -n 'Simple configuration'
/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.