Booting

Revision 2 as of 2007-07-22 16:27:21

Clear message

Scope of this page:

  • give a general overview over the booting process (from BIOS to kernel booted and root mounted)
  • demystify some of the black magic in the dozens of installation howtos
  • give clues for some advanced booting schemes
  • link to more specific instructions and howtos

Booting components

BIOS

The BIOS is part of the hardware (firmware). It takes control when you power up the computer. It will on IBM-compatible PCs look for an MBR (master boot record) on a hard drive or a floppy. Newer BIOSes can also boot from a CD drive, or even from USB devices.

On a Macintosh computer this is the OpenFirmware.

MBR (IBM-compatible PCs)

The master boot record is the first sector on a disk and contains in general a partition table for the disk and a simple boot loader. This simple boot loader will in most cases just look for an active partition on the same disk and jump to the boot sector on that partition. The boot sector will contain the real boot loader.

Boot loader

The boot loader can be for instance grub, lilo or yaboot. Or even a Windows boot loader, which "chain-loads" another, more Linux-friendly boot loader. The boot loader locates and loads the kernel and initrd images and finally hands over control to the kernel.

Kernel and initrd

The initrd is an "initial ram disk" and contains a file system with programs and modules that enables the kernel to find the root partition. When the kernel boots, the initrd is already loaded into memory by the boot loader, so that the kernel doesn't have to think about disk access in the first place. The kernel launches the init script inside the initrd file system, which loads hardware drivers and finds the root partition.

Root partition

The root partition contains the operating system (everything that is not kernel and initrd). After the root filesystem has been checked and mounted, the init program on the root partition is called and the operating system boot scripts are run. These scripts involve different /etc/rc scripts and upstart events that eventually gives you a ready-to-use computer with a login screen.

In some cases, the operating system is split over several partitions (like /usr), and these partitions are mounted by the boot scripts as soon as they can be.

Conditions for success

  • First, the BIOS has to find the boot loader and this depends on your hardware's capabilities.
  • Second, the boot loader has to find the kernel and initrd. It will likely use BIOS calls, so this again depends on your BIOS.
  • Finally, the kernel will boot and must, with the help of the initrd, find the root partition

Finding the boot loader

For older computers (old BIOS) the boot loader must be on the first hard drive or a floppy. Some BIOSes gives a selection between different hard drives and even USB drives. Most computers can also boot from a CD.

When the boot loader is split in two, like grub, the first part has to find the second part! Some intelligence can be built into the first part, but in general it has to use BIOS calls to find the second part (see grub section below).

Finding the kernel and initrd

The kernel/initrd must reside somewhere the boot loader can find it.

  • Example: old BIOS and large hard drive: The kernel and initrd can be on a small boot partition on the beginning of the disk.
  • Example: for dual-boot systems: They can even be on a DOS filesystem.

grub

Grub can be installed to the MBR, but since the space is limited, only the "stage1" of grub is installed there. stage1 in turn loads stage1.5 and stage2 which provide the full grub functionality. Grub will find the /boot/grub/menu.lst which configures its interactive menu. The location of the menu.lst, as well as stage1.5 and stage2 files, is hard-coded into grub when it is installed to the boot sector. Grub locates and loads the kernel and the initrd, using BIOS calls and its build-in recognition of file systems (thanks to the different available stage1.5 parts). And finally boots the kernel.

Finding the root partition

The root partition with the operating system can be somewhere completely different than the kernel, for instance on another drive or on a remote computer. In some cases the kernel may not find the root partition on the disk, because the initrd is missing the modules to access the partition. If this your case, rebuild your initrd to include the missing modules (see man mkinitramfs and man update-initramfs).

Other pages

Comments

Would be nice if some grub expert could review this, especially the stage1.5 part. --TormodVolden