Wednesday, August 31, 2011

Linux Boot Loader => GRUB

Boot loader is a software code that runs before the Operating System and helps in loading the Operating System. Boot loaders usually contain several ways to boot the Operating System kernel and also contain commands for trouble-shooting or passing some values to the kernel while booting.

When a computer with Red Hat Enterprise Linux is powered on, the Red Hat Enterprise Linux Operating System is loaded into memory and started by a boot loader. A boot loader program is located on the system's primary hard drive and the boot loader has the responsibility of loading the Linux kernel with its required necessary files into the computer’s memory.

RedHat enterprise editions for different hardware architecture use different boot loaders. The following table shows the different boot loaders for different hardware platforms.

Architecture

Boot Loaders

AMD32, AMD64,

GRUB

Intel x86, EMT64T

GRUB

Intel Itanium

ELILO

IBM eServer System i

OS/400

IBM eServer System p

YABOOT

IBM System z

z/IPL

The GRUB (GNU GRand Unified Boot loader) is the default boot loader for AMD32, AMD64, Intel x86 and Intel EMT64T based hardware platforms. GRUB (GNU GRand Unified Boot loader) enables the selection of the installed operating system at boot time. GRUB also allows the user to pass arguments to the kernel while booting.

Different stages of Linux booting.

1. The Stage 1 or primary boot loader is read into memory by the BIOS from the Master Boot Record (MBR). The primary boot loader exists on less than 512 bytes of disk space within the MBR and is capable of loading either the Stage 1.5 or Stage 2 boot loader.

2. The Stage 1.5 boot loader is read into memory by the Stage 1 boot loader.

3. The Stage 2 or secondary boot loader is read into memory. The secondary boot loader displays the GRUB menu and command environment. This interface allows the user to select which kernel or operating system to boot, pass arguments to the kernel, or look at system parameters.

4. The secondary boot loader reads the operating system or kernel as well as the contents of /boot/sysroot/ into memory. Once GRUB determines which operating system or kernel to start, it loads it into memory and transfers control of the machine to that operating system.

5) init program is initiated and it will read the inittab file (/etc/inittab) and set up the appropriate runlevel.


A sample grub.cof file is shown below.

The lines beginning with a "#" are comments.



### Beginning of grub.conf ###

# 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/sda2
# initrd /initrd-version.img
#boot=/dev/sda
default=0
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu

#####First Operating System#####

title Red Hat Enterprise Linux Server (2.6.18-8.el5)
root (hd0,0)
kernel /vmlinuz-2.6.18-8.el5 ro root=LABEL=/ rhgb quiet
initrd /initrd-2.6.18-8.el5.img

#####Second Operating System#####

title RedHat Operating System 2
root(hd1,0)
kernel /vmlinuz-2.6.18-8.el5 ro root=/dev/sdb2 rhgb quiet
initrd /initrd-2.6.18-8.el5.img

### End of grub.conf ###

The grub.conf configuration file is explained in detail below.

• The default=0 directive points to the first stanza, which is the default Operating System to boot.

• The timeout=5 directive specifies the time, in seconds, for GRUB to automatically boots the default operating system.

• The splashimage directive locates the graphical GRUB screen.

• The hiddenmenu directive means that the GRUB options are hidden.

A stanza begins with a titile, (the text to be displayed in boot menu for selecting the Operating System) and the next three lines specify the location of the /boot directory, the kernel, and the initial RAM disk (The initial RAM disk (initrd) is an initial root file system that is mounted prior to when the real root file system is available), respectively.

root (hd0,0) - Specifies the boot directory is in first hard disk, first Partition.

kernel /vmlinuz-2.6.18-8.el5 ro root=LABEL=/ rhgb quiet - Specifies the kernel location which is inside the /boot folder. This location is related to the root(hd0,0) statement. The "ro" option specifies the kernel should be opened as read only to protect it from any accidental writes from the initial RAM disk and "rhgb" enables the RedHat Graphical boot option.

initrd /initrd-2.6.18-8.el5.img - Initial RAM disk.

No comments:

Post a Comment