Skip to content

Linux Foundations / Understand the system underneath ยท Step 36 of 38

Lesson: Systemd GoalsSwitch
โ† Linux Foundations

System administration

Systemd Goals

See how systemd uses targets as boot goals and works out dependencies to reach them.

When systemd boots, it has a goal: reach a particular state, such as a multi-user server or a graphical desktop. Those goals are called targets. A target is a unit that mainly groups other units.

Targets

Common targets are:

  • multi-user.target a full system with text login
  • graphical.target multi-user plus a graphical login
  • rescue.target a minimal single user repair mode
  • emergency.target an even smaller shell, for serious trouble
  • poweroff.target and reboot.target

They roughly replace SysV runlevels: 1 maps to rescue, 3 to multi-user, 5 to graphical, 0 to poweroff and 6 to reboot.

The default target

$ systemctl get-default
graphical.target
$ sudo systemctl set-default multi-user.target

The change takes effect at the next boot. To switch a running system now, use isolate:

$ sudo systemctl isolate multi-user.target

isolate stops units that the new target does not need, so a graphical session can end without warning.

Dependencies and ordering

To reach a goal, systemd follows dependencies between units:

  • Wants= pulls in another unit, but carries on if it fails.
  • Requires= is a stronger requirement. If the required unit is explicitly stopped, this one is stopped too.
  • After= and Before= set order only. They do not pull anything in.

So a service that needs a database often has both Requires= and After=. Units with no ordering between them can start in parallel.

When you enable a unit that says WantedBy=multi-user.target, systemd creates a link in multi-user.target.wants. That is how the unit joins the goal.

Exploring

$ systemctl list-dependencies multi-user.target

This draws a tree of what the target pulls in. To see where boot time went:

$ systemd-analyze
$ systemd-analyze blame

blame lists units by how long they took to start. A slow unit does not necessarily delay the whole boot, because others run in parallel. systemd-analyze critical-chain helps show what was actually waiting.

Try it

Check your default target and list its dependencies. Run systemd-analyze blame and look at the top three entries. Do not change the default or isolate a target on a machine that other people are using.

Check your understanding

Systemd Goals

All 5 sections ยท no timer

Unlimited retries

Questions from every section are combined into one assessment. Answer them all correctly to complete the article.

Your completion saves in this browser. Sign in to sync it to your account.