Booting

Differences between revisions 4 and 5
Revision 4 as of 2008-08-06 16:35:07
Size: 4945
Editor: localhost
Comment: converted to 1.6 markup
Revision 5 as of 2010-03-31 00:50:46
Size: 5155
Editor: ip72-208-203-158
Comment:
Deletions are marked like this. Additions are marked like this.
Line 7: Line 7:
= Boot up phases =

There are 3 phases to starting up the system:
 1. BIOS
 2. Boot loader
 3. Kernel

== BIOS Phase ==

When the computer begins execution, it starts by executing this code, which is also called the firmware, as it is normally stored in a permanent form of memory, such as ROM, on the computer's motherboard. On a Macintosh computer this is the Open``Firmware.

This code must initialize the hardware other than the CPU, and obtain the code for the next step, the boot loader.
Modern computers provide several possibilities for the boot loader and the choice is normally set on the BIOS startup screen.

== Boot Loader Phase ==

There are several possible types of boot loaders and ways for the BIOS to obtain them.

A. A boot loader stored in the first sector of a hard disk, the Master Boot Record, or MBR. This may be GRUB or LILO or yaboot or others.

B. A boot loader stored on some other storage device, such as a CDR or USB flash drive.

C. A boot loader which uses the network, such as the Pre-Execution Environment (PXE). This code is normally stored on a ROM on the networking card itself.

The need for the initial parts of the bootloader code on the first part of a storage medium explains why some hard drives are 'bootable' and others are not.

The job of the boot loader is to begin the next phase, loading the kernel and an initial ram disk filesystem.

== Kernel Phase ==

The kernel is the core code of the operating system, providing access to hardware and other services. The bootloader starts the kernel running. To keep kernels to a reasonable size and permit separate modules for separate hardware, modern kernels also use a file system which is present in memory, called an 'initrd' for 'initial ram disk'.

Both the kernel file to load and the initial ram disk are normally specified as options to the boot loader.

The kernel launches the init script inside the initrd file system, which loads hardware drivers and finds the root partition.

== System startup ==

After the kernel is running, the remainder of the operating system is brought online.

First the root partition and filesystem is located, checked and mounted.
Next the init process is started, which runs the initialization scripts.
These scripts involve different /etc/rc scripts and upstart events that
eventually gives you a ready-to-use computer with a login screen.
Line 9: Line 53:

== 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 Open``Firmware.
Line 18: Line 57:
== 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.
== GRUB Boot loader ==
Line 21: Line 59:
Because the GRUB boot loader provides menus of choices and can handle many different forms of hardware, it is larger than the code which can fit in a single MBR. It has 3 stages: stage 1 in the MBR, stage 1.5 in the remainder of the first cylinder of the disk, and stage 2 within in file on the disk.
Line 22: Line 61:
== 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.
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.
Line 25: Line 63:

== 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.
Line 36: Line 70:

== 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.
Line 62: Line 81:
 * http://en.wikipedia.org/wiki/Linux_startup_process
Line 63: Line 83:
= Comments =
Would be nice if some grub expert could review this, especially the stage1.5 part. --TormodVolden

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

Boot up phases

There are 3 phases to starting up the system:

  1. BIOS
  2. Boot loader
  3. Kernel

BIOS Phase

When the computer begins execution, it starts by executing this code, which is also called the firmware, as it is normally stored in a permanent form of memory, such as ROM, on the computer's motherboard. On a Macintosh computer this is the OpenFirmware.

This code must initialize the hardware other than the CPU, and obtain the code for the next step, the boot loader. Modern computers provide several possibilities for the boot loader and the choice is normally set on the BIOS startup screen.

Boot Loader Phase

There are several possible types of boot loaders and ways for the BIOS to obtain them.

A. A boot loader stored in the first sector of a hard disk, the Master Boot Record, or MBR. This may be GRUB or LILO or yaboot or others.

B. A boot loader stored on some other storage device, such as a CDR or USB flash drive.

C. A boot loader which uses the network, such as the Pre-Execution Environment (PXE). This code is normally stored on a ROM on the networking card itself.

The need for the initial parts of the bootloader code on the first part of a storage medium explains why some hard drives are 'bootable' and others are not.

The job of the boot loader is to begin the next phase, loading the kernel and an initial ram disk filesystem.

Kernel Phase

The kernel is the core code of the operating system, providing access to hardware and other services. The bootloader starts the kernel running. To keep kernels to a reasonable size and permit separate modules for separate hardware, modern kernels also use a file system which is present in memory, called an 'initrd' for 'initial ram disk'.

Both the kernel file to load and the initial ram disk are normally specified as options to the boot loader.

The kernel launches the init script inside the initrd file system, which loads hardware drivers and finds the root partition.

System startup

After the kernel is running, the remainder of the operating system is brought online.

First the root partition and filesystem is located, checked and mounted. Next the init process is started, which runs the initialization scripts. These scripts involve different /etc/rc scripts and upstart events that eventually gives you a ready-to-use computer with a login screen.

Booting components

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.

GRUB Boot loader

Because the GRUB boot loader provides menus of choices and can handle many different forms of hardware, it is larger than the code which can fit in a single MBR. It has 3 stages: stage 1 in the MBR, stage 1.5 in the remainder of the first cylinder of the disk, and stage 2 within in file on the disk.

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.

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 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


CategoryBootAndPartition