Since CentOS 7 / RHEL 7, system run levels are replaced with targets and are managed by systemd. Systemd targets are represented by target units and their configuration files end with .target extension.
This systemd target unit file contains other systemd units through a chain of dependencies. For example, the graphical.target which provides graphical console starts GNOME service (gdm.service) and activates the multi-user.target unit.
In this guide, we will see how to change the current/default runlevel in CentOS 8 / RHEL 8.
Available Targets / Runlevels
Contents
CentOS 8 / RHEL 8 comes with a number of predefined targets that are more or less similar to the standard set of runlevels found in CentOS 6 / RHEL 6.
Runlevel | Target Units | Description |
---|---|---|
0 | runlevel0.target / poweroff.target | Power off the system. |
1 | runlevel1.target / rescue.target | Single User mode |
2 | runlevel2.target / multi-user.target | multi-user mode. |
3 | runlevel3.target / multi-user.target | multi-user mode. |
4 | runlevel4.target / multi-user.target | multi-user mode. |
5 | runlevel5.target / graphical.target | Graphical mode. |
6 | runlevel6.target / reboot.target | Reboot the system. |
Change Default Runlevel
The default runlevel can be set either by using the systemctl command or making a symbolic link of runlevel targets to the default.target file.
1. Using systemctl Command
2. Making Symbolic link of runlevel targets
Using systemctl Command
Let’s check the current run level by running the following command.
systemctl get-default
Output:
graphical.target
The above output confirms that the system’s current default runlevel is graphical.target (runlevel 5).
To change the default runlevel to runlevel 3 (nothing but a multi-user.target), use the below command.
systemctl set-default multi-user.target
Reboot and check it out.
reboot
Verify that the default runlevel is runlevel 3 (multi-user.target) post the reboot.
systemctl get-default
Output:
multi-user.target
Making Symbolic Link of target
Check the current runlevel.
systemctl get-default
Output:
multi-user.target
The above output confirms that the system’s current default runlevel is multi-user.target (runlevel 3).
Before making the symbolic link, let’s list out the runlevel files in the systemd directory.
ls /lib/systemd/system/runlevel*target -l
At this time, the default runlevel is multi-user.target (runlevel 3). Issue the following command to make a symbolic link of runlevel5.target to the default.target file.
ln -sf /lib/systemd/system/runlevel5.target /etc/systemd/system/default.target
or
ln -sf /lib/systemd/system/graphical.target /etc/systemd/system/default.target
Reboot the server and check it out.
reboot
Verify that the default runlevel is runlevel 5 (graphical.target) post the reboot.
systemctl get-default
Output:
graphical.target
Change Current Runlevel
You can switch the current runlevel with the systemctl isolate <name.target> command in the session. To invoke multi-user.target / graphical.target, use the below command.
systemctl isolate graphical.target OR systemctl isolate multi-user.target
Conclusion
That’s All. I hope this post helped you to change the current/default runlevel in CentOS 8 / RHEL 8. Please share your feedback in the comments section.