Arch boot process: Difference between revisions

From ArchWiki
(update interlanguage links)
(→‎Feature comparison: GRUB's i386-efi target works now, see https://gitlab.archlinux.org/archlinux/packaging/packages/grub/-/issues/5)
 
(81 intermediate revisions by 14 users not shown)
Line 4: Line 4:
[[es:Arch boot process]]
[[es:Arch boot process]]
[[fr:Arch boot process]]
[[fr:Arch boot process]]
[[it:Arch boot process]]
[[ja:Arch ブートプロセス]]
[[ja:Arch ブートプロセス]]
[[pt:Arch boot process]]
[[pt:Arch boot process]]
Line 20: Line 19:
{{Related articles end}}
{{Related articles end}}


In order to boot Arch Linux, a Linux-capable [[#Boot loader|boot loader]] must be set up. 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. A detailed description is given on this or linked pages.
In order to boot Arch Linux, a Linux-capable [[#Boot loader|boot loader]] must be set up. The boot loader is responsible for loading the kernel and [[#initramfs|initial ramdisk]] before initiating the boot process. The procedure is quite different for [[Wikipedia:BIOS|BIOS]] and [[UEFI]] systems. A detailed description is given on this or linked pages.


== Firmware types ==
== Firmware types ==


The firmware is the very first program that is executed once the system is switched on.  
The firmware is the very first program that is executed once the system is switched on.
 
{{Tip|The words BIOS and (U)EFI are often used instead of firmware}}
{{Tip|The words BIOS and (U)EFI are often used instead of firmware}}


Line 35: Line 35:
The [[Unified Extensible Firmware Interface]] has support for reading both the partition table as well as file systems. UEFI does not launch any [[Partitioning#Master Boot Record (bootstrap code)|boot code from the Master Boot Record (MBR)]] whether it exists or not, instead booting relies on boot entries in the [[Wikipedia:Non-volatile random-access memory|NVRAM]].
The [[Unified Extensible Firmware Interface]] has support for reading both the partition table as well as file systems. UEFI does not launch any [[Partitioning#Master Boot Record (bootstrap code)|boot code from the Master Boot Record (MBR)]] whether it exists or not, instead booting relies on boot entries in the [[Wikipedia:Non-volatile random-access memory|NVRAM]].


The UEFI specification mandates support for the [[FAT|FAT12, FAT16, and FAT32]] file systems (see [https://uefi.org/sites/default/files/resources/UEFI_Spec_2_9_2021_03_18.pdf#G17.1019485 UEFI specification version 2.9, section 13.3.1.1]), but any conformant vendor can optionally add support for additional filesystems; for example, [[Wikipedia:HFS+|HFS+]] or [[Wikipedia:APFS|APFS]] in some Apple's firmwares. UEFI implementations also support ISO-9660 for optical discs.
The UEFI specification mandates support for the [[FAT|FAT12, FAT16, and FAT32]] file systems (see [https://uefi.org/specs/UEFI/2.10/13_Protocols_Media_Access.html#file-system-format-1 UEFI specification version 2.10, section 13.3.1.1]), but any conformant vendor can optionally add support for additional file systems; for example, [[Wikipedia:HFS+|HFS+]] or [[Wikipedia:APFS|APFS]] in some Apple's firmwares. UEFI implementations also support [[Wikipedia:ISO_9660|ISO 9660]] for optical discs.


UEFI launches EFI applications, e.g. [[#Boot loader|boot loaders]], boot managers, [[UEFI shell]], etc. These applications are usually stored as files in the [[EFI system partition]]. Each vendor can store its files in the EFI system partition under the {{ic|/EFI/''vendor_name''}} folder. The applications can be launched by adding a boot entry to the NVRAM or from the UEFI shell.
UEFI launches EFI applications, e.g. [[#Boot loader|boot loaders]], boot managers, [[UEFI shell]], etc. These applications are usually stored as files in the [[EFI system partition]]. Each vendor can store its files in the EFI system partition under the {{ic|/EFI/''vendor_name''}} directory. The applications can be launched by adding a boot entry to the NVRAM or from the UEFI shell.


The UEFI specification has support for legacy [[#BIOS|BIOS]] booting with its [[Wikipedia:Unified Extensible Firmware Interface#CSM booting|Compatibility Support Module (CSM)]]. If CSM is enabled in the UEFI, the UEFI will generate CSM boot entries for all drives. If a CSM boot entry is chosen to be booted from, the UEFI's CSM will attempt to boot from the drive's MBR bootstrap code.
The UEFI specification has support for legacy [[#BIOS|BIOS]] booting with its [[Wikipedia:Unified Extensible Firmware Interface#CSM booting|Compatibility Support Module (CSM)]]. If CSM is enabled in the UEFI, the UEFI will generate CSM boot entries for all drives. If a CSM boot entry is chosen to be booted from, the UEFI's CSM will attempt to boot from the drive's MBR bootstrap code.
Line 51: Line 51:
# BIOS launches the first 440 bytes ([[Partitioning#Master Boot Record (bootstrap code)|the Master Boot Record bootstrap code area]]) of the first disk in the BIOS disk order.
# BIOS launches the first 440 bytes ([[Partitioning#Master Boot Record (bootstrap code)|the Master Boot Record bootstrap code area]]) of the first disk in the BIOS disk order.
# The boot loader's first stage in the MBR boot code then launches its second stage code (if any) from either:
# The boot loader's first stage in the MBR boot code then launches its second stage code (if any) from either:
#* next disk sectors after the MBR, i.e. the so called post-MBR gap (only on a MBR partition table).
#* next disk sectors after the MBR, i.e. the so called post-MBR gap (only on a MBR partition table),
#* a partition's or a partitionless disk's [[Wikipedia:Volume boot record|volume boot record (VBR)]].
#* a partition's or a partitionless disk's [[Wikipedia:Volume boot record|volume boot record (VBR)]],
#* the [[BIOS boot partition]] ([[GRUB]] on BIOS/GPT only).
#* for [[GRUB]] on a GPT partitioned disk—a GRUB-specific [[BIOS boot partition]] (it is used in place of the post-MBR gap that does not exist in GPT).
# The actual [[#Boot loader|boot loader]] is launched.
# The actual [[#Boot loader|boot loader]] is launched.
# The boot loader then loads an operating system by either chain-loading or directly loading the operating system kernel.
# The boot loader then loads an operating system by either chain-loading or directly loading the operating system kernel.
Line 79: Line 79:
== Boot loader ==
== Boot loader ==


A boot loader is a piece of software started by the firmware ([[Wikipedia:BIOS|BIOS]] or [[UEFI]]). It is responsible for loading the kernel with the wanted [[kernel parameters]], and [[mkinitcpio|initial RAM disk]] based on configuration files. In the case of UEFI, the kernel itself can be directly launched by the UEFI using the [[EFISTUB|EFI boot stub]]. A separate boot loader or boot manager can still be used for the purpose of editing kernel parameters before booting.
A boot loader is a piece of software started by the firmware ([[Wikipedia:BIOS|BIOS]] or [[UEFI]]). It is responsible for loading the kernel with the wanted [[kernel parameters]] and any external initramfs images. In the case of UEFI, the kernel itself can be directly launched by the UEFI using the [[EFISTUB|EFI boot stub]]. A separate boot loader or boot manager can still be used for the purpose of editing kernel parameters before booting.


{{Warning|A boot loader must be able to access the kernel and initramfs image(s), otherwise the system will not boot. Thus, in a typical setup, it must support accessing {{ic|/boot}}. That means it must have support for everything starting from the block devices, stacked block devices (LVM, RAID, dm-crypt, LUKS, etc) and ending with the file system on which the kernel(s) and initramfs image(s) reside.}}
{{Warning|To successfully boot Arch, the boot loader needs access to the kernel and initramfs image(s) which typically reside in the {{ic|/boot}} directory. That means the boot loader must have support for everything starting from the block devices, stacked block devices (LVM, RAID, dm-crypt, LUKS, etc.) and ending with the file system on which the kernel(s) and initramfs image(s) reside.


{{Note|Loading [[Microcode]] updates requires adjustments in boot loader configuration. [https://archlinux.org/news/changes-to-intel-microcodeupdates/]}}
Since almost no boot loader supports such stacked block devices and since file systems can introduce new features which may not yet be supported by any boot loader (e.g. {{Issue|archlinux/packaging/packages/grub|7}}, {{Bug|79857}}, {{Bug|59047}}, {{Bug|58137}}, {{Bug|51879}}, {{Bug|46856}}, {{Bug|38750}}, {{Bug|21733}} and [[fscrypt]] encrypted directories), using a separate [[Partitioning#/boot|/boot partition]] with a universally supported file system, such as [[FAT32]], is oftentimes more feasible.
}}


=== Feature comparison ===
=== Feature comparison ===
Line 89: Line 90:
{{Note|
{{Note|
* As GPT is part of the UEFI specification, all UEFI boot loaders support GPT disks. GPT on BIOS systems is possible, using either "hybrid booting" with [https://www.rodsbooks.com/gdisk/hybrid.html Hybrid MBR], or the new [https://repo.or.cz/syslinux.git/blob/HEAD:/doc/gpt.txt GPT-only] protocol. This protocol may however cause issues with certain BIOS implementations; see [https://www.rodsbooks.com/gdisk/bios.html#bios rodsbooks] for details.
* As GPT is part of the UEFI specification, all UEFI boot loaders support GPT disks. GPT on BIOS systems is possible, using either "hybrid booting" with [https://www.rodsbooks.com/gdisk/hybrid.html Hybrid MBR], or the new [https://repo.or.cz/syslinux.git/blob/HEAD:/doc/gpt.txt GPT-only] protocol. This protocol may however cause issues with certain BIOS implementations; see [https://www.rodsbooks.com/gdisk/bios.html#bios rodsbooks] for details.
* Encryption mentioned in file system support is [[wikipedia:Filesystem-level encryption|filesystem-level encryption]], it has no bearing on [[dm-crypt|block-level encryption]].  
* As [[Secure Boot]] is part of the UEFI specification, all UEFI boot loaders support it, although some have limitations.
}}
}}


{| class="wikitable sortable"
{| class="wikitable sortable"  
! rowspan="2"| Name
! rowspan="2" | Name
! colspan="2"| Firmware
! colspan="2" | Firmware
! colspan="2"| [[Partition table]]
! colspan="2" | [[Partition table]]
! rowspan="2"| Multi-boot
! rowspan="2" | Multi-boot
! colspan="5"| [[File systems]]
! rowspan="2" | [[File systems]]
! rowspan="2"| Notes
! rowspan="2" | Notes
|-
|-
! BIOS !! [[UEFI]]
! BIOS !! [[UEFI]]
! [[MBR]] !! [[GPT]]
! [[MBR]] !! [[GPT]]
! [[Btrfs]] !! [[ext4]] !! ReiserFS !! [[VFAT]] !! [[XFS]]
|-
|-
! [[EFISTUB]]
! [[EFISTUB]]
| {{-}} || {{Yes}}
| {{-}}
| {{Yes}}<sup>1</sup>
| {{Yes}} || {{Yes}}
| {{Yes}} || {{Yes}}
| {{-}}
| {{-}}
| {{-}} || {{-}} || {{-}} || {{G|Inherited from firmware<sup>1</sup>}} || {{-}}
| {{G|Inherited from firmware<sup>2</sup>}}
| The kernel is a valid EFI executable which can be loaded directory from the UEFI firmware with [[efibootmgr]], or another bootloader.
| The kernel is a valid EFI executable which can be directly launched from UEFI or from another UEFI boot loader.
|-
|-
! [[Unified kernel image]]
! [[Unified kernel image]]
| {{-}} || {{Yes}}
| {{-}}
| {{Yes}}<sup>3</sup>
| {{Yes}} || {{Yes}}
| {{Yes}} || {{Yes}}
| {{-}}
| {{-}}
| {{-}} || {{-}} || {{-}} || {{G|Inherited from firmware<sup>1</sup>}} || {{-}}
| {{G|Inherited from firmware<sup>2</sup>}}
| {{man|7|systemd-stub}}, a kernel, initramfs and kernel command line packed into EFI executable to be loaded directly from UEFI firmware or another boot loader.
| {{man|7|systemd-stub}}, a kernel, initramfs and kernel command line packed into EFI executable to be loaded directly from UEFI firmware or another boot loader.
|-
|-
! [[GRUB]]
! [[GRUB]]
| {{Yes}} || {{Yes}}
| {{Yes}}
| {{Yes}}<sup>3</sup>
| {{Yes}} || {{Yes}}
| {{Yes}} || {{Yes}}
| {{Yes}}
| {{Yes}}
| {{Yes}} || {{Yes}} || {{Yes}} || {{Yes}} || {{Yes}}
| {{G|[[GRUB#Supported file systems|Built-in]]}}
| On BIOS/GPT configuration requires a [[BIOS boot partition]]. <br/>Supports RAID, LUKS1 and LVM (but not thin provisioned volumes).
| Supports RAID, LUKS1 and LVM (but not thin provisioned volumes). See [[GRUB]] for setup-specific limitations.
|-
|-
! [[Limine]]
! [[Limine]]
| {{Yes}} || {{Yes}}
| {{Yes}}
| {{Yes}}
| {{Yes}} || {{Yes}}
| {{Yes}} || {{Yes}}
| {{Yes}}
| {{Yes}}
| {{No}} || {{Y|Without encryption}} || {{No}} || {{Yes}} || {{No}}
| {{Y|[[Limine#Supported file systems|Limited]]}}
|
|
|-
|-
! [[rEFInd]]
! [[rEFInd]]
| {{No}} || {{Yes}}
| {{No}}
| {{Yes}}
| {{Yes}} || {{Yes}}
| {{Yes}} || {{Yes}}
| {{Yes}}<sup>2</sup>
| {{Yes}}<sup>4</sup>
| {{Y|Without encryption}} || {{Y|Without encryption}} || {{Y|Without tail-packing feature}} || {{G|Inherited from firmware<sup>1</sup>}} || {{No}}
| {{G|[[rEFInd#Supported file systems|Extensible]]<sup>2,5</sup>}}
| Supports auto-detecting kernels and parameters without explicit configuration, and supports fastboot [https://bbs.archlinux.org/viewtopic.php?id=258805].
| Supports auto-detecting kernels and parameters without explicit configuration, and supports fastboot [https://bbs.archlinux.org/viewtopic.php?id=258805].
|-
|-
! [[Syslinux]]
! [[Syslinux]]
| {{Yes}} || {{Y|[[Syslinux#Limitations of UEFI Syslinux|Partial]]}}
| {{Yes}}
| {{Y|[[Syslinux#Limitations of UEFI Syslinux|Partial]]<sup>1</sup>}}
| {{Yes}} || {{Yes}}
| {{Yes}} || {{Yes}}
| {{Y|[[Syslinux#Chainloading|Partial]]}}
| {{Y|[[Syslinux#Chainloading|Partial]]}}
| {{Y|Without: multi-device volumes, compression, encryption}} || {{Y|Without encryption}} || {{No}} || {{Yes}} || {{Y|MBR only; without sparse inodes}}
| {{Y|[[Syslinux#Supported file systems|Limited]]}}
| No support for certain [[file system]] features.[https://wiki.syslinux.org/wiki/index.php?title=Filesystem] <br/>Does not have file system drivers[https://bugzilla.syslinux.org/show_bug.cgi?id=33], can only access the file system it was installed to.
| No support for certain file system features.<br />Can only access the file system it was [[Syslinux#Chainloading|installed to]].
|-
|-
! [[systemd-boot]]
! [[systemd-boot]]
| {{No}} || {{Yes}}
| {{No}}
| {{Y|[https://github.com/systemd/systemd/issues/1125 Manual install only]}} || {{Yes}}
| {{Yes}}<sup>3</sup>
| {{Yes}}<sup>2</sup>
| {{Y|[https://github.com/systemd/systemd/issues/1125 Manual]}} || {{Yes}}
| {{Y|Can be side-loaded<sup>3</sup>}} || {{Y|Can be side-loaded<sup>3</sup>}} || {{Y|Can be side-loaded<sup>3</sup>}} || {{G|Inherited from firmware<sup>1</sup>}} || {{Y|Can be side-loaded<sup>3</sup>}}
| {{Yes}}<sup>4</sup>
| Cannot launch binaries from partitions other than the [[ESP]] or the Extended Boot Loader Partition (XBOOTLDR partition). <br /> Supports automatically detecting [[Unified kernel image|unified kernel images]] when they are placed into {{ic|''esp''/EFI/Linux}}.
| {{G|[[systemd-boot#Supported file systems|Extensible]]<sup>2,5</sup>}}
| Can only launch binaries from the [[ESP]] it is installed to or from the Extended Boot Loader Partition (XBOOTLDR partition) on the same disk.<br>Automatically detects [[unified kernel image]]s placed in {{ic|''esp''/EFI/Linux/}}.
|-
|-
! {{Grey|[[GRUB Legacy]]}}
! {{Grey|[[GRUB Legacy]]}}
| {{Yes}} || {{No}}
| {{Yes}}
| {{No}}
| {{Yes}} || {{No}}
| {{Yes}} || {{No}}
| {{Yes}}
| {{Yes}}
| {{No}} || {{No}} || {{Yes}} || {{Yes}} || {{Y|XFS v4 only}}
| {{Y|[[GRUB Legacy#Supported file systems|Limited]]}}  
| [https://www.gnu.org/software/grub/grub-legacy.html Discontinued] in favor of [[GRUB]].
| [https://www.gnu.org/software/grub/grub-legacy.html Discontinued] in favor of [[GRUB]].
|-
|-
! {{Grey|[[LILO]]}}
! {{Grey|[[LILO]]}}
| {{Yes}} || {{No}}
| {{Yes}} || {{No}}
| {{Yes}}
| {{Yes}}
| {{No}} || {{Y|Without encryption}} || {{Yes}} || {{Yes}} || {{Yes|https://xfs.org/index.php/XFS_FAQ#Q:_Does_LILO_work_with_XFS.3F}}
| {{No}}
| [https://web.archive.org/web/20180323163248/http://lilo.alioth.debian.org/ Discontinued] due to limitations (e.g. with Btrfs, GPT, RAID).
| {{Yes}} || {{Y|[https://salsa.debian.org/joowie-guest/upstream_lilo/-/commit/29a64e6b92cac22d472f4b352de5b1535e4afc5f Partial]}}
| {{Yes}}
| {{Y|[[LILO#Supported file systems|Limited]]}}
| [https://web.archive.org/web/20180323163248/http://lilo.alioth.debian.org/ Discontinued] due to limitations (e.g. with Btrfs, GPT, RAID, encryption).
|}
|}


# File system support is inherited from the firmware. The UEFI specification mandates support for the FAT12, FAT16 and FAT32 file systems[https://uefi.org/sites/default/files/resources/UEFI_Spec_2_8_final.pdf#G17.1345080], but vendors can optionally add support for additional file systems; for example, the firmware in Apple [[Mac]]s supports the HFS+ file system. If the firmware provides an interface for loading [[Unified Extensible Firmware Interface#UEFI drivers|UEFI drivers]] on startup, then support for additional file systems can be added by loading (independently acquired) file system drivers.
# While the binary can be signed for [[Secure Boot]], it does no following verification, thus breaking the chain of trust.
# A [https://www.rodsbooks.com/efi-bootloaders/principles.html boot manager]. It can only launch other EFI applications, for example, Linux kernel images built with {{ic|1=CONFIG_EFI_STUB=y}} and Windows {{ic|bootmgfw.efi}}.
# File system support is inherited from the firmware. The UEFI specification mandates support for the FAT12, FAT16 and FAT32 file systems[https://uefi.org/specs/UEFI/2.10/13_Protocols_Media_Access.html#file-system-format-1], but vendors can optionally add support for additional file systems; for example, the firmware in Apple [[Mac]]s supports the HFS+ file system. If the firmware provides an interface for loading [[Unified Extensible Firmware Interface#UEFI drivers|UEFI drivers]] on startup, then support for additional file systems can be added by loading (independently acquired) file system drivers.
# systemd-boot supports loading [[Unified Extensible Firmware Interface#UEFI drivers|UEFI file system drivers]]. These are provided by {{Pkg|efifs}} and need to be placed into {{ic|''esp''/EFI/systemd/drivers/}}.  
# Supports mixed mode booting. I.e. it can boot a 64-bit x86_64 Linux kernel on [[Unified Extensible Firmware Interface#UEFI firmware bitness|32-bit IA32 UEFI]].
# A [https://www.rodsbooks.com/efi-bootloaders/principles.html boot manager]. It can only launch other EFI applications, for example, Linux kernel images built with {{ic|1=CONFIG_EFI_STUB=y}} and [https://learn.microsoft.com/en-us/windows-hardware/drivers/bringup/boot-and-uefi#understanding-the-windows-boot-manager Windows Boot Manager] ({{ic|bootmgfw.efi}}).
# Supports loading [[Unified Extensible Firmware Interface#UEFI drivers|UEFI file system drivers]].


See also [[Wikipedia:Comparison of boot loaders]].
See also [[Wikipedia:Comparison of boot loaders]].
Line 176: Line 187:
== Kernel ==
== 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. The kernel temporarily stops programs to run other programs in the meantime, which is known as [[Wikipedia:Preemption (computing)|preemption]]. This creates the illusion of many tasks being executed simultaneously, even on single-core CPUs. The kernel uses the CPU scheduler to decide which program takes priority at any given moment.
The [[#Boot loader|boot loader]] boots the [[Wikipedia:vmlinux|vmlinux image]] containing the [[kernel]].
 
The kernel functions on a low level (''kernelspace'') interacting between the hardware of the machine and the programs. The kernel initially performs hardware enumeration and initialization before continuing to userspace. See [[Wikipedia:Kernel (operating system)]] and [[Wikipedia:Linux kernel]] for a detailed explanation.


== initramfs ==
== initramfs ==


After the [[#Boot loader|boot loader]] loads the [[kernel]] and possible initramfs files and executes the kernel, the kernel unpacks the initramfs (initial RAM filesystem) archives into the (then empty) rootfs (initial root filesystem, specifically a ramfs or tmpfs). The first extracted initramfs is the one embedded in the kernel binary during the kernel build, then possible external initramfs files are extracted. Thus files in the external initramfs overwrite files with the same name in the embedded initramfs. The kernel then executes {{ic|/init}} (in the rootfs) as the first process. The ''early userspace'' starts.
The root file system at {{ic|/}} starts out as an empty [https://docs.kernel.org/filesystems/ramfs-rootfs-initramfs.html rootfs], which is a special instance of ramfs or tmpfs. This is the temporary root file system where the initramfs (''init''ial ''RAM'' ''f''ile ''s''ystem) images will be unpacked to.
 
The main purpose of the initramfs is to bootstrap the system to the point where it can access the root file system (see [[FHS]] for details). This includes setting up the storage stack where the rootfs may be lying on, e.g. through [[dm-crypt]], [[dm-verity]], {{man|8|systemd-repart}}, etc. It also resolves the [[Persistent block device naming|persistent block device names]] to real device through [[udev]]. It does not need to contain every module one would ever want to use; it should only have modules required for the root device like IDE, SCSI, SATA or USB/FW (if booting from an external drive) and encryption. The majority of modules will be loaded later on by [[udev]] after switching root into the root file system, during the init process.
 
First, the kernel unpacks its builtin initramfs into the temporary root. Arch Linux's [[Kernel#Officially supported kernels|official kernels]] use an empty archive for the builtin initramfs, which is the default when building Linux. Then, the kernel unpacks external initramfs files specified by the command line passed by the [[#Boot loader|boot loader]], overwriting any files from the embedded initramfs. These external initramfs images can be generated with [[mkinitcpio]], [[dracut]] or [[booster]], and are Arch's preferred method for setting up for ''early userspace''.
 
Note that the initramfs serves more than setting up the root file system. There are tasks that can only be performed before the rootfs is mounted, such as [[fsck]] and resuming from [[hibernation]].
 
Also, the Linux [[kernel]] [https://github.com/torvalds/linux/blob/1b907d0507354b74a4f2c286380cd6059af79248/fs/namespace.c#L4222 pins] the original root it is started from. If an initramfs is not used, the real root file system could end up failing to be cleanly unmounted during shutdown.
 
== Early userspace ==
 
The ''early userspace'' stage takes place while the temporary rootfs is mounted, operating on the files provided by the [[#initramfs]].


Arch Linux [[Kernel#Officially supported kernels|official kernels]] use an empty archive for the builtin initramfs (which is the default when building Linux). External initramfs images can be generated with [[mkinitcpio]], [[dracut]] or [[booster]].
The function of early userspace is [[Mkinitcpio#Common hooks|configurable]], but generally does the following:


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.
* {{man|8|systemd-modules-load}} loads kernel modules, such as any block device modules needed to mount the real root file system.
* Handle decryption of the real root file system, if applicable.
* Load the DRM module, as [[Kernel mode setting#Early KMS start|early KMS]] is enabled by default for in-tree modules.


== init process ==
At the final stage of early userspace, the real root is mounted at {{ic|/sysroot/}} (in case of a [[systemd]]-based initramfs) or at {{ic|/new_root/}} (in case of a busybox-based one), and then switched to. The late userspace starts by executing the [[init]] program from the real root file system.


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]].
== Late userspace ==


== getty ==
The startup of late userspace is executed by the [[init]] process. Arch officially uses [[systemd]] which is built on the concept of units and services, but the functionality described here largely overlaps with other init systems.


[[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}} and {{ic|/etc/shadow}}, then calls [[#Login|login]]. Alternatively, getty may start a display manager if one is present on the system.
=== getty ===


== Display manager ==
The init process calls [[getty]] once for each [[Wikipedia:Virtual console|virtual terminal]] (typically six of them). ''getty'' initializes each terminal and protects it from unauthorized access. When the username and password are provided, ''getty'' checks them against {{ic|/etc/passwd}} and {{ic|/etc/shadow}}, then calls {{man|1|login}}.


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


In order to automatically initialize a display manager after booting, it is necessary to manually enable the service unit through [[systemd]]. For more information on enabling and starting service units, see [[systemd#Using units]].
The ''login'' program begins a session for the user by setting environment variables and starting the user's shell, based on {{ic|/etc/passwd}}. 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.


== Login ==
==== Shell ====


The ''login'' program begins a session for the user by setting environment variables and starting the user's shell, based on {{ic|/etc/passwd}}.
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]]. Jump to [[#Graphical session]] for the end.


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.
=== Display manager ===


== Shell ==
{{Expansion|This section only describes the process with [[Xorg]] but does not explain what happens with [[Wayland]].}}


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]].
Additionally, [[init]] can be configured to start a [[display manager]] instead of ''getty'' on a specific virtual terminal. This requires manually [[enabling]] its [[Systemd#Using units|systemd service file]]. The display manager then starts a graphical session.


== GUI, xinit or wayland ==
==== Graphical session ====


[[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|getty]].
[[xinit]] runs the user's [[xinitrc]] runtime configuration file, which normally starts a [[window manager]] or a [[desktop environment]]. When the user is finished and exits, ''xinit'', ''startx'', the shell, and login will terminate in that order, returning to ''getty'' or the display manager.


== See also ==
== See also ==
Line 220: Line 247:
* [[Wikipedia:Linux startup process]]
* [[Wikipedia:Linux startup process]]
* [[Wikipedia:initrd]]
* [[Wikipedia:initrd]]
* [https://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]
* [https://neosmart.net/wiki/mbr-boot-process/ NeoSmart: The BIOS/MBR Boot Process]
* [https://www.linux.com/learn/kernel-newbie-corner-initrd-and-initramfs-whats Kernel Newbie Corner: initrd and initramfs]
* [https://www.linux.com/learn/kernel-newbie-corner-initrd-and-initramfs-whats Kernel Newbie Corner: initrd and initramfs]
* [https://www.rodsbooks.com/efi-bootloaders/ Rod Smith - Managing EFI Boot Loaders for Linux]
* [https://www.rodsbooks.com/efi-bootloaders/ Rod Smith - Managing EFI Boot Loaders for Linux]
* [https://0pointer.net/blog/linux-boot-partitions.html Lennart Poettering - Linux Boot Partitions and How to Set Them Up]

Latest revision as of 07:52, 15 April 2024

In order to boot Arch Linux, a Linux-capable boot loader must be set up. 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. A detailed description is given on this or linked pages.

Firmware types

The firmware is the very first program that is executed once the system is switched on.

Tip: The words BIOS and (U)EFI are often used instead of firmware

BIOS

A BIOS or Basic Input-Output System is in most cases stored in a flash memory in the motherboard itself and independent of the system storage. Originally created for the IBM PC to handle hardware initialization and the boot process, it has been replaced progressively since 2010 by the UEFI which does not suffer from the same technical limitations.

UEFI

The Unified Extensible Firmware Interface has support for reading both the partition table as well as file systems. UEFI does not launch any boot code from the Master Boot Record (MBR) whether it exists or not, instead booting relies on boot entries in the NVRAM.

The UEFI specification mandates support for the FAT12, FAT16, and FAT32 file systems (see UEFI specification version 2.10, section 13.3.1.1), but any conformant vendor can optionally add support for additional file systems; for example, HFS+ or APFS in some Apple's firmwares. UEFI implementations also support ISO 9660 for optical discs.

UEFI launches EFI applications, e.g. boot loaders, boot managers, UEFI shell, etc. These applications are usually stored as files in the EFI system partition. Each vendor can store its files in the EFI system partition under the /EFI/vendor_name directory. The applications can be launched by adding a boot entry to the NVRAM or from the UEFI shell.

The UEFI specification has support for legacy BIOS booting with its Compatibility Support Module (CSM). If CSM is enabled in the UEFI, the UEFI will generate CSM boot entries for all drives. If a CSM boot entry is chosen to be booted from, the UEFI's CSM will attempt to boot from the drive's MBR bootstrap code.

Note: Intel is phasing out support for CSM, relying on the feature may not be feasible in the future.[1]

System initialization

Under BIOS

  1. System switched on, the power-on self-test (POST) is executed.
  2. After POST, BIOS initializes the hardware required for booting (disk, keyboard controllers etc.).
  3. BIOS launches the first 440 bytes (the Master Boot Record bootstrap code area) of the first disk in the BIOS disk order.
  4. The boot loader's first stage in the MBR boot code then launches its second stage code (if any) from either:
    • next disk sectors after the MBR, i.e. the so called post-MBR gap (only on a MBR partition table),
    • a partition's or a partitionless disk's volume boot record (VBR),
    • for GRUB on a GPT partitioned disk—a GRUB-specific BIOS boot partition (it is used in place of the post-MBR gap that does not exist in GPT).
  5. The actual boot loader is launched.
  6. The boot loader then loads an operating system by either chain-loading or directly loading the operating system kernel.

Under UEFI

  1. System switched on, the power-on self-test (POST) is executed.
  2. After POST, UEFI initializes the hardware required for booting (disk, keyboard controllers etc.).
  3. Firmware reads the boot entries in the NVRAM to determine which EFI application to launch and from where (e.g. from which disk and partition).
    • A boot entry could simply be a disk. In this case the firmware looks for an EFI system partition on that disk and tries to find an EFI application in the fallback boot path \EFI\BOOT\BOOTx64.EFI (BOOTIA32.EFI on systems with a IA32 (32-bit) UEFI). This is how UEFI bootable removable media work.
  4. Firmware launches the EFI application.

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

Note: Some UEFI systems can only boot from the fallback boot 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 EFI application corresponding to the particular operating system's boot loader. This removes the need for relying on the chain loading mechanisms of one boot loader to load another OS.

See also Dual boot with Windows.

Boot loader

A boot loader is a piece of software started by the firmware (BIOS or UEFI). It is responsible for loading the kernel with the wanted kernel parameters and any external initramfs images. In the case of UEFI, the kernel itself can be directly launched by the UEFI using the EFI boot stub. A separate boot loader or boot manager can still be used for the purpose of editing kernel parameters before booting.

Warning: To successfully boot Arch, the boot loader needs access to the kernel and initramfs image(s) which typically reside in the /boot directory. That means the boot loader must have support for everything starting from the block devices, stacked block devices (LVM, RAID, dm-crypt, LUKS, etc.) and ending with the file system on which the kernel(s) and initramfs image(s) reside.

Since almost no boot loader supports such stacked block devices and since file systems can introduce new features which may not yet be supported by any boot loader (e.g. archlinux/packaging/packages/grub#7, FS#79857, FS#59047, FS#58137, FS#51879, FS#46856, FS#38750, FS#21733 and fscrypt encrypted directories), using a separate /boot partition with a universally supported file system, such as FAT32, is oftentimes more feasible.

Feature comparison

Note:
  • As GPT is part of the UEFI specification, all UEFI boot loaders support GPT disks. GPT on BIOS systems is possible, using either "hybrid booting" with Hybrid MBR, or the new GPT-only protocol. This protocol may however cause issues with certain BIOS implementations; see rodsbooks for details.
  • As Secure Boot is part of the UEFI specification, all UEFI boot loaders support it, although some have limitations.
Name Firmware Partition table Multi-boot File systems Notes
BIOS UEFI MBR GPT
EFISTUB Yes1 Yes Yes Inherited from firmware2 The kernel is a valid EFI executable which can be directly launched from UEFI or from another UEFI boot loader.
Unified kernel image Yes3 Yes Yes Inherited from firmware2 systemd-stub(7), a kernel, initramfs and kernel command line packed into EFI executable to be loaded directly from UEFI firmware or another boot loader.
GRUB Yes Yes3 Yes Yes Yes Built-in Supports RAID, LUKS1 and LVM (but not thin provisioned volumes). See GRUB for setup-specific limitations.
Limine Yes Yes Yes Yes Yes Limited
rEFInd No Yes Yes Yes Yes4 Extensible2,5 Supports auto-detecting kernels and parameters without explicit configuration, and supports fastboot [2].
Syslinux Yes Partial1 Yes Yes Partial Limited No support for certain file system features.
Can only access the file system it was installed to.
systemd-boot No Yes3 Manual Yes Yes4 Extensible2,5 Can only launch binaries from the ESP it is installed to or from the Extended Boot Loader Partition (XBOOTLDR partition) on the same disk.
Automatically detects unified kernel images placed in esp/EFI/Linux/.
GRUB Legacy Yes No Yes No Yes Limited Discontinued in favor of GRUB.
LILO Yes No Yes Partial Yes Limited Discontinued due to limitations (e.g. with Btrfs, GPT, RAID, encryption).
  1. While the binary can be signed for Secure Boot, it does no following verification, thus breaking the chain of trust.
  2. File system support is inherited from the firmware. The UEFI specification mandates support for the FAT12, FAT16 and FAT32 file systems[3], but vendors can optionally add support for additional file systems; for example, the firmware in Apple Macs supports the HFS+ file system. If the firmware provides an interface for loading UEFI drivers on startup, then support for additional file systems can be added by loading (independently acquired) file system drivers.
  3. Supports mixed mode booting. I.e. it can boot a 64-bit x86_64 Linux kernel on 32-bit IA32 UEFI.
  4. A boot manager. It can only launch other EFI applications, for example, Linux kernel images built with CONFIG_EFI_STUB=y and Windows Boot Manager (bootmgfw.efi).
  5. Supports loading UEFI file system drivers.

See also Wikipedia:Comparison of boot loaders.

Kernel

The boot loader boots the vmlinux image containing the kernel.

The kernel functions on a low level (kernelspace) interacting between the hardware of the machine and the programs. The kernel initially performs hardware enumeration and initialization before continuing to userspace. See Wikipedia:Kernel (operating system) and Wikipedia:Linux kernel for a detailed explanation.

initramfs

The root file system at / starts out as an empty rootfs, which is a special instance of ramfs or tmpfs. This is the temporary root file system where the initramfs (initial RAM file system) images will be unpacked to.

The main purpose of the initramfs is to bootstrap the system to the point where it can access the root file system (see FHS for details). This includes setting up the storage stack where the rootfs may be lying on, e.g. through dm-crypt, dm-verity, systemd-repart(8), etc. It also resolves the persistent block device names to real device through udev. It does not need to contain every module one would ever want to use; it should only have modules required for the root device like IDE, SCSI, SATA or USB/FW (if booting from an external drive) and encryption. The majority of modules will be loaded later on by udev after switching root into the root file system, during the init process.

First, the kernel unpacks its builtin initramfs into the temporary root. Arch Linux's official kernels use an empty archive for the builtin initramfs, which is the default when building Linux. Then, the kernel unpacks external initramfs files specified by the command line passed by the boot loader, overwriting any files from the embedded initramfs. These external initramfs images can be generated with mkinitcpio, dracut or booster, and are Arch's preferred method for setting up for early userspace.

Note that the initramfs serves more than setting up the root file system. There are tasks that can only be performed before the rootfs is mounted, such as fsck and resuming from hibernation.

Also, the Linux kernel pins the original root it is started from. If an initramfs is not used, the real root file system could end up failing to be cleanly unmounted during shutdown.

Early userspace

The early userspace stage takes place while the temporary rootfs is mounted, operating on the files provided by the #initramfs.

The function of early userspace is configurable, but generally does the following:

  • systemd-modules-load(8) loads kernel modules, such as any block device modules needed to mount the real root file system.
  • Handle decryption of the real root file system, if applicable.
  • Load the DRM module, as early KMS is enabled by default for in-tree modules.

At the final stage of early userspace, the real root is mounted at /sysroot/ (in case of a systemd-based initramfs) or at /new_root/ (in case of a busybox-based one), and then switched to. The late userspace starts by executing the init program from the real root file system.

Late userspace

The startup of late userspace is executed by the init process. Arch officially uses systemd which is built on the concept of units and services, but the functionality described here largely overlaps with other init systems.

getty

The init process calls getty once for each virtual terminal (typically six of them). getty initializes each terminal and protects it from unauthorized access. When the username and password are provided, getty checks them against /etc/passwd and /etc/shadow, then calls login(1).

Login

The login program begins a session for the user by setting environment variables and starting the user's shell, based on /etc/passwd. 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. Jump to #Graphical session for the end.

Display manager

This article or section needs expansion.

Reason: This section only describes the process with Xorg but does not explain what happens with Wayland. (Discuss in Talk:Arch boot process)

Additionally, init can be configured to start a display manager instead of getty on a specific virtual terminal. This requires manually enabling its systemd service file. The display manager then starts a graphical session.

Graphical session

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

See also