Arch boot process

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.9, 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.

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).
  4. Firmware launches the EFI application.

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

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.

Note: Loading Microcode updates requires adjustments in boot loader configuration.

Feature comparison

Name Firmware Partition table Multi-boot File systems Notes
BIOSUEFI MBRGPT Btrfsext4ReiserFSVFATXFS
EFISTUB The kernel is a valid EFI executable which can be loaded directly from the UEFI firmware with efibootmgr, or another bootloader.
Unified kernel image 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 On BIOS/GPT configuration requires a BIOS boot partition.
Supports RAID, LUKS1 and LVM (but not thin provisioned volumes).
Limine
rEFInd 2 Supports auto-detecting kernels and parameters without explicit configuration, and supports fastboot .
Syslinux Without: multi-device volumes, compression, encryption No support for certain file system features.
Does not have file system drivers, can only access the file system it was installed to.
systemd-boot 2 Cannot launch binaries from partitions other than the ESP or the Extended Boot Loader Partition (XBOOTLDR partition).
Supports automatically detecting unified kernel images when they are placed into .
GRUB Legacy Discontinued in favor of GRUB.
Discontinued due to limitations (e.g. with Btrfs, GPT, RAID).
  1. File system support is inherited from the firmware. The UEFI specification mandates support for the FAT12, FAT16 and FAT32 file systems, 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.
  2. A boot manager. It can only launch other EFI applications, for example, Linux kernel images built with and Windows bootmgfw.efi.
  3. systemd-boot supports loading UEFI file system drivers. These are provided by and need to be placed into .

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 purpose of the initramfs is to bootstrap the system to the point where it can access the root file system (see FHS for details). 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, 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.

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:

  • 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, if early KMS is desired.

At the final stage of early userspace, the real root is mounted at , 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 and /etc/shadow, then calls .

Login

The login program begins a session for the user by setting environment variables and starting the user's shell, based on . 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

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.

gollark: Windows internals are wasting more.
gollark: It isn't THAT significant.
gollark: Using Linux means convenient management over SSH instead of "remote desktop protocol".
gollark: I'm not sure how specific it is to deep learning stuff though.
gollark: Have you heard of Triton? It's apparently a nice abstraction over CUDA.

See also

This article is issued from Archlinux. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.