devutils/ATFQ/book ATFQ git

Part II · Your system

20.4 systemd targets

alsotargettargetsrunleveldefault targetmulti-user.targetgraphical.targetrescue modeemergency mode

TL;DR

  • A target is a stage the system can reach. multi-user.target: text mode with network and services. graphical.target: the same plus a login screen.
  • Boot stops at the default target: systemctl get-default shows it, set-default changes it.
  • rescue.target and emergency.target are minimal modes for repairs.
systemctl get-default
sudo systemctl set-default multi-user.target
sudo systemctl isolate rescue.target   # switch now

On your machine

alice@laptopexample
$ atfq 20.4
  Firmware  UEFI · Secure Boot on
  Kernel    6.12.48-amd64
  Cmdline   BOOT_IMAGE=/vmlinuz-6.12.48-amd64
            root=UUID=3f1c2a9e-8b7d-4e21-9c55-0a6b2d7e9f10 ro
            rootflags=subvol=@ quiet splash
  Init      systemd · default target graphical.target
  Loader    systemd-boot 256.4 · 1 unified kernel image(s)
  Up        3 days, 4 h

An example: Alice's laptop, one of the test machines. In your terminal, this block shows your own machine, read live.

Pitfalls

Deep dive 2 questions

How do targets replace runlevels?

SysV init had numbered runlevels, 0 to 6, with fixed meanings. Targets have names, depend on each other and can be combined. Aliases such as runlevel3.target (multi-user) and runlevel5.target (graphical) keep old habits working.

Rescue or emergency?

rescue.target mounts the filesystems, starts a few basic services and opens a root shell. emergency.target mounts only the root filesystem, read-only, for when even /etc/fstab is broken.

Commands
systemctl
Paths
/etc/systemd/system/default.target
See also
20. Boot
22.1 Units and timers
20.2 The kernel command line