CentOS 7 / RHEL 7: Change System Runlevel
In CentOS 7 or RHEL 7 operating system, you probably want to change the runlevle of your system, then How To check the current run levle? How do I change the run level of system ? how to check the current run level of system under CentOS 7 linux system or RHEL 7 linux system? this post will guide you to change or set the system runlevel.
CentOS 7 / RHEL 7 Check The Current Runlevel
You still can use “runlevel” command to check the current level, also can use another two commands.
systemctl get-default"
Or
ll /etc/systemd/system/default.target
Output:
[root@osetc Desktop]# systemctl get-default graphical.target [root@osetc Desktop]# ll /etc/systemd/system/default.target lrwxrwxrwx. 1 root root 36 Nov 27 09:31 /etc/systemd/system/default.target -> /lib/systemd/system/graphical.target
CentOS 7 / RHEL 7 Supported Runlevel
Using the followding command to get out the available runlevel, type:
systemctl list-units --type=target
Output:
[root@osetc Desktop]# 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 nfs.target loaded active active Network File System Server paths.target loaded active active Paths printer.target loaded active active Printer remote-fs.target loaded active active Remote File Systems slices.target loaded active active Slices sockets.target loaded active active Sockets sound.target loaded active active Sound Card 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. 18 loaded units listed. Pass --all to see loaded but inactive units, too. To show all installed unit files use 'systemctl list-unit-files'.
Or you can use “ll -l /lib/systemd/system/runlevel*.target” to get the runlevel that CentOS 7 system support.
[root@osetc Desktop]# ls -l /lib/systemd/system/runlevel*.target lrwxrwxrwx. 1 root root 15 Nov 27 09:18 /lib/systemd/system/runlevel0.target -> poweroff.target lrwxrwxrwx. 1 root root 13 Nov 27 09:18 /lib/systemd/system/runlevel1.target -> rescue.target lrwxrwxrwx. 1 root root 17 Nov 27 09:18 /lib/systemd/system/runlevel2.target -> multi-user.target lrwxrwxrwx. 1 root root 17 Nov 27 09:18 /lib/systemd/system/runlevel3.target -> multi-user.target lrwxrwxrwx. 1 root root 17 Nov 27 09:18 /lib/systemd/system/runlevel4.target -> multi-user.target lrwxrwxrwx. 1 root root 16 Nov 27 09:18 /lib/systemd/system/runlevel5.target -> graphical.target lrwxrwxrwx. 1 root root 13 Nov 27 09:18 /lib/systemd/system/runlevel6.target -> reboot.target
CentOS 7 / RHEL 7 Set Default Runlevel
you need to edit the “/etc/inittab” file to set the defatult runlevel in Centos 6.x system, but now the inittab file is no longer used in centos 7 system, and systemd uses “targets” instead of runlevels, there are two main targets: multi-user.target (runlevel 3) and graphical.target( runlevel 5), to set a defalut target or default runlevel, run the following command:
ln -sf /lib/systemd/system/<target name>.target /etc/systemd/system/default.target
Example: set default runlevel to multi-user.target, issue the following command:
ln -sf /lib/systemd/system/multi-user.target /etc/systemd/system/default.target
This way will create symbolic link of runlevel targets to default target file.
Or you can use a systemctl command to set default runlevel, type:
systemctl set-default multi-user.target
you must reboot the system, type:
reboot
CentOS 7 / RHEL 7 Switch Current Runlevel
If you wanna to switch the current runlevel to another, and also do not want to reboot the system, such as, switching the mult-user.target level to graphical.target level immediately, issue the following command:
systemctl isolate graphical.target
OR
systemctl isolate runlevel5.target
Also switching to multi-user.target level, using following command:
systemctl isolate mult-user.target
OR
systemctl isolate runlevel3.target