Courses3 levels
Level 1 · Foundations11 courses
Level 2 · Core5 courses
Level 3 · Advanced5 courses
Labs8 topics
Library Practice exams AI Range Pricing Start free

Part 4 · Operations and troubleshooting · Lesson 01 · 55 minutes

Follow the boot process from power-on to login

After this lesson you can
  • Name the stages of a boot and the files and tools that belong to each stage
  • Measure a boot with systemd-analyze and read the log of a boot with journalctl
  • Read a boot loader entry and a kernel panic, and name the recovery options
Lab files of this lesson (5)

The lab folder as it stands after this lesson. Unzip it in ~/krlab.

More

The zip holds every file that the course has printed up to here. To start this lesson with the files of the earlier lessons only, take the zip of the lesson before. Type the code yourself first: you learn more.

Scenario

A server takes four minutes to come back after a reboot, and last week another one stopped on a screen full of kernel messages. Your lead asks: "Where does the time go?" and "What does the last message say?" You answer from the evidence that every boot leaves: the log, the times of the units, and the kernel's last words.

The idea

A boot is a chain. Each stage starts the next one and then steps away.

The stages of a boot
FirmwareBoot loaderKernelInitial RAM disksystemdfinds GRUB on a diskloads it with its command linemounts it, runs its initmounts the root, hands overFirmwareBoot loaderKernelInitial RAM disksystemd1234
  1. Firmware → Boot loader: finds GRUB on a disk
  2. Boot loader → Kernel: loads it with its command line
  3. Kernel → Initial RAM disk: mounts it, runs its init
  4. Initial RAM disk → systemd: mounts the root, hands over
StageWhat it doesWhere to look
FirmwareTests the hardware, finds a boot loader on a disk. UEFI keeps it on a small FAT partition (the ESP, usually /boot/efi). BIOS reads the first sector.ls /sys/firmware/efi exists only after a UEFI boot
Boot loaderGRUB reads its configuration, shows a menu, loads the kernel and the initial RAM disk with the command line./etc/default/grub, /boot/grub/grub.cfg
KernelStarts, sets up memory, finds the hardware, mounts the initial RAM disk./boot/vmlinuz-*, /proc/cmdline, journalctl -k
Initial RAM diskA small root file system in memory (initrd or initramfs) with the drivers and tools that find and mount the real root disk.sudo lsinitramfs /boot/initrd.img
systemdRuns as PID 1 and starts the units that the default target needs.systemctl get-default, systemd-analyze

A target is a named group of units that stands for a state: rescue.target is a single-user shell, multi-user.target is a full system without a desktop, and graphical.target adds the desktop.

Worked example

The outputs come from a virtual machine with Ubuntu 24.04, so your times, versions, numbers and lines differ. Recovery mode and a real kernel panic were not run, because they need a console. Commands with sudo need administrator rights.

1. Find the stages on your machine

ls /sys/firmware/efi exists after a UEFI boot. /boot holds the kernel (vmlinuz), the initial RAM disk (initrd.img) and the build settings of the kernel. /proc/cmdline is the command line that the boot loader gave the kernel, and uname -r is the version of the kernel that runs.

[ -d /sys/firmware/efi ] && echo "UEFI" || echo "BIOS"
ls /boot
ls -l /boot/vmlinuz /boot/initrd.img
cut -c1-100 /proc/cmdline
uname -r
UEFI
System.map-6.8.0-149-generic
config-6.8.0-149-generic
efi
grub
initrd.img
initrd.img-6.8.0-149-generic
initrd.img.old
vmlinuz
vmlinuz-6.8.0-149-generic
vmlinuz.old
lrwxrwxrwx 1 root root 28 Nov 18 07:51 /boot/initrd.img -> initrd.img-6.8.0-149-generic
lrwxrwxrwx 1 root root 25 Nov 18 07:51 /boot/vmlinuz -> vmlinuz-6.8.0-149-generic
BOOT_IMAGE=/boot/vmlinuz-6.8.0-149-generic root=UUID=13bf4261-5483-44f0-bb88-22d5851139ad ro quiet s
6.8.0-149-generic

The command line names the kernel file (BOOT_IMAGE) and the root file system (root=). The links vmlinuz and initrd.img point to the newest version, and the .old links keep the one before.

2. Look inside the initial RAM disk

lsinitramfs FILE lists the files of an initial RAM disk. It holds a program init, which the kernel starts first, and the driver modules (.ko files) that the boot needs. grep -x keeps only lines that match completely, and grep -c counts the lines that match. Use sudo: on a newer release only root may read the file.

sudo lsinitramfs /boot/initrd.img | wc -l
sudo lsinitramfs /boot/initrd.img | grep -x init
sudo lsinitramfs /boot/initrd.img | grep -c "\.ko"
545
init
148

