Hardware

The first part of booting involves running code stored in the computer's ROM (Read Only Memory). This code is called BIOS (Basic Input/Output System). BIOS has only two functions:

  1. Memory and device detection and diagnostic checks (also known as "posting")
  2. Loading a bootstrap program from the boot disk into memory. This bootstrap program will eventually load the operating system.

POST

You turn the computer on and the BIOS begins to execute. The first part of BIOS that runs is dubbed POST (Power-On Self Test). Basically, the computer runs diagnostic routines to check the existence and functioning of memory and other devices hooked up to the system. After posting, the rest of BIOS begins to execute.

The Boot Disk

One storage device is called the boot disk; this is the device that holds your operating system. Usually, if there is a disk in your floppy disk, your floppy disk will be the boot disk. Otherwise, the boot disk may be your CD drive or most commonly, one of your hard drives. The point is, BIOS will choose some device attached to your computer and call that the boot disk. That boot disk contains the operating system that will eventually be loaded.

After posting, BIOS will begin to read the 1st physical sector from the boot disk. This is head 0, track 0, sector 1. The computer will begin executing the code contained in this sector. At this point, the next thing that happens depends on whether you're talking about a partitioned boot disk (like a hard drive) or a non-partitioned boot disk (like a floppy or CD drive).

Non Partitioned Boot Disk

The boot disk's first logical sector is called a boot sector. The boot sector must contain a boot record. The boot record is 512 bytes long (the size of a sector) and is organized as:

0x000 - 0x002       A jump instruction to 0x0XX
0x003 -  ...        Disk parameters used by BIOS
0x0XX - 0x1FD       Bootstrap Program
0x1FE - 0x1FF       Holds 0xAA55 (the magic number for BIOS)

The "disk parameters" contain things like the number of tracks per disk, the number of sectors per track, etc. These numbers are stored at well known offsets, so all BIOS's know where to get the pertinant information.

The CPU executes the first line of the boot record, which is a jump to address 0x0XX where XX=3E for Linux and 1E for MS DOS. The bootstrap program loads a more sophisticated loader from elsewhere on the bootdisk. This second loader will then load the operating system.

Partitioned Boot Disk

Hard disks have an additional abstraction, called disk partitioning. In a partitioned hard disk, each partition (logical disk) is treated like a physical disk. A hard drive can have 4 such logical disks (partition). If a partition is a bootable partition then its first sector (logical sector 0. Remember there can be up to 4 sector zero's on a hard drive!) is a boot sector.

In a partitioned disk the physical head 0, track 0, sector 1 contains a partition sector rather than a boot sector. The partition sector proves information that describes the drive's partitioning.

Most Unix systems can boot into either automatic mode or manual mode. Automatic boot is what you're normally used to. Manual boot is the single-user mode that you go into when there's a problem bringing the system up.

In automatic mode, the system brings itself up using initialization and configure scripts without help from the user. In manual mode the system follows the automatic process up to a point but then gives control to the user. Most of the system is non functional and it's in single user mode.

Step In the Boot Process

There are 6 steps in the boot process:

1) Loading and initialization of the kernel
The kernel itself is a program called something like /boot/vmlinuz. The first step is to get the kernel into memory and execute it. Linux is not responsible for loading and running the kernel. This task is usually performed by lilo and won't be discussed here.

Once the kernel is loaded and run, it performs tests to find out how much memory is available. Most kernels run in a fixed amount of memory and know from the outset how much memory they need (except for modules). It will report how much physical memory there is and how much memroy is left after the kernel uses some for its own. On my system:
Memory: 128128k/131072k available (984k kernel code, 412k reserved, 1508k data, 40k init)

2) Device detection and configuration
One of the kernel's first jobs is to check out the system and see what hardware is present. When you compiled the kernel, you told it about what devices it should expect to find. Upon starting, the kernel tries to locate and initialize each device you told it about. Here is an example of my kernel looking for the printer that I configured:
parport0: Printer, Hewlett-Packard HP LaserJet 6MP
Device information at this point is usually underspecified so the kernel tires to determine the other information it needs by probing the bus for devices and asking the appropriate drivers for information. The drivers for devices that are missing or that don't respond to a probe are disabled. Even if a device is later connected to the system, it will not be accessible to unix processes until the machine has been rebooted.

3) System Processes
After basic configuration is complete, the kernel starts the first user space process, named init. Init is the father of all processes (look on your system; it's process 1). I wrote a a page on the init process alone.

At this point, the kernel's role in the bootup is complete. The system is still not functional, though. We still can't accept logins on terminals and almost no system daemons (like sendmail, sysklogd, ftpd) are running. All this is taken care of by init.

4) Operator Intervention (manual boot only)
If the system is being brought up as a manual boot, the kernel will tell init this as a command line option. Init will create a root Bourne shell and wait for it to terminate via cntrl-D or exit before it goes on with the startup procedure.

Only the root partition is mounted, which means you need to mount some filesystems if you want to run commands not on the / partition. Daemons do not normally run in single-user mode, so commands that depend on server processes (like mail) won't work correctly. You need to run fsck by hand.

5) Startup Scripts
Next, init runs a bunch of Bourne shell scripts known as startup scripts. All these scripts are located in /etc/rc.d/init.d but there are links to them in /etc/rc0.d, ..., rc6.d. See my page on init for more info. These scripts do a bunch of things, like:


and many, many more.

6) Multi-User Operation
After the initialization scripts have been run, the system is fully operational, except for the fact that no one can log in. In order for logins to be accepted on a terminal, there must be some kind of getty proces listening on it. init will spawn a getty or mingetty to complete the booting process.