What is a systemd Target
In SysVinit systems, you had a defined but configurable set of runlevels numbered from 0 to 6. A runlevel is essentially a set of capabilities or running services that you can predefine and set the system to boot to so you have a predictable set of services.
In systemd, targets are the new runlevels. For example, the default.target file is typically a symbolic link to another target file such as the graphical.target file. Targets directly correspond to the SysVinit runlevels in that you can match them up as shown below:
|Runlevel||Target File||What it does?|
|0||poweroff.target||Shuts down and power offs the system|
|1||rescue.traget||Configures a rescue shell session|
|2||multi-user.target||Sets the system to non-graphical multi-user system, typically with no network services|
|3||multi-user.target||Sets the system to non-graphical multi-user system with network services|
|4||multi-user.target||Sets the system to non-graphical multi-user system with network services|
|5||graphical.target||Sets the system to graphical multi-user system with network services|
|6||reboot.target||Shuts down and boots the system again|
Selecting a systemd Target
A systemd target is a set of systemd units that should be started to reach a desired state. Important targets are listed in the following table.
|graphical.target||System supports multiple users, graphical and text-based logins.|
|multi-user.target||System supports multiple users, text-based logins only|
|rescue.target||sulogin prompt, basic system initialization completed|
|emergency.targe||sulogin prompt, initramfs pivot complete and system root mounted on / read-only.|
It is possible for a target to be a part of another target; for example, the graphical.target includes multi-user.target, which in turn depends on basic.target and others. These dependencies can be viewed from the command line with the following command:
# systemctl list-dependencies graphical.target | grep target
An overview of all available targets can be viewed with:
# systemctl list-units --type=target --all
An overview of all targets installed on disk can be viewed with:
# systemctl list-unit-files --type=target
Selecting a target at runtime
On a running system, administrators can choose to switch to a different target using the systemctl isolate command; for example, systemctl isolate multi-user.target.
Setting a default target
When the system starts, and control is passed over to systemd from the initramfs, systemd will try to activate the default.target target. Normally the default.target target will be a symbolic link (in /etc/systemd/system/) to either graphical.target or multiuser.target.
The systemctl tool provides two commands to manage the link: get-default and setdefault.
# systemctl get-default multi-user.target
# systemctl set-default graphical.target rm '/etc/systemd/system/default.target' ln -s '/usr/lib/systemd/system/graphical.target' '/etc/systemd/system/default.target'
# systemctl get-default graphical.target
Selecting a different target at boot time
To select a different target at boot time, a special option can be appended to the kernel command line from the boot loader: systemd.unit=. For example, to boot the system into a rescue shell, pass the following option at the interactive boot loader menu:
To use this method of selecting a different target, use the following procedure for Red Hat Enterprise Linux 7 systems:
- (Re)boot the system.
- Interrupt the boot loader menu countdown by pressing any key.
- Move the cursor to the entry to be started.
- Press e to edit the current entry.
- Move the cursor to the line that starts with linux16. This is the kernel command line.
- Append systemd.unit=desired.target.
- Press Ctrl+x to boot with these changes.