TExcelTAD
Home › Operating Systems: Linux & Windows › The Linux Boot Process

The Linux Boot Process

Between pressing the power button and seeing a login prompt, a Linux PC hands control along a chain of five or six programs, each one loading the next and then stepping aside. Knowing the chain is what lets you fix a machine that stops at a black screen, a grub> prompt or an "emergency mode" shell: the place where it stops tells you which link broke.

The chain at a glance

text
 power on
    |
    v
 [1] UEFI firmware      self-test, finds the EFI System Partition (ESP), reads boot entries from NVRAM
    |                    Secure Boot: only signed programs may run
    v
 [2] shim + GRUB        boot loader on the ESP (or systemd-boot); shows the menu,
    |                    loads the kernel image + initramfs into RAM, passes the command line
    v
 [3] Linux kernel       decompresses itself, sets up memory, CPUs, interrupts, built-in drivers
    |                    mounts the initramfs as a temporary root
    v
 [4] initramfs          small user space in RAM: loads storage drivers, unlocks LUKS, assembles RAID/LVM,
    |                    finds the real root (by UUID), mounts it, switches to it
    v
 [5] systemd (PID 1)    mounts /etc/fstab, starts services in parallel up to the default target
    |
    v
 [6] login              getty on a text console, or a display manager (GDM, SDDM) for the desktop

1. Firmware: UEFI

Modern PCs use UEFI instead of the old BIOS. After its power-on self-test, the firmware reads its list of boot entries from NVRAM and looks for the matching .efi program on the EFI System Partition, a small FAT32 partition (usually mounted at /boot/efi). You can inspect and change those entries from Linux (sample output, yours will differ):

bash
ada@ubuntu:~$ efibootmgr
BootCurrent: 0001
Timeout: 0 seconds
BootOrder: 0001,0000,2001
Boot0000* Windows Boot Manager  HD(1,GPT,...)/File(\EFI\Microsoft\Boot\bootmgfw.efi)
Boot0001* ubuntu                HD(1,GPT,...)/File(\EFI\ubuntu\shimx64.efi)
Boot2001* EFI USB Device        RC
ada@ubuntu:~$ ls /boot/efi/EFI
BOOT  Microsoft  ubuntu

This is how dual boot works with UEFI: Windows and Ubuntu each put their loader in their own folder on the same ESP. (The older BIOS/MBR method instead ran 446 bytes of code from the first sector of the disk.)

