Quidest?

Systemd Targets

ยท Lorenzo Drumond

Systemd manages all services and processes in Linux. To control and manage services and processes, it uses units. A unit represents and manages an individual service or process. A target-unit is the logical collection of other system units.

System State

A system state is an environment in which all the required services and processes run to build and provide the necessary functionality.

To define various system states, systemd uses keywords, known as target-units.

target-units organize functionalities. In old init systems, functionality were organized in run-levels. To guarantee backward compatibility, systemd uses symbolic links for each run-level and maps it with the equivalent target-unit.

Run-levels vs Target-units

Here’s a description of the seven run-levels with equivalent target-units:

Run-levelDescriptiontarget-unit
0Shutdown all services and power off the systempoweroff.target
1single user mode for maintenance and recoveryrescue.target
2multiuser mode w/o networkingmulti-user.target
3multiuser mode with networkingmulti-user.target
4user defined mode. Users can customized this run-level.multi-user.target
5X11 GUI with networking.graphical.target
6Shutdown all services and rebootreboot.target

Systemd also provides more service-specific target-units, which inherit all services from other target-units and add their own to them.

Here’s a list of most commonly used target-units

Target-unitDescription
haltShut down all services and halt the system
poweroffshut down all services and power off system
shutdownshut down the system normally
rescuesingle-user (root) mode for maintenance. No networking
multi-usermulti-user command line mode for regular tasks. Starts all essential and custom services and provides the CLI prompt for login and work
graphicalsame as multi-user.target but also includes GUI.
rebootreboot the system normally
defaultdefault target to boot the system. Usually set either to multi-user.target or graphical.target
emergencystart an emergency shell and mount only root fs.
hibernatesave the running state of the system to hard disk and power off the system. When powered on again, the system restores saved state
suspendsame as hibernate.target except the system state is save in memory and power to memory is not turned off.

To view the list of all available target-units with their status, run

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

Switching between different targets

To switch the system into another target or change the current target, use

systemctl isolate [target]

Viewing and changing the default boot target

To view the default boot target, use

systemctl get-default

To change the default boot target, use

systemctl set-default [target]

References

#boot #linux #process #init #targets #introduction #systemctl #systemd