Booting a Linux system is a chain of handoffs: firmware initializes hardware, a bootloader loads the kernel, the kernel prepares the system, and systemd
brings user space to life.
High-Level Overview
1) Power-On, POST, and Firmware (BIOS/UEFI)
- POST (Power-On Self-Test) verifies CPU, RAM, basic chipset, storage controllers, and peripherals.
- Hardware initialization configures controllers (SATA/NVMe/USB, GPU, timers) so code can be read from disks/USB/Net.
- Boot selection uses a firmware-defined order to choose a bootable device (SSD/HDD/USB/Network).
2) Primary vs Secondary Boot Loader
- Primary boot loader (BIOS/MBR): ~446 bytes of code at disk sector 0; too small for menus/filesystems—just finds and loads next stage.
-
UEFI: loads an EFI executable (e.g.,
\EFI\GRUB\grubx64.efi
,\EFI\systemd\systemd-bootx64.efi
) from the EFI System Partition (ESP). - Secondary boot loader (e.g., GRUB, systemd-boot): shows a menu, accepts kernel parameters, loads kernel and initramfs.
Common kernel parameters (set by the bootloader):
-
root=
(e.g.,root=/dev/nvme0n1p2
orroot=UUID=...
) – tells the kernel where the real root filesystem is. -
ro
/rw
– mount root initially read-only or read-write. -
quiet
/verbose
– control console verbosity. -
single
orsystemd.unit=rescue.target
– maintenance boot modes. -
init=
– override PID 1 (rare, for rescue/debug).
3) Kernel Initialization (Early Userspace with initramfs)
- Kernel decompression & start: kernel unpacks in RAM and begins execution.
- Hardware bring-up: CPU & SMP, memory manager & page tables, device buses (PCI/USB), interrupts & timers.
- Driver loading: built-in drivers + modules from initramfs to access storage, crypto, filesystems, etc.
-
Root filesystem discovery: initramfs scripts discover and mount the real root FS, then
pivot_root
/switch_root
to it. -
PID 1 start: kernel executes the first userspace process (normally
/sbin/init
→systemd
).
4) systemd Takes Over (PID 1)
- Unit files describe services, sockets, timers, mounts, targets (goal states).
-
Parallel startup honors dependencies (
After=
,Wants=
,Requires=
) to speed boot. -
Targets replace SysV runlevels:
-
rescue.target
(single-user),multi-user.target
(server/text),graphical.target
(desktop).
-
-
Key tools:
systemctl
(control units),journalctl
(logs),systemd-analyze
(boot timing).
Example service dependencies:
-
network-online.target
before services needing network (e.g.,docker.service
). -
local-fs.target
ensures local filesystems are mounted before dependent services.
5) Login Stage
-
Server consoles: systemd spawns
agetty@ttyX.service
for virtual TTYs (Ctrl+Alt+F1..F6). - Desktops: a Display Manager (GDM, SDDM, LightDM) provides GUI login and launches the session (GNOME/KDE/etc.).
- After authentication, shell or desktop session starts and userland completes initialization (user services, autostart apps).
6) Common Failure Points & Recovery Hints
- Firmware/Boot order: ensure the correct disk/ESP entry is first.
-
GRUB issues: from live media,
chroot
and reinstallgrub
, regenerate configs (grub-mkconfig
). -
Kernel panic (root FS): verify
root=UUID=...
, rebuild initramfs (e.g.,dracut
,update-initramfs
), confirm modules for storage controller. -
Emergency/Rescue: boot with
systemd.unit=rescue.target
, inspect logsjournalctl -b -p err
, disable problematic services withsystemctl disable --now ...
.
Quick Reference: Useful Commands
-
Firmware/ESP:
efibootmgr -v
(UEFI entries),lsblk -f
(filesystems & UUIDs) -
Bootloader:
grub-install
,grub-mkconfig -o /boot/grub/grub.cfg
-
Kernel/initramfs:
uname -a
,lsinitramfs
/lsinitrd
,update-initramfs -u
/dracut -f
-
systemd:
systemd-analyze blame/critical-chain
,systemctl list-dependencies
,journalctl -b
Final Takeaway
From POST to login, Linux traverses predictable stages. Knowing where you are—firmware, bootloader, kernel, or systemd
—turns a mysterious “it won’t boot” into a solvable problem with concrete tools and checkpoints.
Top comments (0)