Linux Boot Process
BIOS/UEFI → GRUB2 → kernel → initramfs → systemd: understanding every stage of boot.
Overview
Overview Understanding the Linux boot process helps diagnose startup failures and tune boot performance.
Stage 1 — POST and firmware: Power-On Self Test runs, then BIOS or UEFI firmware takes over. BIOS uses MBR (Master Boot Record, first 512 bytes of disk), limited to 4 primary partitions and 2TB disks. UEFI supports GPT (GUID Partition Table), Secure Boot (cryptographic signature verification of bootloader), and reads the EFI System Partition (ESP, typically /boot/efi, FAT32 formatted).
Stage 2 — GRUB2: The bootloader. In BIOS mode, GRUB stage 1 lives in the MBR and loads stage 1.5 from the gap after MBR, which loads stage 2 from /boot/grub/. In UEFI mode, GRUB lives on the ESP as a .efi file. GRUB reads /boot/grub/grub.cfg (generated by update-grub or grub2-mkconfig, never edited directly) to display the boot menu. Kernel parameters are passed here (root=UUID=..., ro, quiet, splash, init=/path for alternative init).
Stage 3 — Kernel initialization: GRUB decompresses the kernel image (vmlinuz) into RAM and passes control. The kernel initializes CPU, memory management, and devices. It mounts the initramfs (initial RAM filesystem) as a temporary root.
Stage 4 — initramfs: A small, compressed cpio archive containing just enough tools and drivers to mount the real root filesystem (drivers for disk controllers, LVM, RAID, crypto). After mounting real root, it performs pivot_root to switch over.
Stage 5 — systemd: PID 1 takes over, reads unit files, starts services in dependency order to reach the default target (usually multi-user.target or graphical.target). systemd-analyze blame shows which services are slowest to start.
Key concepts
- UEFI vs BIOS
- BIOS: MBR, max 2TB, 4 primary partitions, no Secure Boot. UEFI: GPT, no practical size limit, 128 partitions, Secure Boot support, reads ESP partition.
- GRUB2
- Bootloader that loads the kernel. Config in /boot/grub/grub.cfg (auto-generated). Kernel parameters passed here. GRUB rescue shell for recovery when config is broken.
- initramfs
- Compressed cpio archive containing minimal drivers and tools needed to mount the real root filesystem. Lives at /boot/initrd.img-VERSION. Rebuilt with update-initramfs -u.
- systemd targets vs runlevels
- multi-user.target = runlevel 3 (text multi-user), graphical.target = runlevel 5 (GUI), rescue.target = runlevel 1 (single user), emergency.target (minimal). systemctl get-default shows current.
When to use it
- Diagnosing servers that fail to boot
- Adding kernel parameters for debugging (single user mode, no module loading)
- Understanding initramfs rebuild requirements after kernel module changes
- Performance tuning boot time with systemd-analyze
Interview questions
- Describe every step from pressing the power button to the login prompt appearing.
- What is initramfs and why does Linux need it?
Sign up free to read the full topic
More Linux topics
Start free on Cariara · Coding problems · System design studio