Linux Labs

Inside the system: resources, kernel, processes / Stage 10 of 12

From GRUB to a target: how the system boots

Not running Starting usually ~20 s
Leave the lesson

Step 5 of 8 · on a machine · 6 min

Boot targets

A target is a unit without a program of its own: a milestone "the system has reached such a state".

You met multi-user.target in the lesson on service states: it is the normal working state of a server, and enable attaches services to it by the WantedBy= line of the [Install] section. systemctl get-default prints which target the boot heads for, and systemctl list-dependencies what is attached to a target:

bash
systemctl get-default
systemctl list-dependencies multi-user.target | head -n 8

Inside the boot there are milestone targets too: sysinit.target and basic.target from critical-chain, network.target — the network is configured, network-online.target — the network is ready for connections. A service that needs the network gets Wants= and After=network-online.target — that is how nginx is set up on this machine. This target is what held the boot up at the start of the lesson: the systemd-networkd-wait-online network wait service waits for the network to come up — on servers for up to two minutes. The training machine has no network, so the wait is switched off in the image, and the experience's preparation switched it on with a 10-second limit. Your terminal waited too: the prompt only appeared after the network wait.

Check yourself 1 question

A service unit has After=network-online.target but no Wants=, and no other unit pulls that target in. What happens at boot?

  • After= only orders units that are being started anyway. Nobody started the target — there is nothing to wait for.

  • After= is not a dependency: a target missing from the boot does not cancel the start. Only Requires= could do that.

After= only takes effect when both units are being started. network-online.target is pulled into the boot by someone's Wants= — which is why a service that needs the network writes both: Wants= and After=.

A mistake in a unit is better found before a reboot: systemd-analyze verify <unit> checks the file and prints what systemd will not understand in it — for example, Unknown key name 'Afer' for a line with a typo. At boot systemd silently skips such a line, and the ordering in it does not work.

Key points

  • A target is a boot milestone; the boot heads for the target from systemctl get-default, on a server — multi-user.target.
  • A service that needs the network waits for network-online.target with Wants= and After= lines.
  • systemd-analyze verify finds a unit's mistakes before they surface at boot.
Ubuntu 24.04
Loading…