3.2 About the GRUB Boot Loader

GRUB can load many operating systems in addition to Oracle Linux and it can chain-load proprietary operating systems. GRUB understands the formats of file systems and kernel executables, which allows it to load an arbitrary operating system without needing to know the exact location of the kernel on the boot device. GRUB requires only the file name and drive partitions to load a kernel. You can configure this information by editing the /boot/grub/grub.conf file, by using the GRUB menu, or by entering it on the command line. A portion of the GRUB bootloader code (stage 1 code) is written to the MBR, and the remainder is written to the /boot partition.

The GRUB bootloader is modular and operates in the following stages:

Stage 1

Stage 1 code is stored in the MBR. This code contains a block list that points to the next stage of GRUB, which is either stage1_5 or stage 2, depending on the file system type.

# dd if=/dev/sda count=1 of=/tmp/MBR
1+0 records in
1+0 records out
512 bytes (512 B) copied, 0.000283544 s, 1.8 MB/s
# file /tmp/MBR
/tmp/MBR: x86 boot sector; GRand Unified Bootloader, stage1 version 0x3,
boot drive 0x80, 1st sector stage2 0x8480e, GRUB version 0.94;
partition 1: ID=0x83, active, starthead 32, startsector 2048, 1024000 sectors;
partition 2: ID=0x8e, starthead 221, startsector 1026048, 82860032 sectors,
             code offset 0x48

An unamended copy of the stage 1 code can be found in the file /boot/grub/stage1.

# file /boot/grub/stage1
/boot/grub/stage1: x86 boot sector; GRand Unified Bootloader, stage1 version 0x3,
GRUB version 0.94, code offset 0x48
Stage 1_5

Stage1_5 code allows GRUB to interpret different types of file system. For some file system types such as ext4, GRUB does not need to load stage1_5. The code for each file system type is stored as files in /boot/grub:

# cd /boot/grub
# ls *stage1_5
e2fs_stage1_5  iso9660_stage1_5  reiserfs_stage1_5  xfs_stage1_5
fat_stage1_5   jfs_stage1_5      ufs2_stage1_5
ffs_stage1_5   minix_stage1_5    vstafs_stage1_5
Stage 2

Stage 2 code reads /boot/grub/grub.conf to determine how to load the kernel. The stage 2 code is stored in the file /boot/grub/stage2:

# ls -al /boot/grub/stage2
-rw-r--r--. 1 root root 125976 Jun 28  2012 /boot/grub/stage2