3.2. Booting the PC

Before we can start building a bootable CD, we have to answer a basic question: what does the boot process of a computer look like?

3.2.1. The boot process[4]

TODO: add copyright notice according to http://www.tldp.org/copyright.html!

All PC systems start the boot process by executing code in ROM (specificially, the BIOS, the basic input/output system) to load the first sector of the boot drive. The boot drive is usually the first floppy drive (designated /dev/fd0 in Linux). The BIOS then tries to execute this sector. On most bootable disks, this sector contains either:

  • code from a boot loader, such as LILO, the LInux LOader, or GRUB, the GRand Unified Bootloader, which locates an operating system kernel, loads it and executes it to start the boot proper; or

  • the start of an operating system kernel itself, such as Linux.

TODO: the following remarks about the boot process of raw-copied Linux kernels needs additional (or easier to understand) explanation.

If a Linux kernel has been raw-copied to a diskette, the first sector of the disk will be the first sector of the Linux kernel itself. This first sector will continue the boot process by loading the rest of the kernel from the boot device.

When the kernel is completely loaded, it initializes device drivers and its internal data structures. Once it is completely initialized, it consults a special location in its image called the ramdisk word. This word tells it how and where to find its root filesystem. A root filesystem is simply a filesystem that will be mounted as the root directory, ‘/’. The kernel has to be told where to look for the root filesystem; if it cannot find a loadable image there, it halts. One possible source of trouble are device and/or filesystem drivers necessary for using the root filesystem, that are compiled as modules rather than right into the kernel where they would have to be.

In some boot situations — often when booting from a diskette — the root filesystem is loaded into a ramdisk, which is RAM accessed by the system as if it were a disk. RAM is several orders of magnitude faster than a floppy disk, so system operation is faster from a ramdisk. Also, the kernel can load a compressed filesystem from the floppy and uncompress it onto the ramdisk, allowing many more files to be squeezed onto the diskette.

Once the root filesystem is loaded and mounted, you see a message like:

VFS: Mounted root (ext2 filesystem) readonly.

Once the system has loaded a root filesystem successfully, it tries to execute a particular program, which, in the case of Linux 2.4[5], is either the one specified using the boot time argument init=, /sbin/init, /etc/init, /bin/init, or /bin/sh, in that order, thus creating the first running process (number 1) on the system (also called mother process, init process or root process).[6]

Taking into account the abilities that processes have on Unix systems, this first process now can do just about anything you could imagine. (For example, guess what init=/usr/games/tetris-bsd would do...) But most of the time, the job of the init process is much more sophisticated and provides for runlevels that start and stop daemons (background processes) and multiple virtual terminals using getty. However, these things aren't necessary for the basic understanding of the boot process.

3.2.2. Summary

Now you should know enough to head for the next chapter dealing with bootable Linux floppy disks. In short, the boot process of a PC looks like this:

  • After switching on your computer, software execution starts with executing BIOS code.

  • The BIOS looks for a boot device (often the first floppy device, or /dev/fd0), loads its first sector (the boot sector) and executes this sector.

  • The boot sector code (either a bootloader like LILO or the first sector of the Linux kernel) loads the Linux kernel into memory and executes it.

  • Linux initializes some hardware and itself.

  • Linux starts the rest of the operating system by starting the operating system's second program (after the kernel) to create the init process.



[4] Derived from [Faw02], 3.1. The boot process. The legal exception concerning derived portions applies to this section.

[5] See /usr/src/linux/init/main.c.

[6] A process is an instance of a program running in a computer.