Notes
1 · Firmware
Power on, and the CPU starts running firmware stored on the motherboard. Older machines use BIOS, newer ones UEFI. The firmware checks the hardware and finds something to boot. BIOS reads the first sector of a disk; UEFI reads a boot program from a small EFI partition. In our test virtual machine the firmware was SeaBIOS, a free BIOS. In the cloud, the hypervisor provides the firmware for you.
- power on: the CPU runs firmware stored on the motherboard
- checks hardware (POST)
- finds a boot device: BIOS reads the first sector UEFI reads an EFI partition
- cloud VMs: the hypervisor provides the firmware
2 · Boot loader
Next comes the boot loader, usually GRUB. It can show a menu of installed kernels, which is how you boot the previous kernel when a new one fails. It loads two files into memory, the kernel and the initramfs, and passes the kernel a command line of options, such as which disk holds the root filesystem and where to print messages. Its config is generated; you change settings in the defaults file and regenerate it.
- shows a menu of kernels (often hidden)
- loads the kernel file and the initramfs into memory
- passes the kernel command line: root=, console=, quiet
- config: /boot/grub/grub.cfg (generated, do not edit; use /etc/default/grub)
3 · Kernel
The kernel starts. It decompresses itself, sets up memory management, detects the CPU and devices, and loads drivers. Every step is logged, and dmesg shows the log with seconds since boot. Our run printed the version line at time zero, Ubuntu's six point eight kernel, fifteen megabytes compressed. A couple of seconds later it freed the memory it only needed while starting. Kernel panics and missing disk drivers show up right here.
[0.000000] Linux version 6.8.0-151-generic ... gcc 13.3.0 ... [2.468470] Freeing unused kernel image (initmem) memory: 4948K kernel file: 15.1 MB (vmlinuz, compressed)
4 · initramfs
Here is a puzzle. The real root filesystem may sit on a disk that needs a driver, RAID, LVM or decryption before it can be read. So the kernel first unpacks an initramfs, a small archive of tools held in memory, and runs it. Its job is to find and mount the real root, then hand over. Ours was tiny, one point one megabytes: a single busybox program and a short script. Ubuntu's real initramfs is larger, with drivers for many disks.
- the real root disk may need drivers, RAID, LVM or decryption first
- initramfs: a small archive of tools in memory
- it mounts the real root, then hands over ours: 1.1 MB, one busybox binary + an init script
5 · PID 1
Then the kernel starts process number one, PID one, the ancestor of every other process. On real servers that is systemd. In our test it was our own small init script, which printed when user space began: two point seven six, two point six seven and two point four nine seconds after power-on in three boots. Sixty one processes already existed, most of them kernel threads. Our CPU was fully emulated, with no hardware virtualisation, so a normal VM boots faster.
INIT: userspace started at 2.76 s / 2.67 s / 2.49 s PID1: init KERNEL: 6.8.0-151-generic PROCS: 61 no KVM: the CPU was emulated, so a real VM boots faster
6 · systemd
systemd reads unit files, which describe services, mounts, sockets and timers, and starts them in parallel, respecting their dependencies. It aims for a target. Servers usually aim for multi user target: networking, SSH and your services, no desktop. Desktops aim for graphical target. systemd also restarts services that crash and collects their logs, which episode nine covers in depth.
- reads unit files: services, mounts, sockets, timers
- starts them in parallel, in dependency order
- reaches a target: multi-user.target (servers) graphical.target (desktops)
- restarts services that crash
Measure your boot
On a machine running systemd, you can measure the boot yourself. systemd analyze prints the time spent in firmware, loader, kernel and user space. Blame lists the slowest units first, and critical chain shows what the boot actually waited on, which is often a network wait or a slow disk mount. And journal control with minus b and priority error shows the errors from this boot only. Run these in your lab after a reboot.
$ systemd-analyze firmware + loader + kernel + userspace = total $ systemd-analyze blame slowest units first $ systemd-analyze critical-chain what the boot waited on $ journalctl -b -p err errors from this boot
When it will not boot
When a server will not boot, find the stage that failed. No boot device points at firmware or disk order. Stuck at a GRUB prompt means the boot loader config or the kernel file is missing. A kernel panic saying it cannot mount root means the root option is wrong, or the initramfs lacks a driver. Dropped into an emergency shell usually means a bad line in the filesystem table, fstab. In the cloud, use the serial console to see these messages.
- no boot device → firmware or disk order
- GRUB prompt → boot loader config or missing kernel
- kernel panic: unable to mount root → root= or initramfs missing a driver
- emergency shell → a bad /etc/fstab line
- service missing → systemd unit
Common mistakes
Mistakes. A typo in fstab that stops the boot; mark optional disks with nofail. Removing the previous kernel before the new one has booted successfully. Editing the generated GRUB file directly, so your change vanishes. Having no serial console access for cloud servers. And starting a service by hand but never enabling it, so it is gone after the next reboot.
- a typo in /etc/fstab: no boot (use nofail for extras)
- removing the old kernel before the new one is proven
- editing grub.cfg directly
- no serial console access in the cloud
- services enabled nowhere: gone after reboot
Say it like this
In the interview: firmware, BIOS or UEFI, checks the hardware and finds the boot loader. GRUB loads the kernel and the initramfs and passes the kernel command line. The kernel initialises memory and devices, the initramfs finds and mounts the real root filesystem, and the kernel starts PID one, systemd, which starts units in dependency order until it reaches multi user target. I debug boots by finding which of those stages failed.
- "Firmware, BIOS or UEFI, finds
- the boot loader, GRUB, which loads the kernel and initramfs
- with a command line. The kernel
- initialises hardware, the initramfs mounts the real root, then PID 1, systemd, starts
- units up to multi-user.target."