Arch boot process (简体中文)
This article is intended to give a chronological overview of the Arch boot process and the system files and processes involved, providing links to relevant wiki articles where necessary. Arch famously follows the BSD init convention as opposed to the more common SysV. What this means is that there is little distinction between runlevels, since the system by default is configured to use the same modules and run the same processes on all runlevels. The advantage is that users have a simple way to configure the startup process (see rc.conf); the disadvantage is that some fine-grained configuration options that SysV offers are lost. See Adding Runlevels for a way to hack some SysV-like capabilities into Arch. See Wikipedia:init for more on the distinctions between SysV and BSD style.
系统开机并且执行完开机自检后，BIOS会根据自身设置选择最佳的启动媒介。把控制权传递给该媒介的主引导记录（Master Boot Record）部分。再GNU/Linux系统中，MBR里通常是像GRUB、LILO这样的引导器（bootloader）。引导器通常会给用户一个菜单或者命令行之类的机制，供用户选择和设置。例如双系统的设置。一旦你选择启动Arch时，引导器就会载入Template:Filename 目录下的内核镜像（比如Template:Filename），并解压缩。
The kernel is the core of an operating system. It functions on a low level (kernelspace) interacting between the hardware of the machine, and the programs which use the hardware to run. To make efficient use of the CPU, the kernel uses a scheduler to arbitrate which tasks take priority at any given moment, creating the illusion (to human perception) of many tasks being executed simultaneously.
After the kernel is loaded, it reads from the initramfs (initial RAM filesystem). The purpose of the initramfs is to bootstrap the system to the point where it can access the root filesystem (see FHS for details). This means that any modules that are required for devices like IDE, SCSI, or SATA drives (or USB/FW, if booting off a USB/FW drive) must be loaded. Once the initramfs loads the proper modules, either manually or through udev, it passes control to the kernel and the boot process continues. For this reason, the initrd only needs to contain the modules necessary to access the root filesystem; it does not need to contain every module one would ever want to use. The majority of modules will be loaded later on by udev, during the init process.
The kernel then looks for the program Template:Codeline which resides at Template:Filename. Template:Codeline relies on Template:Codeline, the GNU C library. Libraries are collections of frequently used program routines and are readily identifiable through their filename extension of Template:Filename. They are essential for basic system functionality. This part of the boot process is called early userspace.
init: The Arch boot scripts
The main Arch startup process is initiated by the program Template:Codeline, which spawns all other processes. The purpose of Template:Codeline is to bring the system into a usable state, using the boot scripts to do so. As previously mentioned, Arch uses BSD-style boot scripts. Template:Codeline reads the file Template:Filename; the default Template:Filename begins with the following:
The first uncommented line defines the default system runlevel (3). When the kernel calls init:
- First, the main initialization script is run, Template:Filename (a Bash script).
- If started in single user mode (runlevel 1 or S), the script Template:Filename will be run.
- If in any other runlevel (2-5), Template:Filename is run instead.
- The last script to run will be Template:Filename, which is empty by default.
Template:Filename is a huge startup script that basically takes care of all hardware configuration plus a number of general initialization tasks. It can be identified by its first task, printing the lines:
Arch Linux http://www.archlinux.org Copyright 2002-2007 Judd Vinet Copyright 2007-2010 Aaron Griffin Distributed under the GNU General Public License (GPL)
A rough overview of its tasks:
- Sources the Template:Filename script
- Sources the Template:Filename script
- Displays a welcome message
- Mounts various virtual file systems
- Creates dummy device files
- Starts minilogd
- Outputs messages from dmesg
- Configures the hardware clock
- Empties the Template:Filename file
- Starts udev and checks for udev events
- Starts the loopback interface
- Loads modules from the Template:Codeline array defined in rc.conf
- Configures RAID and encrypted filesystem mappings
- Runs a forced check of partitions (fsck) if the /etc/fstab file contains instructions to do so
- Mounts local partitions and swap (networked drives are not mounted before a network profile is up)
- Activates swap areas
- Sets the hostname, locale and system clock as defined in Template:Filename
- Removes various leftover/temporary files, such as Template:Filename
- Configures the locale, console and keyboard mappings
- Sets the console font
- Writes output from dmesg to Template:Filename
Template:Filename is a script and not a place for settings. It sources (i.e. reads and inherits variables and functions) rc.conf for settings and Template:Filename for the functions that produce its graphical output (nice colors, alignments, switching 'busy' to 'done', etc.) There is no particular need to edit this file, although some may wish to do so in order to speed up the boot process.
Single-user mode will boot straight into the root user account and should only be used if one cannot boot normally. This script ensures no daemons are running except for the bare minimum: syslog-ng and udev. The single-user mode is useful for system recovery where preventing remote users from doing anything that might cause data loss or damage is necessary. In single-user mode, users can continue with the standard (multi-user) boot by entering 'exit' at the prompt.
Template:Filename is run on any multi-user runlevel (i.e. 2, 3. 4 and 5) which basically means any ordinary boot. Typically, users will not notice the transition from Template:Filename to Template:Filename as Template:Filename also uses the functions file to produce output. This script has three tasks:
- First, it runs sysctl (to modify kernel parameters at runtime) which applies the settings in Template:Filename. Arch has very few of these by default; mainly networking settings.
- Secondly, and most importantly, it starts daemons, as per the Template:Codeline array in Template:Filename.
- Finally, it will run Template:Filename.
Template:Filename is the local multi-user startup script. Empty by default, it is a good place to put any last-minute commands the system should run at the very end of the boot process. Most common system configuration tasks (like loading modules, changing the console font, or setting up devices) usually have a dedicated place where they belong. To avoid confusion, ensure that whatever one intends to add to Template:Filename is not already residing in Template:Filename, or any other existing configuration location instead.
When editing this file, keep in mind that it is run after the basic setup (modules/daemons), as the root user, and whether or not X starts. Here is an example which just un-mutes the ALSA sound settings:
Another common usage for Template:Filename is to apply various hacks when one cannot make the ordinary initialization work correctly.
By default, after the Arch boot scripts are completed, the Template:Codeline program prompts users for a login name. After a login name is received, Template:Codeline calls Template:Codeline to prompt for the login password.
Finally, with a successful login, the Template:Codeline program starts the user's default shell. The default shell and environment variables may be globally defined within Template:Filename. All variables within a user's home directory shall take precedence over those globally defined under Template:Filename. For instance, if two conflicting variables are specified within Template:Filename and Template:Filename, the one dictated by Template:Filename shall prevail.
The majority of users wishing to start an X server during the boot process will want to install a display manager, and see Display Manager for details. Alternatively, Start X at Boot outlines methods that do not involve a display manager.