Exercise: the Linux boot process

  1. Step 1 — Phase 1 — Measure boot and find the culprit on the slow VM (171)
  2. Step 2 — Phase 2 — Compare with the fast-booting VM (172) to confirm the culprit
  3. Step 3 — Phase 3 — Inspect each layer + the fix (not applied on the VM)
  4. Illustration 1 — Measure boot + find the culprit (slow VM 171)
  5. Illustration 2 — FAILED unit + the reason (journal)
  6. Illustration 3 — Comparison with the fast-booting VM (172)

Estimated time: 40 minutes.

Analyze the Linux boot process: measure boot time and identify the service that slows down boot with systemd-analyze (blame / critical-chain / --failed),

explain the 5 boot layers (firmware → GRUB → kernel → initramfs → systemd), and propose ways to fix a slow boot.

The IP addresses in this exercise are illustrative addresses from the range reserved for documentation (RFC 5737): dattqh-nat = 192.0.2.21, dattqh-client = 192.0.2.22; when you do the exercise, replace them with the real IPs of your machines.

Step 1 — Phase 1 — Measure boot and find the culprit on the slow VM (171)

The standard procedure for finding a slow boot is systemd-analyze → blame → critical-chain → --failed (systemd-analyze(1)).

# On dattqh-nat (192.0.2.21)
systemd-analyze
systemd-analyze blame | head -10
systemd-analyze critical-chain | head -20
systemctl --failed
sudo journalctl -b -u systemd-networkd-wait-online --no-pager | tail

Notes: Observations: systemd-analyze → 4.065s (kernel) + 2min 2.993s (userspace).

Top of blame = 2min 131ms systemd-networkd-wait-online.service. systemctl --failed lists this unit as FAILED. journal: Timeout occurred while waiting for network connectivity.

Step 2 — Phase 2 — Compare with the fast-booting VM (172) to confirm the culprit

Same image, the dattqh-client VM boots in 8.9s.

# On dattqh-client (192.0.2.22)
systemd-analyze
systemd-analyze blame | head -6
systemctl --failed
sudo journalctl -b -u systemd-networkd-wait-online --no-pager | tail -3

Notes: Observations: systemd-analyze → 4.322s + 4.663s = 8.985s. blame: 1.140s systemd-networkd-wait-online.service (finished quickly). systemctl --failed is empty. journal: Finished systemd-networkd-wait-online.service (~1s, no timeout).

Step 3 — Phase 3 — Inspect each layer + the fix (not applied on the VM)

Understanding boot is not just measuring time; it also means reading the current state of each layer: kernel cmdline, GRUB, initramfs, default.target.

# On 171 — read each layer (read-only)
cat /proc/cmdline
ps -p 1 -o pid,comm
findmnt /
lsinitramfs /boot/initrd.img-$(uname -r) | grep -iE 'lvm|virtio' | head
systemctl get-default

# HOW TO FIX wait-online (for reference — do not run on the lab VM):
#   sudo nano /etc/netplan/50-cloud-init.yaml  -> add 'optional: true' under ens160
#   sudo netplan try && sudo netplan apply
# or remove 'dhcp4: true' if you only use a static address.

Notes: Observations: cat /proc/cmdline → BOOT_IMAGE=/vmlinuz-6.8.0-31-generic root=/dev/mapper/ubuntu--vg-ubuntu--lv ro. ps -p 1 → 1 systemd. findmnt / → root on /dev/mapper/ubuntu--vg-ubuntu--lv. systemctl get-default → graphical.target.

Illustration 1 — Measure boot + find the culprit (slow VM 171)

systemd-analyze 2min; blame lists networkd-wait-online first

systemd-analyze: userspace takes 2 minutes; blame lists systemd-networkd-wait-online first.

Illustration 2 — FAILED unit + the reason (journal)

systemctl --failed lists wait-online; journal shows a 120s Timeout

systemctl --failed + journal: wait-online timed out after 120s → status=1/FAILURE.

Illustration 3 — Comparison with the fast-booting VM (172)

systemd-analyze 9s; wait-online 1.1s; no failed unit

Same image: boot takes 9s, wait-online finishes in 1.1s, no unit is FAILED → the culprit is a hung service, not the hardware.

Exercise: the Linux boot process