With Secure Boot on, the firmware only runs programs signed with a key it trusts (Microsoft's, on most PCs). Distributions therefore boot through shim, a tiny loader signed by Microsoft that carries the distribution's own key and uses it to check GRUB and the kernel. The chain of trust looks like this:

python · try it yourself
trusted_by_firmware = {"Microsoft UEFI CA"}

chain = [   # (stage, signed by, key it adds for the next stages)
    ("shimx64.efi",          "Microsoft UEFI CA", "Canonical"),
    ("grubx64.efi",          "Canonical",         None),
    ("vmlinuz-6.8.0-45",     "Canonical",         None),
    ("nvidia.ko (DKMS)",     "unknown",           None),
]

def secure_boot(chain, trusted):
    keys = set(trusted)
    for stage, signer, adds in chain:
        if signer not in keys:
            print(f"BLOCKED  {stage:20} signed by {signer!r}: not trusted")
            return
        print(f"verified {stage:20} signed by {signer}")
        if adds:
            keys.add(adds)

secure_boot(chain, trusted_by_firmware)
verified shimx64.efi          signed by Microsoft UEFI CA
verified grubx64.efi          signed by Canonical
verified vmlinuz-6.8.0-45     signed by Canonical
BLOCKED  nvidia.ko (DKMS)     signed by 'unknown': not trusted

The last line is a real-world classic: a driver module you compiled yourself is not signed, so with Secure Boot the kernel refuses to load it until you enrol your own key (MOK, Machine Owner Key) with mokutil --import.

2. The boot loader: GRUB

GRUB shows the menu (hold Shift or tap Esc to see it if it is hidden), reads its configuration, loads the kernel (/boot/vmlinuz-…) and the initramfs (/boot/initrd.img-…) into memory and jumps to the kernel with a command line. You never edit grub.cfg directly; you edit /etc/default/grub and regenerate it (sample session):

bash
ada@ubuntu:~$ grep CMDLINE /etc/default/grub
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"
GRUB_CMDLINE_LINUX=""
ada@ubuntu:~$ sudo update-grub          # Fedora/RHEL: sudo grub2-mkconfig -o /boot/grub2/grub.cfg
Sourcing file `/etc/default/grub'
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-6.8.0-45-generic
Found initrd image: /boot/initrd.img-6.8.0-45-generic
Found linux image: /boot/vmlinuz-6.8.0-41-generic
Found initrd image: /boot/initrd.img-6.8.0-41-generic
Found Windows Boot Manager on /dev/nvme0n1p1@/efi/Microsoft/Boot/bootmgfw.efi
done

Keeping the previous kernel in the menu is your safety net: if an update breaks booting, pick the older entry under "Advanced options".

3. The kernel and its command line

The kernel decompresses itself, detects CPUs and memory, starts its built-in drivers and reads its command line. A running system shows the line it was booted with in /proc/cmdline. The script below takes a typical line (saved in a file, since the sandbox container was never booted) and splits it into parameters:

bash · try it yourself
cat > cmdline <<'EOF'
BOOT_IMAGE=/boot/vmlinuz-6.8.0-45-generic root=UUID=3c70a1f8-24c5-4ad1-a6ca-ca36277b21b2 ro quiet splash
EOF
tr ' ' '\n' < cmdline | while IFS='=' read -r key value; do
  printf '%-11s %s\n' "$key" "${value:-(flag)}"
done
BOOT_IMAGE  /boot/vmlinuz-6.8.0-45-generic
root        UUID=3c70a1f8-24c5-4ad1-a6ca-ca36277b21b2
ro          (flag)
quiet       (flag)
splash      (flag)

Only the first = separates a parameter from its value: root=UUID=3c70… means "the parameter root has the value UUID=3c70…". read gets this right because the last variable receives the rest of the line, including any further = signs. The kernel handles the parameters it knows (root, ro, quiet), and splash is picked up later by the boot splash program; unknown name=value pairs end up in PID 1's environment.

Useful parameters to add once from the GRUB menu (press e on an entry, edit the linux line, boot with Ctrl+X):

Parameter Effect
quiet / remove it Hide / show kernel messages during boot
systemd.unit=rescue.target Boot to a single-user root shell (after the root password)
systemd.unit=emergency.target Even more minimal: only the root file system, read-only
init=/bin/bash Skip systemd entirely and start a shell as PID 1 (last resort for a lost root password)
nomodeset Do not load graphics drivers' mode setting (black screen after GRUB)
ro / rw Mount root read-only first (so fsck can check it) or read-write

The kernel's own messages are kept in a ring buffer you can read later with dmesg or journalctl -k (sample output):

bash
ada@ubuntu:~$ sudo dmesg | head -n 4
[    0.000000] Linux version 6.8.0-45-generic (buildd@lcy02-amd64-075) ...
[    0.000000] Command line: BOOT_IMAGE=/boot/vmlinuz-6.8.0-45-generic root=UUID=3c70a1f8-... ro quiet splash
[    0.000000] KERNEL supported cpus:
[    0.000000]   Intel GenuineIntel

4. The initramfs

Here is a chicken-and-egg problem: to mount the root file system, the kernel may need a driver (NVMe, RAID, LVM, encryption) that is itself stored on that root file system. The initramfs solves it: a compressed archive of a mini Linux (a shell, udev, a few modules, scripts) that the boot loader loaded into RAM next to the kernel.

python · try it yourself
initramfs_modules = {"nvme", "dm-crypt", "ext4"}
disks = {"/dev/nvme0n1p2": {"uuid": "3c70a1f8", "encrypted": True, "fs": "ext4"}}

def initramfs(root_uuid, passphrase_ok=True):
    print("initramfs: loading modules", sorted(initramfs_modules))
    for dev, info in disks.items():
        if info["uuid"] != root_uuid:
            continue
        if info["encrypted"]:
            if not passphrase_ok:
                return "cryptsetup: wrong passphrase -> drop to (initramfs) shell"
            dev = "/dev/mapper/root"
            print("initramfs: LUKS unlocked ->", dev)
        if info["fs"] not in initramfs_modules:
            return f"no {info['fs']} driver -> drop to (initramfs) shell"
        print(f"initramfs: mount {dev} on /sysroot, switch_root, exec /sbin/init")
        return "handing over to systemd (PID 1)"
    return f"ALERT! UUID={root_uuid} does not exist. Dropping to a shell!"

print(initramfs("3c70a1f8"))
print(initramfs("deadbeef"))
initramfs: loading modules ['dm-crypt', 'ext4', 'nvme']
initramfs: LUKS unlocked -> /dev/mapper/root
initramfs: mount /dev/mapper/root on /sysroot, switch_root, exec /sbin/init
handing over to systemd (PID 1)
initramfs: loading modules ['dm-crypt', 'ext4', 'nvme']
ALERT! UUID=deadbeef does not exist. Dropping to a shell!

The second case is the famous (initramfs) prompt: usually a wrong UUID in the boot entry, or a missing driver in an initramfs that was not rebuilt. The fix is to rebuild it: sudo update-initramfs -u (Debian/Ubuntu) or sudo dracut --force (Fedora, RHEL, openSUSE).

5. systemd takes over

/sbin/init is a symlink to systemd on nearly every major distribution. As PID 1 it mounts what /etc/fstab lists, starts udev, journald, networking and every enabled service in parallel, ordered by their dependencies, until it reaches the default target (graphical.target on a desktop, multi-user.target on a server). init & systemd covers it in depth. systemd-analyze shows where the time went (sample output):

bash
ada@ubuntu:~$ systemd-analyze
Startup finished in 5.912s (firmware) + 2.143s (loader) + 1.507s (kernel) + 4.820s (userspace) = 14.383s
graphical.target reached after 4.796s in userspace.
ada@ubuntu:~$ systemd-analyze blame | head -n 4
2.304s NetworkManager-wait-online.service
 812ms snapd.seeded.service
 455ms dev-nvme0n1p2.device
 301ms systemd-journald.service

Comparison with Windows

Step Linux Windows 11 (The Windows Boot Process)
Firmware entry \EFI\ubuntu\shimx64.efi \EFI\Microsoft\Boot\bootmgfw.efi
Boot loader GRUB / systemd-boot Windows Boot Manager → winload.efi
Boot config /boot/grub/grub.cfg (from /etc/default/grub) BCD store (bcdedit)
Kernel vmlinuz ntoskrnl.exe + hal.dll
Early drivers initramfs Boot-start drivers loaded by winload
First user process systemd (PID 1) smss.exe (Session Manager)
Login getty / GDM winlogon.exe + LogonUI
Recovery shell rescue/emergency target, (initramfs) Windows Recovery Environment (WinRE)

Learn more: init & systemd · Kernel Modules & Drivers · The Windows Boot Process

Test yourself

What is the job of the initramfs?

  1. Show the boot menu
  2. Provide the drivers and tools needed to find and mount the real root file system
  3. Store the kernel's log
  4. Hold user home directories

Why do Secure Boot systems start Linux through shim?

  1. shim is faster than GRUB
  2. shim is signed by Microsoft (trusted by the firmware) and carries the distribution's key to verify GRUB and the kernel
  3. shim replaces the kernel
  4. shim encrypts the disk

A machine stops at an (initramfs) prompt saying a UUID does not exist. Which stage failed?

  1. UEFI firmware
  2. GRUB menu
  3. Finding and mounting the root file system
  4. Starting the desktop