Translation(s): English - 简体中文
https://www.debian.org/doc/manuals/debian-reference/ch03.en.html - Chapter 3. The system initialization in Debian Reference
These sections were originally 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. It has been rewritten since.
This document may be used under the terms of the GNU General Public License version 2 or higher.
The boot process
The computer system undergoes several phases of initialization after it is turned on. Roughly:
A BootLoader (usually Grub2) finds an operating system (your Debian installation) and starts it.
- The init system launches other programmes and services
Each of these stages can be configured. For example, if you compiled your own kernel, you may skip the initramfs step entirely.
The following sections give an overview of the boot process.
UEFI or BIOS
When the computer is turned on, the hardware is initialized and the computer executes UEFI code (or BIOS code on older systems). This code is usually held in read only memory (ROM) in the hardware. It is usually proprietary (some hardware may support Firmware/Open)
This code initializes hardware and runs basic tests (a Power On Self Test (POST)).
You are likely to see a startup screen, and can interrupt the process by pressing a key: which key to use depends on your hardware, and is often one of F1, F2, F10, Escape, Insert, or Delete. You may be able to hide any graphics by pressing Escape.
Interrupting the process at this stage usually allows you to choose which devices (hard disk, USB, CD-ROM, etc) to use for the rest of the boot process. Some systems let you boot from the network.
Boot loader
Typically, the UEFI or BIOS looks in the first few sectors of the first storage device (hard disk, USB, CD-ROM, etc) for a boot loader. The bootloader is effectively a very small operating system that only exists to launch a more featureful operating system like Debian (some small operating systems like FreeDOS can be run directly from this space and not need a separate boot loader at all).
Exactly where the bootloader is stored depends on whether you are using GPT or MBR-based partitioning.
The default boot loader in Debian is usually Grub2. See BootLoader for alternatives. Grub allows you to choose which kernel to launch, or to launch other operating systems that are installed. It also allows you to edit the kernal command line. See Grub2 for more information.
Initramfs
The default Debian Kernel packages use a initramfs RAM disk image created by initramfs-tools. Using an initramfs stage is usual, but not strictly requires. It ensures critical kernel modules are loaded and allows the user to decrypt the root file system (see Cryptsetup).
You can interrupt this part of the boot process by adding break=init to the kernel command line (this can be done from the grub menu): this will give you a root shell.
The initramfs in Debian is a gzipped cpio archive. The contents of the archive are used as a temporary root system from which a small init program is started. This /init is a shell script which initializes the Linux kernel and, eventually, starts the full /sbin/init programme on the main root partition.
The commands available in the initramfs are usually provided by busybox, and may use a different syntax to the usual command version on the full system (mount is an example of this). See initramfs source for more information.
/sbin/init
This is the main part of boot process. The kernel runs the /sbin/init from the root file system, and this is responsible for starting the rest of the system by mounting other filesystems, starting services and, eventually, allowing the user to log in.
The default init system in Debian is systemd. Alternatives include ?Sysvinit. See Init for more information.
Systemd
Systemd is the default init-system in Debian. It is documented in several manpages and its ?https://systemd.io includes an overview.
Its main function is to act as service manage that starts and monitors services. What to start is controlled by a series of text files in which you can customize by editing files in . See systemd(7) and related man-pages for more information.
Sysvinit
The Sysvinit is an older init system that starts services using shell scripts.
Sysvinit defines a number of runlevels. The runlevel at the start of the boot 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:
/etc/rc2.d
/etc/rc3.d
/etc/rc4.d
/etc/rc5.d
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:
runlevel
directory
meaning
N
none
System bootup (NONE). There is no /etc/rcN.d/ directory.
0
/etc/rc0.d/
Halt the system.
S
/etc/rcS.d/
Single-user mode on boot. The lower case s can be used as alias.
1
/etc/rc1.d/
Single-user mode switched from multi-user mode.
2 ... 5
/etc/rc{2,3,4,5}.d/
Multi-user mode. The Debian system does not pre-assign any special meaning differences among these.
6
/etc/rc6.d/
Reboot the system.
7 ... 9
/etc/rc{7,8,9}.d/
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/.
Other information about Sysvinit
Runlevels - A description of the System V runlevels used by the Debian System
Init Script Standards - standards for developing Init Script
See Also
Grub2 - The default BootLoader for most Debian architectures - the first software to be loaded and run by your computer's BIOS
initramfs - a detailed discussion about the RamDisk image loaded into RAM by the BootLoader
Init - the first program that runs after the system is booted
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
