Chapter 14. Working with systemd targets

systemd targets are represented by target units. Target units file ends with the .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.

This section includes procedures to implement while working with systemd targets.

14.1. Difference between SysV runlevels and systemd targets

The previous versions of Red Hat Enterprise Linux were distributed with SysV init or Upstart, and implemented a predefined set of runlevels that represented specific modes of operation. These runlevels were numbered from 0 to 6 and were defined by a selection of system services to be run when a particular runlevel was enabled by the system administrator. Starting with Red Hat Enterprise Linux 7, the concept of runlevels has been replaced with systemd targets.

Red Hat Enterprise Linux 7 was distributed with a number of predefined targets that are more or less similar to the standard set of runlevels from the previous releases. For compatibility reasons, it also provides aliases for these targets that directly maps to the SysV runlevels.

The following table provides a complete list of SysV runlevels and their corresponding systemd targets:

Table 14.1. Comparison of SysV runlevels with systemd targets

RunlevelTarget UnitsDescription

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.

The following table compares the SysV init commands with systemctl. Use the systemctl utility to view, change, or configure systemd targets:

Important

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 14.2. Comparison of SysV init commands with systemctl

Old CommandNew CommandDescription

runlevel

systemctl list-units --type target

Lists currently loaded target units.

telinit runlevel

systemctl isolate name.target

Changes the current target.

Additional resources

  • man sysv init
  • man upstart init
  • man systemctl

14.2. Viewing the default target

The default target unit is represented by the /etc/systemd/system/default.target file.

Procedure

  • To determine which target unit is used by default:

    $ systemctl get-default
    graphical.target
  • To determine the default target using the symbolic link:

    $  ls -l /usr/lib/systemd/system/default.target

    = Viewing the target units

By default, the systemctl list-units command displays only active units.

Procedure

  • To list all loaded units regardless of their state:

    $ systemctl list-units --type target --all
  • To list all currently loaded target units:

    $ 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.

14.2.1. Changing the default target

The default target unit is represented by the /etc/systemd/system/default.target file. The following procedure describes how to change the default target by using the systemctl command:

Procedure

  1. To determine the default target unit:

    # systemctl get-default
  2. To configure the system to use a different target unit by default:

    # 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

    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. Replace multi-user with the name of the target unit you want to use by default.

  3. Reboot

    # reboot