When working with systemd, administrators often need to verify the currently active target. The confusion arises when:
systemctl get-default
shows the default target (what boots at startup)systemctl isolate
changes the current target without affecting defaults
To accurately determine the currently running target:
# Method 1: List active targets
systemctl list-units --type=target --state=active
# Method 2: Check specifically for graphical target
systemctl is-active graphical.target
# Method 3: View all dependencies
systemctl show --property=Requires --property=Wants multi-user.target
The key distinction:
- Default target: Configured in
/etc/systemd/system/default.target
- Active target: Current runtime state modified by
isolate
When debugging target issues:
# Switch to multi-user target
sudo systemctl isolate multi-user.target
# Verify current target
ACTIVE_TARGET=$(systemctl get-default)
CURRENT_TARGET=$(systemctl list-units --type=target --state=active --no-legend | awk '{print $1}')
echo "Default: $ACTIVE_TARGET, Running: $CURRENT_TARGET"
For deeper analysis:
# View target dependencies tree
systemd-analyze dot multi-user.target | dot -Tsvg > multi-user.svg
# Check conflicting units
systemd-analyze verify multi-user.target
# Monitor target changes in real-time
journalctl -f _SYSTEMD_UNIT=multi-user.target
Remember isolation is temporary. To make persistent changes:
# Set default target permanently
sudo systemctl set-default multi-user.target
# Verify both default and current state
systemctl get-default
systemctl list-units --type=target --state=active
When working with systemd targets, there's often confusion between systemctl get-default
(which shows the default target that boots at startup) and the currently active target. The isolation mechanism changes your runtime state without altering the persistent default configuration.
To see your currently active target (equivalent to traditional runlevels), use:
systemctl list-units --type=target --state=active
Or more precisely for the graphical/multi-user distinction:
systemctl is-active multi-user.target
systemctl is-active graphical.target
Here's what happens in practice when switching targets:
# Check default target (persistent across reboots)
$ systemctl get-default
graphical.target
# Switch to multi-user temporarily
$ sudo systemctl isolate multi-user.target
# Verify active target
$ systemctl is-active multi-user.target
active
$ systemctl is-active graphical.target
inactive
To make the change persist across reboots (setting the default target):
sudo systemctl set-default multi-user.target
Key differences:
isolate
: Immediate runtime change onlyset-default
: Changes configuration for future boots
For debugging complex target dependencies:
# Show all available targets
systemctl list-unit-files --type=target
# View dependency tree
systemctl list-dependencies multi-user.target