How do I change run level (targets) within Systemd?
Many Linux like operating systems, such as CentOS 7, RHEL 7, Ubuntu 16, Fedora has started using the systemd instead of init. The systemd is a new init system for Linux. It is common for most of the Linux users to change the run levels for booting into either text mode or GUI mode. Earlier run levels were changed through /etc/inittab but Now any Linux like operating system that uses systemd (system management daemon) will need to use a command “systemctl” to change run level. In this article, I will explain you how to change run level in Linux.
Relationship between runlevels and targets.
Run level 0 = poweroff.target Run level 1, s = rescue.target Run level 2, 3, 4 = multi-user.target Run level 5 = graphical.target Run level 6 = reboot.target Emergency mode = emergency.target
How to check current runlevel (Target) in Linux
We can view the current run level by using runlevel command
[[email protected] ~]# runlevel N 5
In this example, our system is running runlevel 5 which is graphical.target
View run level in systemd
[[email protected] ~]# systemctl get-default graphical.target
How to Change the target (runlevel) in Systemd?
To switch to run level 2, 3, 4 (multi-user) run the following command.
# systemctl isolate multi-user.target
To switch to GUI mode run level 5 type the following command
# systemctl isolate graphical.target
To view all the targets which are available you use the following command.
[[email protected] ~]# systemctl list-units --type target
How to Change the run level in init?
Use the following command to change your run level in Linux system using init
# init 5
This command will change your run level to “GUI” mode.
Change the default run level (Target) in Systemd
In systemd the default runlevel (target) can be changed by using the systemctl command with set-default as an option.
This command will change your default run-level to GUI mode
[[email protected] ~]# systemctl set-default graphical.target Removed symlink /etc/systemd/system/default.target. Created symlink from /etc/systemd/system/default.target to /usr/lib/systemd/system/graphical.target.
To change your default run-level to Text mode, use the following command
[[email protected] ~]# 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.
Change the default run level (Target) in init
For Linux systems using init default run level can be changed by editing the file /etc/inittab file and change the entry initdefault:
# vim /etc/inittab Change id to 5 id:5:initdefault:
This will change your default run level to the graphical interface.
In this article, I have shown you how to change run levels (targets) with the systemd or with init in Linux systems. Changing Linux run level is common for every system administrator and Linux user. By learning these commands you can easily switch runlevels in your Linux system.
If you have any questions? Leave a comment below, or you can contact me using the contact us page.