• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • VCS
  • Interview Questions
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

CentOS / RHEL 7 : Beginners guide to systemd targets (replacement of SysV init run levels)

by admin

Previous versions of CentOS/RHEL Linux use SysV init run levels. These run levels provided the ability to use systems for different purposes and only start the services needed for a specific purpose, at a specific run level. In RHEL 7, run levels have been replaced with systemd target units. Target units have a .target extension and similar to run levels, target units allow you to start a system with only the services that are required for a specific purpose.

RHEL 7 is distributed with a set of predefined targets that are similar to run levels in previous versions of RedHat Linux. The following command returns the absolute pathname of these predefined systemd run level target units:

# find / -name "runlevel*.target"
/usr/lib/systemd/system/runlevel5.target
/usr/lib/systemd/system/runlevel0.target
/usr/lib/systemd/system/runlevel6.target
/usr/lib/systemd/system/runlevel1.target
/usr/lib/systemd/system/runlevel2.target
/usr/lib/systemd/system/runlevel3.target
/usr/lib/systemd/system/runlevel4.target

Comparision of SysV Run Levels and Target Units

Run Level Target Units Description
0 runlevel0.target, poweroff.target Shut down and power off
1 runlevel1.target, rescue.target Set up a rescue shell
2,3,4 runlevel[234].target, multi- user.target Set up a nongraphical multi-user shell
5 runlevel5.target, graphical.target Set up a graphical multi-user shell
6 runlevel6.target, reboot.target Shut down and reboot the system

Each runlevel[0123456].target file is a symbolic link to the system-start target equivalents. For example:

# cd /usr/lib/systemd/system
# ls -l runlevel*
lrwxrwxrwx. 1 root root 15 Sep 23 19:52 runlevel0.target -> poweroff.target
lrwxrwxrwx. 1 root root 13 Sep 23 19:52 runlevel1.target -> rescue.target
lrwxrwxrwx. 1 root root 17 Sep 23 19:52 runlevel2.target -> multi-user.target
lrwxrwxrwx. 1 root root 17 Sep 23 19:52 runlevel3.target -> multi-user.target
lrwxrwxrwx. 1 root root 17 Sep 23 19:52 runlevel4.target -> multi-user.target
lrwxrwxrwx. 1 root root 16 Sep 23 19:52 runlevel5.target -> graphical.target
lrwxrwxrwx. 1 root root 13 Sep 23 19:52 runlevel6.target -> reboot.target

1. View default/current target unit

Use the following command to view which target unit is used by default:

# systemctl get-default
graphical.target

The graphical.target target unit indicates that the system is running in a graphical, multi- user state. This is similar to run level 5 in a SysV init system. You can verify this using the old command runlevel :

# runlevel
N 5

The default target unit is represented by the /etc/systemd/system/default.target file. This file is a symbolic link to the current default target unit. For example :

# ls -lrt /etc/systemd/system/default.target
lrwxrwxrwx. 1 root root 36 Sep 23 20:01 /etc/systemd/system/default.target -> /lib/systemd/system/graphical.target

2. list the currently active targets

To view the currently active target units on your system use below command.

# 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-online.target  loaded active active Network is Online
network.target         loaded active active Network
nfs-client.target      loaded active active NFS client services
nss-user-lookup.target loaded active active User and Group Name Lookups
paths.target           loaded active active Paths
remote-fs-pre.target   loaded active active Remote File Systems (Pre)
remote-fs.target       loaded active active Remote File Systems
slices.target          loaded active active Slices
sockets.target         loaded active active Sockets
swap.target            loaded active active Swap
sysinit.target         loaded active active System Initialization
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.

19 loaded units listed. Pass --all to see loaded but inactive units, too.
To show all installed unit files use 'systemctl list-unit-files'.

3. Change default target unit

Use the following command to change the default target unit (for example, to change the default to the multi-user.target unit):

# systemctl set-default multi-user.target
Removed symlink /etc/systemd/system/default.target.
Created symlink from /etc/systemd/system/default.target to /usr/lib/systemd/system/multi-user.target.

Notice that the default.target symbolic link has changed, and is now pointing to the multi-user.target unit:

# ls -lrt /etc/systemd/system/default.target
lrwxrwxrwx. 1 root root 41 Sep 24 11:58 /etc/systemd/system/default.target -> /usr/lib/systemd/system/multi-user.target

4. Change currently active system target unit

The set-default command does not change the current state of the system. To change the currently active system target (for example, to change the currently active system target to multi-user.target):

# systemctl isolate multi-user.target

This command is similar to using telinit [runlevel] to change the current run level. This telinit command still exists but is only included for compatibility reasons.

You can also use the following command to enter the default target unit:

# systemctl default

This is equivalent to the following command:

# systemctl isolate default.target
CentOS / RHEL 7 : systemd command line reference (cheat sheet)
CentOS / RHEL 7 : How to change runlevels (targets) with systemd
CentOS / RHEL 7 : Beginners guide to systemd service units
CentOS / RHEL 7 : Beginners guide to systemd

Filed Under: CentOS/RHEL 7, Linux

Some more articles you might also be interested in …

  1. faketime: command not found
  2. debootstrap Command Examples in Linux
  3. How to use netstat command under Linux (Examples included)
  4. How To Check a Disk for Bad Blocks or Disk Errors on CentOS / RHEL
  5. How to Enable Password Aging in Linux with NIS
  6. Linux OS Service ‘o2cb’
  7. e2image: command not found
  8. fprintd-enroll Command Examples in Linux
  9. apt-add-repository: command not found
  10. /etc/rsyslog.conf – Setup a Filter to Discard or Redirect Messages

You May Also Like

Primary Sidebar

Recent Posts

  • nixos-rebuild Command Examples in Linux
  • nixos-option: Command Examples in Linux
  • nixos-container : Command Examples in Linux
  • nitrogen Command Examples in Linux

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright