Skip to main content

The Linux Boot Process

When a Linux system is powered on, it goes through a specific sequence of events to become fully operational. Understanding this boot process is essential for troubleshooting and system administration.

1. Hardware Initialization (BIOS/UEFI)​

The very first step happens at the hardware level. The system's firmware takes control.

  • POST (Power-On Self Test): The firmware checks the hardware components (RAM, CPU, storage devices) to ensure they are functioning properly.
  • Boot Device Selection: The firmware determines which device to boot from, based on a pre-configured boot order.
  • Bootloader Handoff: Once the boot device is selected, the firmware loads the first sector of that device (containing the bootloader) into memory and passes control to it.

2. The Bootloader (GRUB)​

The bootloader's primary job is to load the operating system's kernel. In most modern Linux systems, this is GRUB (GRand Unified Bootloader).

  • Stage 1 / Stage 2: GRUB often operates in stages. Stage 1 is tiny and exists just to load Stage 2, which contains the logic to parse filesystems and present a boot menu.
  • Kernel Selection: GRUB displays a menu allowing the user to select which kernel or operating system to boot.
  • Loading Kernel and Initramfs: GRUB loads the selected Linux kernel into memory. It also loads the initramfs (Initial RAM Filesystem) into memory and passes its location to the kernel.

3. Kernel Initialization​

The kernel is the core of the Linux operating system.

  • Hardware Setup: The kernel takes control of the system, initializes memory, and sets up interrupt handlers.
  • Initramfs Mounting: The kernel mounts the initramfs as a temporary root filesystem.
  • Driver Loading: The initramfs contains essential kernel modules (drivers) needed to access the real root filesystem (e.g., LVM, RAID, or specific storage controller drivers).
  • Pivot Root: Once the real root filesystem is accessible, the kernel switches (pivots) from the temporary initramfs to the real root filesystem.

4. The Init System (systemd)​

After the real root filesystem is mounted, the kernel executes the first user-space program, which has Process ID (PID) 1. Today, this is almost universally systemd.

  • Service Initialization: systemd is responsible for starting all other processes and services required for the system to function.
  • Target State: systemd reads its configuration to determine the default "target" (e.g., multi-user.target for a text console, or graphical.target for a GUI) and starts all necessary services to reach that state.
  • Login Prompt: Finally, systemd spawns getty processes to provide login prompts on terminals, or a display manager for a graphical login.

Best Practices​

  • Keep old kernels: When upgrading, always keep at least one older, known-working kernel in your GRUB menu in case the new kernel fails to boot.
  • Understand rescue modes: Familiarize yourself with appending systemd.unit=rescue.target or init=/bin/bash to your kernel boot parameters in GRUB to troubleshoot systems that won't fully boot.