The init of the initial RAM disk loads the drivers, finds the root disk, mounts it, and hands over to /sbin/init, which is systemd. If a driver is missing here, the root disk is not found: that is the cause of the panic in step 7.

3. Read the default target and the targets that are active

systemctl get-default prints the default target. systemctl list-units --type=target lists the targets that are active now. set-default changes the default for the next boot, so remember the old value and put it back.

systemctl get-default
systemctl list-units --type=target --no-pager --no-legend | head -n 3
OLD=$(systemctl get-default)
sudo systemctl set-default multi-user.target
sudo systemctl set-default "$OLD"
graphical.target
  basic.target               loaded active active Basic System
  cryptsetup.target          loaded active active Local Encrypted Volumes
  first-boot-complete.target loaded active active First Boot Complete
Created symlink /etc/systemd/system/default.target → /usr/lib/systemd/system/multi-user.target.
Created symlink /etc/systemd/system/default.target → /usr/lib/systemd/system/graphical.target.

If the link existed already, each set-default also prints a line Removed "/etc/systemd/system/default.target".

The default target is a link, and set-default changes only the link. A server without a desktop should boot to multi-user.target.

4. Measure the boot

systemd-analyze prints how long the boot took. blame lists the units, slowest first. critical-chain shows the chain of units that decided the total time: a unit that starts in parallel with others does not slow the boot, but a unit that the others wait for does. On physical hardware the first line also names the firmware and boot loader times.

systemd-analyze
systemd-analyze blame --no-pager | head -n 3
systemd-analyze critical-chain --no-pager | sed -n '4,9p'
Startup finished in 2.900s (kernel) + 2.029s (userspace) = 4.930s 
graphical.target reached after 2.007s in userspace.
873ms incus-agent.service
724ms dev-sda2.device
363ms systemd-udev-trigger.service
graphical.target @2.007s
└─multi-user.target @2.007s
  └─incus-agent.service @1.133s +873ms
    └─systemd-journald.socket @400ms
      └─system.slice @358ms
        └─-.slice @358ms

In critical-chain, the number after @ is the time at which the unit started, and the number after + is how long it took. Each line waited for the line below it. A large + time on the chain is the unit to fix. (incus-agent is the helper of the program that runs this virtual machine; your list has other units.)

5. Read the log of a boot

The journal keeps the messages of each boot. journalctl --list-boots lists the boots that it holds. -b selects the current boot, -b -1 the one before, -p err keeps messages of the priority error and worse, and -k keeps only the kernel's messages. The journal is kept across reboots only when Storage=persistent is set, or when /var/log/journal exists. In the last command below, grep -m2 stops after two matches.

sudo journalctl --list-boots --no-pager | tail -n 2
sudo journalctl -b -1 --no-pager -n 2
sudo journalctl -b -p err --no-pager
sudo journalctl -b -k --no-pager | grep -m2 sda | cut -c1-90
 -1 79a2c93eee714b90b5d29004e04df0a0 Sat 2026-11-21 18:53:51 UTC Sat 2026-11-21 18:55:33 UTC
  0 166ec0b5c59d41bdb339bc7396c69a84 Sat 2026-11-21 18:55:47 UTC Sat 2026-11-21 18:55:49 UTC
