10.3. Working with systemd Targets
.target file extension and their only purpose is to group together other systemd units through a chain of dependencies. For example, the graphical.target unit, which is used to start a graphical session, starts system services such as the GNOME Display Manager (gdm.service) or Accounts Service (accounts-daemon.service) and also activates the multi-user.target unit. Similarly, the multi-user.target unit starts other essential system services such as NetworkManager (NetworkManager.service) or D-Bus (dbus.service) and activates another target unit named basic.target.
Table 10.6. Comparison of SysV Runlevels with systemd Targets
| Runlevel | Target Units | Description |
|---|---|---|
0 | runlevel0.target, poweroff.target | Shut down and power off the system. |
1 | runlevel1.target, rescue.target | Set up a rescue shell. |
2 | runlevel2.target, multi-user.target | Set up a non-graphical multi-user system. |
3 | runlevel3.target, multi-user.target | Set up a non-graphical multi-user system. |
4 | runlevel4.target, multi-user.target | Set up a non-graphical multi-user system. |
5 | runlevel5.target, graphical.target | Set up a graphical multi-user system. |
6 | runlevel6.target, reboot.target | Shut down and reboot the system. |
systemctl utility as described in Table 10.7, “Comparison of SysV init Commands with systemctl” and in the sections below. The runlevel and telinit commands are still available in the system and work as expected, but are only included for compatibility reasons and should be avoided.
Table 10.7. Comparison of SysV init Commands with systemctl
| Old Command | New Command | Description |
|---|---|---|
runlevel | systemctl list-units --type target | Lists currently loaded target units. |
telinit runlevel | systemctl isolate name.target | Changes the current target. |
10.3.1. Viewing the Default Target
systemctl get-default/etc/systemd/system/default.target and displays the result. For information on how to change the default target, see Section 10.3.3, “Changing the Default Target”. For information on how to list all currently loaded target units, see Section 10.3.2, “Viewing the Current Target”.
Example 10.10. Viewing the Default Target
~]$ systemctl get-default
graphical.target10.3.2. Viewing the Current Target
systemctl list-units --type targetUNIT) followed by a note whether the unit has been loaded (LOAD), its high-level (ACTIVE) and low-level (SUB) unit activation state, and a short description (DESCRIPTION).
systemctl list-units command displays only active units. If you want to list all loaded units regardless of their state, run this command with the --all or -a command line option:
systemctl list-units --type target --allExample 10.11. Viewing the Current Target
~]$ systemctl list-units --type target
UNIT LOAD ACTIVE SUB DESCRIPTION
basic.target loaded active active Basic System
cryptsetup.target loaded active active Encrypted Volumes
getty.target loaded active active Login Prompts
graphical.target loaded active active Graphical Interface
local-fs-pre.target loaded active active Local File Systems (Pre)
local-fs.target loaded active active Local File Systems
multi-user.target loaded active active Multi-User System
network.target loaded active active Network
paths.target loaded active active Paths
remote-fs.target loaded active active Remote File Systems
sockets.target loaded active active Sockets
sound.target loaded active active Sound Card
spice-vdagentd.target loaded active active Agent daemon for Spice guests
swap.target loaded active active Swap
sysinit.target loaded active active System Initialization
time-sync.target loaded active active System Time Synchronized
timers.target loaded active active Timers
LOAD = Reflects whether the unit definition was properly loaded.
ACTIVE = The high-level unit activation state, i.e. generalization of SUB.
SUB = The low-level unit activation state, values depend on unit type.
17 loaded units listed. Pass --all to see loaded but inactive units, too.
To show all installed unit files use 'systemctl list-unit-files'.10.3.3. Changing the Default Target
root:
systemctl set-default name.targetmulti-user). This command replaces the /etc/systemd/system/default.target file with a symbolic link to /usr/lib/systemd/system/name.target, where name is the name of the target unit you want to use. For information on how to change the current target, see Section 10.3.4, “Changing the Current Target”. For information on how to list all currently loaded target units, see Section 10.3.2, “Viewing the Current Target”.
Example 10.12. Changing the Default Target
multi-user.target unit by default, run the following command as root:
~]# systemctl set-default multi-user.target
rm '/etc/systemd/system/default.target'
ln -s '/usr/lib/systemd/system/multi-user.target' '/etc/systemd/system/default.target'10.3.4. Changing the Current Target
root:
systemctl isolate name.targetmulti-user). This command starts the target unit named name and all dependent units, and immediately stops all others. For information on how to change the default target, see Section 10.3.3, “Changing the Default Target”. For information on how to list all currently loaded target units, see Section 10.3.2, “Viewing the Current Target”.
Example 10.13. Changing the Current Target
multi-user.target unit in the current session, run the following command as root:
~]# systemctl isolate multi-user.target10.3.5. Changing to Rescue Mode
root:
systemctl rescuesystemctl isolate rescue.target, but it also sends an informative message to all users that are currently logged into the system. To prevent systemd from sending this message, run this command with the --no-wall command line option:
systemctl --no-wall rescueExample 10.14. Changing to Rescue Mode
root:
~]# systemctl rescue
Broadcast message from root@localhost on pts/0 (Fri 2013-10-25 18:23:15 CEST):
The system is going down to rescue mode NOW!10.3.6. Changing to Emergency Mode
root:
systemctl emergencysystemctl isolate emergency.target, but it also sends an informative message to all users that are currently logged into the system. To prevent systemd from sending this message, run this command with the --no-wall command line option:
systemctl --no-wall emergencyExample 10.15. Changing to Emergency Mode
root:
~]# systemctl --no-wall emergency
Where did the comment section go?
Red Hat's documentation publication system recently went through an upgrade to enable speedier, more mobile-friendly content. We decided to re-evaluate our commenting platform to ensure that it meets your expectations and serves as an optimal feedback mechanism. During this redesign, we invite your input on providing feedback on Red Hat documentation via the discussion platform.