Prerequisites: To get the most from this article, understand these concepts and terms before reading: basic Core Utilities, configuration files, kernel, files, directories, symlinks
These sections were copied here from the Debian Reference originally written by: Copyright © 2001–2005 by Osamu Aoki <osamu#at#debian.org>. Copyright (Chapter 2) © 1996–2001 by Software in the Public Interest.
The computer system undergoes several phases of initialization from the power-on event until it offers the fully functional operating system (OS) to the user.
Here is a rough sequence of events for the default installation of Debian with the Linux kernel on the typical PC platform.
- Execution of the BIOS code.
- Execution of the boot loader code (alternatively called initial program loader, IPL).
- Execution of /init program under the Linux kernel with the expanded initramfs image in memory as the temporary root file system.
- Execution of /sbin/init under the Linux kernel while switching the root file system to the hard disk.
Of course, these can be configured differently. For example, if you compiled your own kernel, you may be skipping the step with the initramfs image. So please do not assume this is the case for your system until you check it yourself.
Let me provide a general overview of this system initialization process. For simplicity, I'll limit discussion to the typical i386 PC platform.
When the power-on event happens, the computer hardware initializes itself and executes BIOS code residing on the read only memory (ROM) from the particular memory location.
Basically this BIOS code performs the basic initialization of the hardware (POST: power on self test) and hands the system control to the next step which you provide. The BIOS code is usually provided with the hardware.
The BIOS startup screen usually indicates what key(s) to press to enter the BIOS setup screen to configure the BIOS behavior. Popular keys used are F1, F2, F10, Esc, Ins, and Del. If your BIOS startup screen is hidden by a nice graphics screen, you may press some keys such as ESC to disable this. These keys are highly dependent on the hardware.
The hardware location and the priority of the code started by the BIOS can be selected from the BIOS setup screen. Typically, the first few sectors of the first found selected device (hard disk, floppy disk, CD-ROM, ...) are loaded to the memory and this initial code is executed. This initial code can be:
- the kernel code of the target OS if it fits in this small space,
- the kernel code of the stepping stone OS such as FreeDOS,
- the boot loader code.
Some modern BIOS may also offer more capability such as the PXE network boot loader which loads initial code via network.
Typically, the system is booted from the specified partition of the primary hard disk partition. The first 2 sectors of the hard disk contain the master boot record (MBR). The disk partition information including the boot selection is recorded at the end of this MBR. The first boot loader code executed from the BIOS for the hard disk occupies the rest of this MBR.
The default install of the Debian system places first stage GRUB boot loader code into the MBR for the PC platform. There are many boot loaders and configuration options available.
The preferred boot loader code which is smart enough to understand disk partitions and file systems such as vfat, ext3, ... during the boot process. The loading of the intrd image is supported.
The older boot loader code which relies on the sector locations of data on the hard disk. The loading of the intrd image is supported.
The boot loader code which understands the MSDOS file system. The loading of the intrd image is supported. This is used by the boot floppy.
The boot loader code which understands the ISO9660 file system. The loading of the intrd image is supported. This is used by the boot CD.
The boot loader program which is started from FreeDOS/MSDOS. The loading of the intrd image is supported.
Neil Turton's MBR
This is a free boot loader code provided by the Debian mbr package and compatible with MSDOS MBR. This starts the boot loader code from one of the partitions on the hard disk. The loading of the intrd image is not supported.
Here initrd is used as a generic term from the boot loader perspective indicating both traditional initrd RAM disk image and new initramfs RAM disk image used for the 2.6 kernel.
For GRUB, the menu configuration file is located at /boot/grub/menu.lst.
/init on the initramfs RAM disk image
The current default Debian system uses the 2.6 series Linux kernel with the initramfs RAM disk image which is a gzipped cpio archive when booted initially. The /init program is executed in this initramfs as a shell script program which initializes the kernel in the user space and hands control over to /sbin/init on the hard disk while switching to the root file system.
This is a preparatory part of boot process. It's an optional process and offers flexibility to the boot process such as adding kernel modules before the main boot process or mounting the root file system as an encrypted one. The commands used in this environment is a stripped down Unix system provided by the busybox etc. Please note that some commands, such as mount, use slightly different syntax.
You can interrupt this part of the boot process to gain root shell by providing break=init etc. to the kernel boot parameter. See /init source for more.
/sbin/init on the hard disk (Init Scripts)
This is the main part of the boot process. The runlevel at the start of this process is "N" (none).
The /sbin/init program initializes the system following the description in the /etc/inittab configuration file. Debian normally uses the traditional sysvinit scheme with the sysv-rc package. See man 8 init, man 5 inittab, and /usr/share/doc/sysv-rc/README.runlevels.gz for the exact explanation.
Following is a simplified overview of this boot process.
- The Debian system goes into runlevel S to initialize the system under the single-user mode to complete hardware initialization etc.
- The Debian system switches itself to one of the specified multi-user runlevels (2 to 5) to start the system services.
The initial runlevel used for multi-user mode is specified with the "init=" kernel boot parameter or in the "initdefault" line of /etc/inittab. The Debian system as installed starts at the runlevel 2.
All scripts executed by the init system are located in the directory /etc/init.d/. There are four other directories which correspond to the multi-user runlevels:
These directories contain relative links to the scripts in /etc/inint.d/. The names of the symlinks in the runlevel directories have the form S<2-digit-number><original-name> or K<2-digit-number><original-name>. The 2-digit-number is used to determine the order in which to run the scripts. When init or telinit commands change the runlevel to <n>:
the script names starting with a K in /etc/rc<n>.d/ are executed in alphabetical order with the single argument stop . (killing services)
the script names starting with an S in /etc/rc<n>.d/ are executed in alphabetical order with the single argument start . (starting services)
For example, if you had the links S10sysklogd and S20exim4 in a runlevel directory, S10sysklogd would run before S20exim4.
The meanings of all the runlevels are as follows:
System bootup (NONE). There is no /etc/rcN.d/ directory.
Halt the system.
Single-user mode on boot. The lower case s can be used as alias.
Single-user mode switched from multi-user mode.
2 ... 5
Multi-user mode. The Debian system does not pre-assign any special meaning differences among these.
Reboot the system.
7 ... 9
Valid multi-user mode but traditional Unix variants don’t use. Their /etc/rc?.d/ directories are not populated when packages are installed.
The configuration decision on the use of the runlevels between 2 and 5, is solely left to the system administrator on the Debian system.
It is not advisable to make any changes to symlinks in /etc/rcS.d/.
Grub - The bootloader for Debian - the first software to be loaded and run by your computer's BIOS
LILO - An alternative to GRUB
Init - the first program that runs after the system is booted
Runlevels - A description of the System V runlevels used by the Debian System
Discover - a hardware identification system used for doing hardware detection at boot time
Udev - a filesystem executing in user space, which allows for dynamic updating of /dev
Long Pause During Boot? - The fix if your system has a long pause during startup
Boot Process Speed Up - Tips to speed up system startup
Init Script Standards - standards for developing Init Scripts External links