Linux runlevels are handled a little bit different in CentOS 7 and RHEL 7 (also recent versions of Fedora, etc..) since the move to systemd. We no longer have the /etc/inittab file to change our runlevel at boot, nor does the init command work like it did in systemV.
Below is a table that maps SysV runlevels to systemd.
To check the current runlevel or target, you can still use the runlevel command as it was left intact for backward compatibility:
$ runlevel
N 5
I prefer to use the new systemd commands as this allows me to get out of old habits, and get used to using systemd. So to check runlevel in systemd, we should use the systemctl command.
$ systemctl get-default
graphical.target
Any system using systemd now uses the systemctl command to set the “target” which we used to call the runlevel. In RHEL 7 / CentOS 7 instead of specifying runlevels, we specify targets as previously mentioned since they now use systemd.
We can list all currently loaded targets using the systemctl command.
$ systemctl list-units -t 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
nfs.target loaded active active Network File System
...OUTPUT TRUNCATED...
From the output above, we can see that we are at what we used to call runlevel 5, the graphical multi-user targets are both loaded.
graphical.target loaded active active Graphical Interface
multi-user.target loaded active active Multi-User System
We can view all available targets by issuing the following command:
$ systemctl list-units -t target -a
UNIT LOAD ACTIVE SUB DESCRIPTION
basic.target loaded active active Basic System
cryptsetup.target loaded active active Encrypted Volumes
dbus.target not-found inactive dead dbus.target
emergency.target loaded inactive dead Emergency Mode
final.target loaded inactive dead Final Step
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 inactive dead Network is Online
network.target loaded active active Network
...OUTPUT TRUNCATED...
We can drop down to runlevel 3 (multi-user non-graphical) by isolating the multi-user target.
# systemctl isolate multi-user.target
To switch to runlevel 3 permanently, even after a reboot, we have to change the default target. Here we change the default target to multi-user.target or runlevel 3. Systemd uses symbolic links to point to the default target.
We can use systemctl to set the default target, like so:
# systemctl set-default multi-user.target
This can also be done manually. We can delete the current symlink (or default) then create a new one pointing default.target to multi-user.target.
# rm /etc/systemd/system/default.target
# ln -sf /lib/systemd/system/multi-user.target /etc/systemd/system/default.target
Now when we reboot, the system will boot into our new default target which is multi-user.target, or what we used to call runlevel 3.
Red Hat 7, and CentOS also offer symlinks named after the runlevels. They are located in /usr/lib/systemd/system. For example, if you wanted to set the default target to graphical (runlevel 5) you can do:
rm /etc/systemd/system/default.target
ln -sf /lib/systemd/system/runlevel5.target /etc/systemd/system/default.target
Here is a list of runlevel symlinks you can use:
$ ls -l /usr/lib/systemd/system | grep runlevel
lrwxrwxrwx. 1 root root 15 Jan 19 23:50 runlevel0.target -> poweroff.target
lrwxrwxrwx. 1 root root 13 Jan 19 23:50 runlevel1.target -> rescue.target
drwxr-xr-x. 2 root root 4096 Jan 19 23:50 runlevel1.target.wants
lrwxrwxrwx. 1 root root 17 Jan 19 23:50 runlevel2.target -> multi-user.target
drwxr-xr-x. 2 root root 4096 Jan 19 23:50 runlevel2.target.wants
lrwxrwxrwx. 1 root root 17 Jan 19 23:50 runlevel3.target -> multi-user.target
drwxr-xr-x. 2 root root 4096 Jan 19 23:50 runlevel3.target.wants
lrwxrwxrwx. 1 root root 17 Jan 19 23:50 runlevel4.target -> multi-user.target
drwxr-xr-x. 2 root root 4096 Jan 19 23:50 runlevel4.target.wants
lrwxrwxrwx. 1 root root 16 Jan 19 23:50 runlevel5.target -> graphical.target
drwxr-xr-x. 2 root root 4096 Jan 19 23:50 runlevel5.target.wants
lrwxrwxrwx. 1 root root 13 Jan 19 23:50 runlevel6.target -> reboot.target
-rw-r--r--. 1 root root 761 Jun 10 2014 systemd-update-utmp-runlevel.service
Join Our Newsletter
Categories
- Bash Scripting (17)
- Basic Commands (50)
- Featured (7)
- Just for Fun (5)
- Linux Quick Tips (98)
- Linux Tutorials (65)
- Miscellaneous (15)
- Network Tools (6)
- Reviews (2)
- Security (32)