Difference between revisions of "Arch boot process"

From ArchWiki
Jump to: navigation, search
(Init process: Change to SysVinit.)
(UEFI: link to partition table)
 
(53 intermediate revisions by 19 users not shown)
Line 1: Line 1:
 
[[Category:Boot process]]
 
[[Category:Boot process]]
 
[[Category:About Arch]]
 
[[Category:About Arch]]
[[cs:Arch Boot Process]]
+
[[ar:Arch boot process]]
[[es:Arch Boot Process]]
+
[[cs:Arch boot process]]
 +
[[es:Arch boot process]]
 
[[fr:Processus de boot]]
 
[[fr:Processus de boot]]
[[it:Arch Boot Process]]
+
[[it:Arch boot process]]
[[ru:Arch Boot Process]]
+
[[ja:Arch ブートプロセス]]
[[zh-CN:Arch Boot Process]]
+
[[ru:Arch boot process]]
{{Article summary start}}
+
[[zh-cn:Arch boot process]]
{{Article summary text|A chronological overview of the Arch boot process.}}
+
{{Related articles start}}
{{Article summary heading|Overview}}
+
{{Related|Boot loaders}}
{{Article summary text|{{Boot process overview}}}}
+
{{Related|Master Boot Record}}
{{Article summary heading|Related}}
+
{{Related|GUID Partition Table}}
{{Article summary wiki|fstab}}
+
{{Related|Unified Extensible Firmware Interface}}
{{Article summary wiki|Systemd}}
+
{{Related|mkinitcpio}}
{{Article summary wiki|Autostarting}}
+
{{Related|init}}
{{Article summary end}}
+
{{Related|systemd}}
 +
{{Related|fstab}}
 +
{{Related|Autostarting}}
 +
{{Related articles end}}
  
== Bootloader ==
+
In order to boot Arch Linux, a Linux-capable [[boot loader]] such as [[GRUB]] or [[Syslinux]] must be installed to the [[Master Boot Record]] or the [[GUID Partition Table]]. The boot loader is responsible for loading the kernel and [[initial ramdisk]] before initiating the boot process. The procedure is quite different for [[Wikipedia:BIOS|BIOS]] and [[UEFI]] systems, the detailed description is given on this or linked pages.
After the system is powered-on and the [[Wikipedia:Power-on self-test|POST]] is completed, the BIOS locates the preferred boot medium and transfers control to the [[Master Boot Record]] of this device. On a GNU/Linux machine, often a bootloader such as [[GRUB]] or [[LILO]] is found and loaded from the MBR. The bootloader presents the user with a range of options for boot, e.g. Arch Linux and Windows on a [[Windows and Arch Dual Boot|dual-boot setup]]. Once Arch is selected, the bootloader loads the kernel ({{ic|vmlinuz-linux}}) and the initial root filesystem image ({{ic|initramfs-linux.img}}) into memory and then starts the kernel, passing in the memory address of the image.
+
 
 +
== Firmware types ==
 +
=== BIOS ===
 +
 
 +
A BIOS or Basic Input-Output System is the very first program (firmware) that is executed once the system is switched on. In most cases it is stored in a flash memory in the motherboard itself and independent of the system storage.
 +
 
 +
The BIOS loads the beginning 512 bytes ([[Master Boot Record]]) of the first valid disk in the BIOS disk order. Of these 512 bytes, the first 440 contains the first stage of a boot loader like [[GRUB]], [[Syslinux]] or [[LILO]]. Since very little can be achieved by a program of this size, the second stage (residing on the next disk sectors) is loaded from here and looks up a file stored on the partition itself (the actual bootloader). This then loads an operating system by either chain-loading or directly loading the operating system kernel.
 +
 
 +
=== UEFI ===
 +
UEFI has support for reading both the partition table as well as understanding filesystems. Hence it is not limited by 440 byte code limitation (MBR boot code) as in BIOS systems. It does not use the MBR boot code at all.
 +
 
 +
