Where to start First steps track · 15 stages
Linux Labs

System boot and GRUB

5 min Ubuntu 24.04

How Linux boots: firmware, the GRUB bootloader, the kernel, systemd targets and emergency mode.

Cheat sheet

7 commands Printable version
  • sudo update-grub after editing /etc/default/grub
  • sudo grub-install /dev/sda reinstall the bootloader
  • systemctl get-default current default target
  • sudo systemctl set-default multi-user.target a server with no GUI
  • systemctl isolate rescue.target emergency mode
  • systemd-analyze blame boot timing
  • journalctl -b -1 log of the previous boot

Overview

A simplified boot chain:

BIOS/UEFI → GRUB (bootloader) → kernel + initramfs → systemd (PID 1) → target

systemd brings the system up to a target (multi-user.target for a server). Understanding the stages helps when fixing "it won't boot".

Recipes

2

GRUB

The config is /etc/default/grub (don't edit the generated grub.cfg directly):

bash
sudo nano /etc/default/grub       # GRUB_TIMEOUT, GRUB_CMDLINE_LINUX, GRUB_DEFAULT
sudo update-grub                  # rebuild grub.cfg after edits (= grub-mkconfig)
sudo grub-install /dev/sda        # reinstall the bootloader (after a disk swap, on BIOS)

Common kernel parameters in GRUB_CMDLINE_LINUX: quiet splash (quiet boot), remove them to see boot messages; nomodeset (video issues); systemd.unit=rescue.target; fsck.mode=force (force a filesystem check). In the GRUB menu, the e key edits the kernel line for one boot (e.g. to add single or init=/bin/bash).

Targets and timing

bash
systemctl get-default                       # current default target
sudo systemctl set-default multi-user.target  # a server with no GUI
systemctl isolate rescue.target             # single-user (minimal services)
systemctl isolate emergency.target          # even earlier (almost nothing up)
systemd-analyze                             # how long boot took (firmware/loader/kernel/userspace)
systemd-analyze blame                       # what's slowing boot down (by unit)
systemd-analyze critical-chain              # the critical dependency chain
systemd-analyze plot > boot.svg             # a boot diagram
Target What it is
multi-user.target a server with no graphics (normal)
graphical.target + GUI
rescue.target single-user, root mounted, minimal services
emergency.target only root (ro), almost nothing

More on targets, rescue and emergency — boot-targets; the boot time breakdown — systemd-analyze.

Troubleshooting

5

The system doesn't finish booting

  1. In GRUB, pick a previous kernel (Advanced) — it boots → the new kernel is the problem.
  2. recovery mode → root shell, fix it (fstab, permissions, configs).
  3. After logging in, journalctl -b -1 (log of the previous failed boot).

It hangs on boot because of fstab

An error in /etc/fstab drops you into emergency mode. Boot into recovery, mount -o remount,rw /, fix fstab, check with mount -a (see mount).

Slow boot

systemd-analyze blame plus critical-chain show which units are slow (often a hung network wait or mount with a timeout, NetworkManager-wait-online).

Forgot the root password

GRUB → e → add init=/bin/bash to the kernel line → boot → mount -o remount,rw / → passwd → exec /sbin/init or reboot.

initramfs prompt after a kernel update

The root/a module wasn't found. ls, find the partition, exit to continue; then sudo update-initramfs -u from a working system.

Danger zone

2

grub-install on the wrong disk

sudo grub-install /dev/sdX writes the bootloader into the MBR/EFI partition of the given disk. On a machine with several disks (or after /dev/sda and /dev/sdb swap names on reboot), it is easy to write the bootloader to the wrong place — on BIOS/MBR disks this can overwrite the first sectors with someone else's data (dual-boot, RAID metadata). Check lsblk/fdisk -l before running it; don't rely on memory.

Editing grub.cfg instead of /etc/default/grub

/boot/grub/grub.cfg is a generated file: the next update-grub (including an automatic one after a kernel update) overwrites your manual edits without warning. Change /etc/default/grub and the files in /etc/grub.d/, then run update-grub. A syntax error that accidentally ends up in grub.cfg directly can keep the system from booting until the next rebuild.

Terms

1
initramfs
A temporary root file system in memory that the boot loader hands to the kernel along with it: its programs find and mount the real root and hand over to systemd. Also appears in: Kernel modules, Software RAID with mdadm, systemd-analyze: what slows the boot and what is wrong in a unit

See also

  • systemd — The init system and service manager (PID 1): units, targets, dependencies, journals.
  • kernel-modules — Loading kernel modules, viewing kernel messages, parameters.
  • mount — Mounting filesystems, persistent mounts via /etc/fstab, UUIDs.
Loading…