Nov 21 18:55:33 krbox systemd-shutdown[1]: Sending SIGTERM to remaining processes...
Nov 21 18:55:33 krbox systemd-journald[242]: Journal stopped
-- No entries --
Nov 21 18:55:47 krbox kernel: sd 0:0:0:1: [sda] 41943040 512-byte logical blocks: (21.5
Nov 21 18:55:47 krbox kernel: sd 0:0:0:1: [sda] Write Protect is off

The last lines of the boot before show how it ended: after a crash they are the most useful lines that you have. The third command lists the errors of this boot: -- No entries -- on a healthy machine. The kernel lines show that it found the disk sda (20 GiB). sudo dmesg prints the same kernel messages with the seconds since the kernel started in place of the date.

6. Read the boot loader configuration

GRUB settings live in /etc/default/grub. update-grub builds /boot/grub/grub.cfg from it and from the scripts in /etc/grub.d. Never edit grub.cfg by hand, because the next kernel update replaces it. Read the settings file first.

grep -v '^#' /etc/default/grub | grep -v '^$' | grep -E "TIMEOUT|CMDLINE"
GRUB_TIMEOUT_STYLE=hidden
GRUB_TIMEOUT=0
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"
GRUB_CMDLINE_LINUX=""

GRUB_TIMEOUT is the seconds of the menu. GRUB_CMDLINE_LINUX_DEFAULT is added to the command line of the normal entries only, and GRUB_CMDLINE_LINUX to all of them, the recovery entry too. To change a setting, edit the file as root and run sudo update-grub, which says which files it read and which kernels it found:

sudo update-grub
Sourcing file `/etc/default/grub'
Sourcing file `/etc/default/grub.d/50-incus.cfg'
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-6.8.0-149-generic
Found initrd image: /boot/initrd.img-6.8.0-149-generic
Adding boot menu entry for UEFI Firmware Settings ...
done

A file in /etc/default/grub.d/ overrides the main file: here it adds a serial console. The real grub.cfg differs on every machine, so practise on a sample, saved as grub-sample.cfg. It has the form that grub.cfg has, with the extra --class words removed.

grub-sample.cfg

### BEGIN /etc/grub.d/10_linux ###
menuentry 'Ubuntu' $menuentry_id_option 'gnulinux-simple-0a1b2c3d' {
	linux	/boot/vmlinuz-6.8.0-45-generic root=UUID=0a1b2c3d-1111-2222-3333-444455556666 ro  quiet splash $vt_handoff
	initrd	/boot/initrd.img-6.8.0-45-generic
}
submenu 'Advanced options for Ubuntu' $menuentry_id_option 'gnulinux-advanced-0a1b2c3d' {
	menuentry 'Ubuntu, with Linux 6.8.0-45-generic' {
		linux	/boot/vmlinuz-6.8.0-45-generic root=UUID=0a1b2c3d-1111-2222-3333-444455556666 ro  quiet splash $vt_handoff
		initrd	/boot/initrd.img-6.8.0-45-generic
	}
	menuentry 'Ubuntu, with Linux 6.8.0-45-generic (recovery mode)' {
		linux	/boot/vmlinuz-6.8.0-45-generic root=UUID=0a1b2c3d-1111-2222-3333-444455556666 ro recovery nomodeset dis_ucode_ldr
		initrd	/boot/initrd.img-6.8.0-45-generic
	}
	menuentry 'Ubuntu, with Linux 6.8.0-41-generic' {
		linux	/boot/vmlinuz-6.8.0-41-generic root=UUID=0a1b2c3d-1111-2222-3333-444455556666 ro  quiet splash $vt_handoff
		initrd	/boot/initrd.img-6.8.0-41-generic
	}
}
### END /etc/grub.d/10_linux ###
grep -c "menuentry '" grub-sample.cfg
sed -n '3,4p' grub-sample.cfg | cut -c1-120
4
	linux	/boot/vmlinuz-6.8.0-45-generic root=UUID=0a1b2c3d-1111-2222-3333-444455556666 ro  quiet splash $vt_handoff
	initrd	/boot/initrd.img-6.8.0-45-generic

Each menuentry is one choice of the menu. Its linux line names the kernel and its command line. The initrd line names the initial RAM disk. The recovery entry has (recovery mode) in its name and recovery on its linux line (Debian writes single). On Ubuntu it opens a menu with a root shell, a file system check and a package repair.

The linux line of a menu entry
linuxload this kernel/boot/vmlinuz-6.8.0-45-genericthe kernel fileroot=UUID=0a1b2c3d...the root file systemromount it read-only at firstquiet splashhide the boot messageslinuxload this kernel/boot/vmlinuz-6.8.0-45-genericthe kernel fileroot=UUID=0a1b2c3d...the root file systemromount it read-only at firstquiet splashhide the boot messages

7. Read a kernel panic

A kernel panic is the kernel's decision to stop, because it found an error that it cannot survive. The console shows its last messages. Read a short log. grep -B2 prints the two lines before each match.

cat > panic-demo.log <<'EOT'
[    2.101123] VFS: Cannot open root device "UUID=0a1b2c3d" or unknown-block(0,0): error -6
[    2.101890] Please append a correct "root=" boot option; here are the available partitions:
[    2.102455] Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(0,0)
[    2.103012] CPU: 0 PID: 1 Comm: swapper/0 Not tainted 6.8.0-45-generic #45-Ubuntu
EOT
grep -B2 "Kernel panic" panic-demo.log | cut -c1-96
[    2.101123] VFS: Cannot open root device "UUID=0a1b2c3d" or unknown-block(0,0): error -6
[    2.101890] Please append a correct "root=" boot option; here are the available partitions:
[    2.102455] Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(0,0)

Read a panic in four steps. First, the Kernel panic - not syncing: line gives the reason:

The panic line
[ 2.102455]seconds since kernel startKernel panic - not syncing:the kernel stops hereVFS: Unable to mount...the reason: no root device[ 2.102455]seconds since kernel startKernel panic - not syncing:the kernel stops hereVFS: Unable to mount...the reason: no root device

Second, the lines before it give the cause: the kernel could not open the root device, and no partition is listed, so the driver of the disk is missing from the initial RAM disk, or the root= value is wrong. Third, PID: 1 says that the failure came in the first process. Fourth, the call trace names the code path, which matters for kernel developers but seldom for you. Copy the lines before the panic into the ticket: the screen is gone after the next boot, unless a serial console or kdump saved it.

8. Know the recovery options

These need a console, so they were not tested.

SituationOption
The newest kernel does not bootIn the GRUB menu, choose an older kernel under "Advanced options".
A configuration error stops the bootEdit the entry in GRUB (key e). With a root password, add systemd.unit=rescue.target for a root shell, or emergency.target for the minimum. Ubuntu locks the root account, so these two stop with "the root account is locked": use the recovery entry, or add init=/bin/bash (the root file system is read-only then: mount -o remount,rw / first).
The boot loader or /etc/fstab is brokenBoot a live USB, mount the root disk, enter it with chroot (lesson 7 of Part 3), fix /etc/fstab, or run grub-install and update-grub.
The file system is damagedfsck on the unmounted file system, from the live USB.

Access to the console means access to everything: a person who can edit the GRUB entry can get a root shell. Protect it with a GRUB password and with disk encryption, and keep the machine in a locked room.

Your turn

Two files came from a server that boots slowly and from one that panics. Save them. There are no steps here: use the commands of the worked example.

boot-times.txt

1min 30.114s systemd-networkd-wait-online.service
     9.804s cloud-init-local.service
     4.512s snapd.seeded.service
     3.907s apt-daily-upgrade.service
     2.246s dev-sda2.device
     1.388s cloud-init.service
     1.205s networkd-dispatcher.service
      914ms ssh.service
      703ms systemd-journal-flush.service
      410ms cron.service

panic.log

[    0.000000] Linux version 6.8.0-45-generic (buildd@lcy02-amd64-051) #45-Ubuntu SMP PREEMPT_DYNAMIC
[    0.000000] Command line: BOOT_IMAGE=/vmlinuz-6.8.0-45-generic root=UUID=0a1b2c3d-1111-2222-3333-444455556666 ro quiet
[    1.804120] Freeing unused kernel image (initmem) memory: 4096K
[    1.812377] Write protecting the kernel read-only data: 26624k
[    4.310982] Run /sbin/init as init process
[    4.311540] Starting init: /sbin/init exists but couldn't execute it (error -8)
[    4.312018] Run /etc/init as init process
[    4.312399] Run /bin/init as init process
[    4.312720] Run /bin/sh as init process
[    4.313122] Kernel panic - not syncing: No working init found.  Try passing init= option to kernel.
[    4.313998] CPU: 1 PID: 1 Comm: swapper/0 Not tainted 6.8.0-45-generic #45-Ubuntu
[    4.314650] Call Trace:
[    4.314990]  <TASK>
[    4.315210]  dump_stack_lvl+0x48/0x70
[    4.315470]  panic+0x356/0x380
[    4.315690]  kernel_init+0x1ab/0x1c0
[    4.315930]  ret_from_fork+0x44/0x70
[    4.316200]  </TASK>
[    4.316480] ---[ end Kernel panic - not syncing: No working init found.  Try passing init= option to kernel. ]---

boot-times.txt is the output of systemd-analyze blame. panic.log is the text from a console. Find the answers.

Then say in two sentences what each case needs next.

Check yourself

The system boots but a service you need is not running. Which stage failed?

Only the last one. The firmware, the boot loader, the kernel and the initial RAM disk worked, because systemd runs. Read systemctl status and journalctl -b -u NAME of the service.

You edit /boot/grub/grub.cfg to add a kernel option, and it is gone after the next kernel update. Why?

grub.cfg is generated by update-grub from /etc/default/grub and the scripts in /etc/grub.d. Change the source, and run sudo update-grub.

What does the line "VFS: Unable to mount root fs" tell you, and what do you check first?

The kernel could not find or mount the root file system. Check the root= value of the boot entry and whether the initial RAM disk holds the driver of the disk. A live USB lets you repair either.

systemd-analyze blame lists a unit at 20 seconds. Is it the reason for a slow boot?

Not necessarily. blame shows how long each unit took, and units run in parallel. Only a unit on the critical chain delays the boot. Check systemd-analyze critical-chain.

Field notes

  • Keep the journal across reboots (Storage=persistent in /etc/systemd/journald.conf). A log that vanishes at the reboot cannot explain the crash.
  • Keep two kernels installed, so that a bad update can be skipped from the GRUB menu. Test a new kernel with a reboot while you can reach the console.
  • A serial console and kdump give you the last messages of a panic on a server that has no screen. Set a root password, or learn the recovery menu, before you need either.
  • Secure Boot checks the signature of the boot loader and the kernel. It protects against a replaced boot file, and it needs signed modules.
  • Do not change /etc/fstab without checking it: a wrong line can stop the boot in emergency mode. sudo findmnt --verify checks the file before you reboot.