The commonly used UEFI firmwares support both MBR and GPT [[Partitioning#Partition table|partition table]]. EFI in Apple-Intel Macs are known to also support Apple Partition Map besides MBR and GPT. Most UEFI firmwares have support for accessing FAT12 (floppy disks), FAT16 and FAT32 filesystems in HDDs and ISO9660 (and UDF) in CD/DVDs. EFI in Intel Macs can also access HFS/HFS+ filesystems, in addition to the mentioned ones.
 +
 
 +
UEFI does not launch any boot code in the MBR whether it exists or not. Instead it uses a special partition in the partition table called '''EFI System Partition''' in which files required to be launched by the firmware are stored. Each vendor can store its files under {{ic|<EFI SYSTEM PARTITION>/EFI/<VENDOR NAME>/}} folder and can use the firmware or its shell (UEFI shell) to launch the boot program. An EFI System Partition is usually formatted as FAT32 or (less commonly) FAT16.
 +
 
 +
== System initialization ==
 +
 
 +
=== Under BIOS ===
 +
 
 +
# System switched on - [[Wikipedia:Power-on self-test|Power-on self-test]] or POST process
 +
# After POST, BIOS initializes the necessary system hardware for booting (disk, keyboard controllers etc.)
 +
# BIOS launches the first 440 bytes ([[Master Boot Record]]) of the first disk in the BIOS disk order
 +
# The MBR boot code then takes control from BIOS and launches its next stage code (if any) (mostly [[boot loader]] code)
 +
# The launched actual boot loader
 +
 
 +
=== Under UEFI ===
 +
 
 +
# System switched on. The Power On Self Test (POST) is executed.
 +
# UEFI firmware is loaded. Firmware initializes the hardware required for booting.
 +
# Firmware reads the boot entries in the firmware's boot manager to determine which UEFI application to be launched and from where (i.e. from which disk and partition).
 +
# Firmware launches the UEFI application.
 +
#* This could be the Arch kernel itself (since [[EFISTUB]] is enabled by default).
 +
#* It could be some other application such as a shell or a graphical boot manager.
 +
#* Or the boot entry could simply be a disk. In this case the firmware looks for an [[EFI System Partition]] on that disk and tries to run the fallback UEFI application {{ic|\EFI\BOOT\BOOTX64.EFI}} ({{ic|BOOTIA32.EFI}} on 32-bit systems). This is how UEFI bootable thumb drives work.
 +
 
 +
If [[Secure Boot]] is enabled, the boot process will verify authenticity of the EFI binary by signature.
 +
 
 +
{{Note|On some (poorly-designed) UEFI systems the only way to boot is using a disk boot entry with the fallback UEFI application path.}}
 +
 
 +
=== Multibooting in UEFI ===
 +
 
 +
Since each OS or vendor can maintain its own files within the EFI System Partition without affecting the other, multi-booting using UEFI is just a matter of launching a different UEFI application corresponding to the particular OS's bootloader. This removes the need for relying on chainloading mechanisms of one [[boot loader]] to load another OS.
 +
 
 +
See also [[Dual boot with Windows]].
 +
 
 +
== Boot loader ==
 +
 
 +
The boot loader is the first piece of software started by the [[Wikipedia:BIOS|BIOS]] or [[UEFI]]. It is responsible for loading the kernel with the wanted [[kernel parameters]], and [[mkinitcpio|initial RAM disk]] based on config files.  
  
 
== Kernel ==
 
== Kernel ==
Line 29: Line 80:
  
 
== Init process ==
 
== Init process ==
At the final stage of early userspace, the real root is mounted, and then replaces the initial root filesystem. {{ic|/sbin/init}} is executed, replacing the {{ic|/init}} process.
+
At the final stage of early userspace, the real root is mounted, and then replaces the initial root filesystem. {{ic|/sbin/init}} is executed, replacing the {{ic|/init}} process. Arch uses [[systemd]] as the default [[init]].
 +
 
 +
== Getty ==
 +
[[init]] calls [[getty]] once for each [[Wikipedia:Virtual console|virtual terminal]] (typically six of them), which initializes each tty and asks for a username and password. Once the username and password are provided, getty checks them against {{ic|/etc/passwd}}, then calls [[#Login|login]], which begins a session for the user, and executes the user's shell according to {{ic|/etc/passwd}}. Alternatively, getty may start a display manager if one is present on the system.
 +
 
 +
== Display Manager ==
 +
A [[display manager]] can be configured to replace the getty login prompt on a tty.
 +
 
 +
== Login ==
 +
The ''login'' program begins a session for the user by setting environment variables and starting the user's shell, based on {{ic|/etc/passwd}}.
 +
 
 +
=== Message of the day ===
 +
 
 +
The ''login'' program displays the contents of [[Wikipedia:motd (Unix)|/etc/motd]] (''m''essage ''o''f ''t''he ''d''ay) after a successful login, just before it executes the login shell.
 +
 
 +
It is a good place to display your Terms of Service to remind users of your local policies or anything you wish to tell them.
 +
 
 +
== Shell ==
 +
Once the user's [[shell]] is started, it will typically run a runtime configuration file, such as [[bashrc]], before presenting a prompt to the user. If the account is configured to [[Start X at login]], the runtime configuration file will call [[startx]] or [[xinit]].
  
In the past, Arch use [[SysVinit]] as the init process. Now on new installs, [[Systemd]] is used by default. Existing [[SysVinit]] users are recommended to switch to [[systemd]].
+
== xinit ==
 +
[[xinit]] runs the user's [[xinitrc]] runtime configuration file, which normally starts a [[window manager]]. When the user is finished and exits the window manager, xinit, startx, the shell, and login will terminate in that order, returning to getty.
  
 
== See also ==
 
== See also ==
* [http://archlinux.me/brain0/2010/02/13/early-userspace-in-arch-linux/ Early Userspace in Arch Linux]
+
* [https://web.archive.org/web/20150430223035/http://archlinux.me/brain0/2010/02/13/early-userspace-in-arch-linux/ Early Userspace in Arch Linux]
 
* [http://www.ibm.com/developerworks/linux/library/l-linuxboot/ Inside the Linux boot process]
 
* [http://www.ibm.com/developerworks/linux/library/l-linuxboot/ Inside the Linux boot process]
 
* [http://www.linuxjournal.com/article/4622 Boot with GRUB]
 
* [http://www.linuxjournal.com/article/4622 Boot with GRUB]
Line 40: Line 110:
 
* [[Wikipedia:initrd]]
 
* [[Wikipedia:initrd]]
 
* [http://www.cyberciti.biz/faq/grub-boot-into-single-user-mode/ Boot Linux Grub Into Single User Mode]
 
* [http://www.cyberciti.biz/faq/grub-boot-into-single-user-mode/ Boot Linux Grub Into Single User Mode]
 +
* [https://neosmart.net/wiki/mbr-boot-process/ NeoSmart: The BIOS/MBR Boot Process]

Latest revision as of 11:51, 7 September 2016

In order to boot Arch Linux, a Linux-capable boot loader such as GRUB or Syslinux must be installed to the Master Boot Record or the GUID Partition Table. The boot loader is responsible for loading the kernel and initial ramdisk before initiating the boot process. The procedure is quite different for BIOS and UEFI systems, the detailed description is given on this or linked pages.

Firmware types

BIOS

A BIOS or Basic Input-Output System is the very first program (firmware) that is executed once the system is switched on. In most cases it is stored in a flash memory in the motherboard itself and independent of the system storage.

The BIOS loads the beginning 512 bytes (Master Boot Record) of the first valid disk in the BIOS disk order. Of these 512 bytes, the first 440 contains the first stage of a boot loader like GRUB, Syslinux or LILO. Since very little can be achieved by a program of this size, the second stage (residing on the next disk sectors) is loaded from here and looks up a file stored on the partition itself (the actual bootloader). This then loads an operating system by either chain-loading or directly loading the operating system kernel.

UEFI

UEFI has support for reading both the partition table as well as understanding filesystems. Hence it is not limited by 440 byte code limitation (MBR boot code) as in BIOS systems. It does not use the MBR boot code at all.

The commonly used UEFI firmwares support both MBR and GPT partition table. EFI in Apple-Intel Macs are known to also support Apple Partition Map besides MBR and GPT. Most UEFI firmwares have support for accessing FAT12 (floppy disks), FAT16 and FAT32 filesystems in HDDs and ISO9660 (and UDF) in CD/DVDs. EFI in Intel Macs can also access HFS/HFS+ filesystems, in addition to the mentioned ones.

UEFI does not launch any boot code in the MBR whether it exists or not. Instead it uses a special partition in the partition table called EFI System Partition in which files required to be launched by the firmware are stored. Each vendor can store its files under <EFI SYSTEM PARTITION>/EFI/<VENDOR NAME>/ folder and can use the firmware or its shell (UEFI shell) to launch the boot program. An EFI System Partition is usually formatted as FAT32 or (less commonly) FAT16.

System initialization

Under BIOS

  1. System switched on - Power-on self-test or POST process
  2. After POST, BIOS initializes the necessary system hardware for booting (disk, keyboard controllers etc.)
  3. BIOS launches the first 440 bytes (Master Boot Record) of the first disk in the BIOS disk order
  4. The MBR boot code then takes control from BIOS and launches its next stage code (if any) (mostly boot loader code)
  5. The launched actual boot loader

Under UEFI

  1. System switched on. The Power On Self Test (POST) is executed.
  2. UEFI firmware is loaded. Firmware initializes the hardware required for booting.
  3. Firmware reads the boot entries in the firmware's boot manager to determine which UEFI application to be launched and from where (i.e. from which disk and partition).
  4. Firmware launches the UEFI application.
    • This could be the Arch kernel itself (since EFISTUB is enabled by default).
    • It could be some other application such as a shell or a graphical boot manager.
    • Or the boot entry could simply be a disk. In this case the firmware looks for an EFI System Partition on that disk and tries to run the fallback UEFI application \EFI\BOOT\BOOTX64.EFI (BOOTIA32.EFI on 32-bit systems). This is how UEFI bootable thumb drives work.

If Secure Boot is enabled, the boot process will verify authenticity of the EFI binary by signature.

Note: On some (poorly-designed) UEFI systems the only way to boot is using a disk boot entry with the fallback UEFI application path.

Multibooting in UEFI

Since each OS or vendor can maintain its own files within the EFI System Partition without affecting the other, multi-booting using UEFI is just a matter of launching a different UEFI application corresponding to the particular OS's bootloader. This removes the need for relying on chainloading mechanisms of one boot loader to load another OS.

See also Dual boot with Windows.

Boot loader

The boot loader is the first piece of software started by the BIOS or UEFI. It is responsible for loading the kernel with the wanted kernel parameters, and initial RAM disk based on config files.

Kernel

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 of many tasks being executed simultaneously.

initramfs

After the kernel is loaded, it unpacks the initramfs (initial RAM filesystem), which becomes the initial root filesystem. The kernel then executes /init as the first process. The early userspace starts.

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, SATA, USB/FW (if booting from an external drive) must be loadable from the initramfs if not built into the kernel; once the proper modules are loaded (either explicitly via a program or script, or implicitly via udev), the boot process continues. For this reason, the initramfs 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.

Init process

At the final stage of early userspace, the real root is mounted, and then replaces the initial root filesystem. /sbin/init is executed, replacing the /init process. Arch uses systemd as the default init.

Getty

init calls getty once for each virtual terminal (typically six of them), which initializes each tty and asks for a username and password. Once the username and password are provided, getty checks them against /etc/passwd, then calls login, which begins a session for the user, and executes the user's shell according to /etc/passwd. Alternatively, getty may start a display manager if one is present on the system.

Display Manager

A display manager can be configured to replace the getty login prompt on a tty.

Login

The login program begins a session for the user by setting environment variables and starting the user's shell, based on /etc/passwd.

Message of the day

The login program displays the contents of /etc/motd (message of the day) after a successful login, just before it executes the login shell.

It is a good place to display your Terms of Service to remind users of your local policies or anything you wish to tell them.

Shell

Once the user's shell is started, it will typically run a runtime configuration file, such as bashrc, before presenting a prompt to the user. If the account is configured to Start X at login, the runtime configuration file will call startx or xinit.

xinit

xinit runs the user's xinitrc runtime configuration file, which normally starts a window manager. When the user is finished and exits the window manager, xinit, startx, the shell, and login will terminate in that order, returning to getty.

See also