Guide
Linux
Intermediate
Linux Boot Process
The full boot sequence — firmware, bootloader, kernel initialization, initramfs, and systemd targets — plus how to debug a failed boot.
What Happens When a Linux Machine Boots?
flowchart TD
A["1. Firmware: BIOS/UEFI POST"] --> B["2. Bootloader: GRUB2"]
B --> C["3. Kernel Loads + initramfs"]
C --> D["4. Kernel Mounts Real Root Filesystem"]
D --> E["5. systemd (PID 1) Starts"]
E --> F["6. systemd Reaches Target: multi-user / graphical"]
F --> G["7. Login Prompt / Services Ready"]
Step by Step
- Firmware (BIOS/UEFI) — runs a Power-On Self Test (POST), initializes basic hardware, then hands off to a bootable device based on boot order.
- Bootloader (GRUB2) — reads its config (
/boot/grub/grub.cfg), presents the OS/kernel menu, then loads the selected kernel (vmlinuz) and initramfs into memory. - Kernel initialization — the kernel decompresses itself, initializes core drivers, and mounts the temporary initramfs as a root filesystem.
- initramfs → real root — initramfs contains just enough drivers/tools to find and mount the actual root filesystem (e.g., on an encrypted or LVM volume), then hands off (
switch_root) to it. - systemd starts as PID 1 — the very first real userspace process; everything else is its descendant.
- Targets — systemd brings up services in dependency order until it reaches the configured target (
multi-user.targetfor servers,graphical.targetfor desktops). - Login — a getty process presents a login prompt on the console, or a display manager starts for a GUI.
Inspecting and Debugging Boot
systemctl get-default # which target boots by default
systemd-analyze # total boot time
systemd-analyze blame # which services took the longest to start
systemd-analyze critical-chain # the critical path of slow-starting units
journalctl -b # full boot log for the current boot
journalctl -b -1 # log from the PREVIOUS boot (useful after a crash)
dmesg -T # kernel ring buffer messages
GRUB Essentials
cat /boot/grub2/grub.cfg | grep menuentry # available boot entries
sudo grub2-mkconfig -o /boot/grub2/grub.cfg # regenerate config after a kernel update
# At the GRUB menu: press 'e' to edit boot params, add:
# systemd.unit=rescue.target -> boot to a minimal rescue shell
# single -> single-user mode
SysV init vs systemd (Why It Changed)
| SysV init | systemd | |
|---|---|---|
| Startup | Sequential shell scripts (/etc/init.d/), largely serial | Parallel, dependency-graph based |
| Boot speed | Slower | Faster (parallelism) |
| Service definition | Shell scripts | Declarative unit files (.service) |
| Logging | Scattered across /var/log/* | Centralized in the journal (journalctl) |
Most modern distros (RHEL 7+, Ubuntu 16.04+, Debian 8+) use systemd; a few minimal/embedded distros still use SysV or OpenRC.
Recovering From a Broken Boot
# From the GRUB menu, add to the kernel line:
systemd.unit=emergency.target # minimal shell, only root mounted read-only
systemd.unit=rescue.target # single-user, most local filesystems mounted
# Once in a rescue shell:
mount -o remount,rw / # remount root as writable
journalctl -xb # see what failed on the last boot attempt
systemctl list-units --failed # which units failed to start
Production Considerations
- A bad
/etc/fstabentry is one of the most common causes of a server dropping into emergency mode — always test mount changes carefully, and knowsystemd.unit=emergency.targetas your escape hatch. systemd-analyze blameshould be part of any “why is this server slow to boot/scale up” investigation — especially for autoscaling groups where boot time directly affects scale-out latency.- Cloud instances (EC2, GCE) rely on the same boot chain but add cloud-init as an additional systemd-managed step for first-boot configuration.
Quick Interview Answer
“Boot goes: firmware POST, bootloader (GRUB) loads the kernel and initramfs, the kernel initializes and switches from initramfs to the real root filesystem, then systemd starts as PID 1 and brings the system up to a target like multi-user or graphical in dependency order rather than the old sequential SysV init scripts.
journalctl -bandsystemd-analyze blameare the go-to tools for debugging boot issues.”
Common Mistakes
- Confusing “kernel panic” (kernel itself crashes) with “systemd unit failed” (a service failed after the kernel booted fine) — very different debugging paths.
- Not knowing
journalctl -b -1exists to inspect the previous boot after an unexpected reboot. - Editing
/etc/fstabwithout testing (mount -a) before rebooting — an error there can strand a remote server in emergency mode.
Add More Questions to This Guide
Know a question that should be here? Share it and help the community!
Open Google Form