The Bootloader

How Grub works, booting other OSs

           Nick Urbanik <nicku(at)nicku.org>
Copyright Conditions: GNU FDL (see http://www.gnu.org/licenses/fdl.html  )

A computing department

Grub: Grand Unified Bootloader

A bootloader can be very simple, provide minimal functionality

Can pay money for tools such as System Commander, or BootMagic (with Partition Magic)

Or use lilo, or better still, Grub.

Grub aims to boot anything on an Intel 86 architecture

Booting Windows on an Intel Computer

bios loads MBR (Master Boot Record), first 512 bytes of “first” hard disk to ram bios jumps to this code That code (by default) reads first sector of first active partition, the boot sector boot sector code then loads the operating system

Disk sectors, cylinders

The rings are called cylinders:

OSSI — Bootloader — ver. 1.1 – p. 4/11

Methods of Booting

bios always loads mbr mbr can load a bootloader, such as grub’s stage2 or lilo Booting os directly:

bootloader can load an operating system kernel directly

Chaining bootloaders:

bootloader can load another bootloader which in turn loads an operating system

How grub works

We install “stage1” of grub into mbr

stage1 reads stage1_5 or stage2 from a list of disk blocks

stage1 loads stage1_5 from hard disk

stage1_5 can now read files on the hard disk, and

loads stage2

stage2 of grub provides commands to support many features

Features of grub

support directly loading many different operating system kernels can directly read many file system formats can load a configuration file from disk can decompress files automatically can read any device that the bios recognises is independent of drive geometry can detect all ram supports Logical Block Address mode (lba) supports network booting supports remote (serial) terminals

Installing grub into mbr from floppy

Create a grub installation disk

see the lab sheet to see how Boot computer with this disk, type:

grub> find /boot/grub/stage2
grub> root (hdx,y)
grub> setup (hdx)

Installing grub into mbr from floppy — 2

What happens when type

grub> find /boot/grub/stage2

grub searches all partitions for that file lists the partitions that contain stage2 of grub

What happens when type

grub> root (hdx,y)

The “x” and “y” were found in previous step grub mounts the partition, and determines file system type

Installing grub into mbr from floppy — 3

What happens when type

grub> setup (hdx)

grub copies small stage1 to mbr of disk x installs a list of sectors containing the stage1_5 file aim is so stage1 can load stage1_5 when booting

Booting using grub

bios loads stage1 from mbr stage1 knows which sectors of hard disk contain

stage1_5, so

loads stage1_5 into ram, jumps to that code

stage1_5 can now read the file system containing

stage2

reads stage2 from hard disk stage2 can read the menu in

/boot/grub/grub.conf

stage2 can boot (almost?) any operating system from any disk bios can read