4. Boot Loaders
Invocation of the boot loader usually occurs in one of two ways:
o BIOS loads the first stage boot loader from the drive’s MBR.
o BIOS loads another boot loader which then loads the first stage boot loader from a partition’s boot sector.
The first stage boot loader is also known as Initial Program Loader (IPL). It must be less than 512 bytes in size, so it is fairly limited. It’s primary job is to load a more functional boot loader (a.k.a. the second stage boot loader).
There are two different ways to configure a boot loader:
o Install the first stage of the boot loader on the MBR. It can then be configured to pass control to any desired operating system.
o Install the first stage of the boot loader in the boot sector of a partition. Another boot loader is then installed on the MBR. This other boot loader must be configured to pass control to the Linux boot loader.
1. Configuration File
prompt # Present lilo prompt so user can interact with lilo
timeout=50 # Timeout in milliseconds to wait for user interaction
default=linux # Default image to boot
boot=/dev/hda6 # Specifies boot device (Location to install primary boot loader)
# To install in the MBR, specify /dev/hda
map=/boot/map # Location of map file
install=/boot/boot.b # Location of Second stage boot loader
password=some_passwd # A password required to boot
restricted # Password only required if options are entered at boot prompt
message=/boot/message # Text message or splash screen (PCX) that will be displayed at boot time.
# Image definition
image=/boot/vmlinuz-2.4.7-10 # Specifies location of the virtual memory compressed kernel
initrd=/boot/initrd-2.4.7-10.img # Initial RAM Disk
root=/dev/hda9 # Location of root file system
other=/dev/hda1 # Image definition
See lilo.conf man page for an example.
2. Command Line Options
o -t – Test lilo configuration, but don’t actually install.
o -v – Verbose
3. Boot Time arguments
Command line options can be entered at the boot prompt by appending it to the image that you are booting. For example:
linux root=/dev/hda5 mem=128M 1
Tells lilo to boot the kernel with a label of “linux” into runlevel 1 using /dev/hda5 as the root filesystem. It also states the machine has 128 MB of RAM.
If lilo has been password protected, you will be required to enter the password before booting.
The ‘LILO’ prompt itself can be used to help diagnose boot related errors. The number of letters presented at the LILO prompt can indicate the success or failure of the boot loader.
o L = First stage boot loaded and started. Usually indicates disk problems or invalid options in /etc/lilo.conf.
o LI = Second stage boot loaded from /boot, but /etc/lilo.conf has invalid parameters or /boot/boot.b was moved without re-running /sbin/lilo.
o LIL = Second stage loader started, but the descriptor table can’t be loaded due to a bad disk or invalid parms in /etc/lilo.conf.
o LIL? = Second stage loaded at an incorrect address because of invalid parms in /etc/lilo.conf or /boot/boot.b was moved without re-running /sbin/lilo.
o LIL- = Descriptor table is corrupt. Caused by invalid parms in /etc/lilo.conf or /boot/boot.b was moved without re-running /sbin/lilo.
o LILO = All of LILO loaded correctly.
o Must be installed on the 1st or 2nd IDE drive.
o Limited by BIOS (uses BIOS to load kernel off of disk).
o Must re-run /sbin/lilo every time you change your configuration.
6. Fixing a corrupt MBR
Use lilo to fix:
7. Uninstalling LILO
When LILO overwrites an existing boot sector, it saves a copy of the original boot sector in /boot. The name of the original boot sector will be boot.MMmm where ‘MM’ is the major device number and ‘mm’ is the minor device number. So, the original boot sector from /dev/hda will be /boot/boot.0300.
To restore the original boot sector, use the dd command:
dd if=/boot/boot.0300 of=/dev/hda bs=446 count=1
The original boot sector is actually 512 bytes in length, but the remaining bytes after 446 are part of the partition table and we don’t want to overwrite that in case it’s changed.
8. Initial RAM Disk
o Need: Allows necessary drivers to be loaded at boot time that aren’t compiled directly into the kernel.
o Creation: Use mkinitrd to create the initial RAM disk:
o mkinitrd /boot/initrd-2.4.7-10 2.4.7-10
o Setup: Specify in /etc/lilo.conf file as shown above.
o Command line interface available at boot prompt.
o Can boot from multiple file systems including ext2/3, Reiserfs, FAT, minix, and FFS
o Password protection using MD5
o Changes to configuration file take effect immediately. Don’t have to re-install MBR.
2. Configuration File
# grub.conf generated by anaconda
# Note that you do not have to rerun grub after making changes to this file
# NOTICE: You have a /boot partition. This means that
# all kernel and initrd paths are relative to /boot/, eg.
# root (hd0,0)
# kernel /vmlinuz-version ro root=/dev/hdb5
# initrd /initrd-version.img
default=0 # Default to First definition for booting
timeout=10 # Time in seconds to wait for user interaction
splashimage=(hd1,0)/grub/splash.xpm.gz # Splash Screen
password –md5 $1$???X?t$Z………….. # Password protection
title Red Hat Linux (2.4.17) # First definition
kernel /vmlinuz-2.4.17 ro root=/dev/hdb5
title Red Hat Linux (2.4.17pre2-pk) # Second definition
kernel /vmlinuz-2.4.17pre2-pk ro root=/dev/hdb5
title Red Hat Linux (2.4.17pre2)
kernel /vmlinuz-2.4.17pre2 ro root=/dev/hdb5
title Windows 98SE
3. Boot Time arguments
In order to pass arguments to the image being booted, you must enter menu editing mode, or enter the grub command line. If GRUB has been password protected, you’ll need to enter ‘p’ followed by your password first.
To enter menu editing mode, select and entry and press ‘e’. This will allow you to modify an existing boot setup and pass options to the kernel as well as init.
The GRUB command line allows you to create boot commands that don’t exist in your grub.conf file. You can also run diagnostic tests and view the contents of files on your file systems.
4. Device Names according to Grub
o (fd0) – First floppy drive detected by BIOS
o (hd0) – First hard drive detected by BIOS (SCSI or IDE)
o (hd1,3) – Fourth partition on the 2nd hard drive detected by the BIOS
5. Fixing a corrupt MBR
Use grub-install to fix:
6. Multi-disk scenario
In this situation, we have a nameless OS installed on /dev/hda and Linux installed on /dev/hdb. We need to setup grub to boot both OSes. This involves installing the first stage of grub on the MBR of /dev/hda and the second stage of grub on the /boot partition of /dev/hdb. We will use the grub configuration file listed above. This scenario assumes you either have a working system or are running in rescue mode chroot’d to /mnt/sysimage.
o Launch a grub shell:
Note: The remaining steps will performed from within the “grub shell”.
o Set the root device:
o Specify where to install various boot stages:
install (hd1,0)/grub/stage1 (hd0) (hd1,0)/grub/stage2 p (hd1,0)/grub/grub.conf
The above command line can be broken down as follows:
4.4 DOS Based
1. Loadlin – Capable of booting multiple OSes
2. Syslinux – Used by RH installation program.