Systemd Target Units Explained

Systemd manages all services and processes. It uses units to control and manage services and processes. A unit is a collection of configurations and settings a service or process needs to function. A target unit is a collection of units that create a particular work environment, known as a system state. In other words, A system state is a collection of services and processes that provide a specific platform to achieve a particular goal.

Systemd v/s SysVinit

Before RHEL6, RedHat Linux used SysVinit as the services and processes management system. Starting from RHEL7, Systemd is the default services and processes management system. SysVinit defines system states as run levels, whereas Systemd describes them as target units. Both use different terms to represent the same thing. SysVinit organizes system states into seven run levels. Each run level provides a specific functionality. Systemd uses target units to offer the same functionality. It uses symbolic links to provide backward compatibility. It creates a symbolic link for each run level and maps it with the equivalent target unit.

The following command shows the mapping between run levels and target units.

# ls -l /usr/lib/systemd/system/runlevel?.target

run levels and target units

Run levels v/s Target units

The following table lists all run levels and their equivalent target units.

Run level (SysVinit) Description Equivalent Target unit
0 Shut down all services and power off the system poweroff.target
1 Single-user mode for maintenance and recovery. Only the root account can log in. Networking is not available in this mode. rescue.target
2 Multiuser mode without networking. multi-user.target
3 Multiuser mode with networking. All users can log in and access the CLI prompt. No Graphical user interface is available. multi-user.target
4 User-defined mode. Users can customize this run level. Both command line and GUI (graphic user interface) are available for customization. multi-user.target
5 X11 GUI with networking. All users can log in to the GUI interface. graphically.target
6 Shut down all services and reboot the system. reboot.target

To fulfil modern requirements and best utilize available hardware resources, besides the above-listed units, the systemd also provides a lot of service-specific target units. These units inherit all services from other target units and add their own. These service-specific target units are mainly used to deploy a dedicated system. A dedicated system is a system that runs only a few services and makes all resources available to them.

The following command lists all available target units with their status and a brief description.

#systemctl list-units --type=target --all

listing all target units

The following table lists standard target units and their use.

Target unit name Description
halt Shut down all services and halt the system.
poweroff Shut down all services and power off the system.
shutdown Shut down the system usually.
rescue Single-user (root) mode for maintenance and recovery functions. It mounts all file systems but does not start any networking-related service or function.
multi-user Multi-user command line mode for regular tasks. It starts all essential and custom services and provides the CLI prompt for login and work.
graphical Same as the multi-user.target but also includes GUI. A user can use the graphical desktop environment to log in and work or can use a regular command line interface.
reboot Reboot the system normally.
default Default target to boot the system. Usually set either to multi-user.target or graphical.target.
emergency Start an emergency shell and mount only the root file system. Other file systems and networking remain disabled.
hibernate Save the running state to the hard disk and power off the system. When the system is powered on again, the systemd restores the saved state.
suspend Same as the hibernate, except the system state is saved in the memory and power to the memory is not turned off.

This tutorial is part of the tutorial series Systemd service in Linux. Other parts of this series are the following.

Chapter 01  Differences between SysVinit, Upstart and Systemd
Chapter 02  Systemd Units Explained with Types and States
Chapter 03  Systemd Unit Configuration Files Explained
Chapter 05  How to use the systemctl command to manage Systemd services

Switching between different targets

To switch the system into another target or change the current target into another one, use the following command.

#systemctl isolate [target]

For example, the following command switches the system into the multi-user.target.

#systemctl isolate multiuser.target

Use the following command to switch back to the graphical target.

# systemctl isolate graphical.target

Viewing and changing the default boot target

To view the default boot target, use the following command.

#systemctl get-default

To change the default boot target, use the following command.

#systemctl set-default [target]

For example, the following command changes the current default boot target to multi-user.target.

#systemctl set-default multiuser.target

viewing and setting default target units

Conclusion

Systemd target units define system states. A system state is a specific working environment. The systemctl command allows to us change the system state. You can customize the Linux system by understanding target units per your requirements and flexibility.

ComputerNetworkingNotes Linux Tutorials Systemd Target Units Explained

We do not accept any kind of Guest Post. Except Guest post submission, for any other query (such as adverting opportunity, product advertisement, feedback, suggestion, error reporting and technical issue) or simply just say to hello mail us ComputerNetworkingNotes@gmail.com