Learn how Linux runlevels manage system operating states, from booting to GUI and CLI options, and how they help manage Linux systems efficiently.
In Linux, “runlevels” handle the system’s operating state. It is such that Linux boots to GUI and CLI options when the system turns on. After the booting is done, the applications it runs are analyzed via the run levels. These play a key role in managing the Linux systems and their behavior at specific points.
The run levels are assigned to each task in Linux and range from “0” to “6” with each runlevel having a dedicated task. These analyze which programs to run after the OS boots. These come in handy when giving access to various processes and resolving issues.
Table of Contents
Significance of Runlevels
Linux systems depend on run levels to analyze, starting and stopping services, checking network status, and resolving various issues by switching between run levels. They also decide which programs to execute during OS runtime.
Types of Runlevels in Linux
There are the following seven different types of run levels in Linux each assigned for a dedicated objective:
Runlevel 0:
It is mainly used for troubleshooting and shutting down the system.
Runlevel 1:
It is also known as a single-user mode that initiates daemons.
Runlevel 2:
It corresponds to a multi-user mode lacking a networking/network file system.
Runlevel 3:
This is also a multi-user mode with networking under CLI that starts the system in a normal behavior.
Runlevel 4:
It is a user-defined mode.
Runlevel 5:
This level represents a multi-user mode with networking under GUI.
Runlevel 6:
It is a reboot utilized to restart the system.
Checking the Linux Runlevels:
You can use the who
command or runlevel
command to check the current runlevel, usually set to “5,” the default in Linux systems.
who -r
Output:

runlevel
Output:

The above executed commands signify that the runlevel is set to “5” which is usually the default level in Linux systems.
What are “init” Scripts and Where are the Runlevels Located?
The “init” refers to a program that launches other processes while the system boots. These are located at the “/etc/init.d/” path and can be viewed using the below cmdlet:
ls /etc/init.d/
Output:

The runlevels, however, are located at the “/etc/ directory” path and can be listed as follows:
ls /etc/ | grep rc
Output:

Relationship Between System Booting and Default Runlevel in Linux
When a system boots, the “init” process initiates. In order to run the start scripts suitable for the default run level, the init process first analyzes the default run level of the system. Based on this decision, the hardware is initialized and the GUI is started. You can get in-depth knowledge about about boot process through blog Linux Boot Process Unveiled -A Comprehensive Guide to Understand.
How to Set the Default Runlevel for Linux?
The “systemctl” cmdlet is used to set the default runlevel in Linux. For instance, to set the default runlevel to “5”, apply the below command:
sudo systemctl set-default graphical.target
In this command, “graphical.target” is the multi-user mode with graphics i.e., GUI that represents the particular runlevel i.e., 5.
Now, to configure the default runlevel as a multi-user mode without GUI, use the below command:
sudo systemctl set-default multi-user.target
How to Change/Switch the Linux Run Levels?
The “init” or the “telinit” cmdlets are used to change the run levels in Linux. It is important to note that the runlevels are the same across the Linux distributions but their implementation can vary.
Note: The users can edit/modify the current or default runlevels but it should be done if one has extensive knowledge of Linux administration.
For instance, for changing the system to runlevel “2”, execute the below cmdlet:
sudo init 2
Likewise, the same command can also be used with the latter “telinit” command:
sudo telinit 2
Runlevel Important Commands
Below are some useful run level commands.
Use either of the below commands to suppress the output:
runlevel -r
Or
runlevel - quiet
For executing in verbose mode,
runlevel -v
runlevel --verbose
Only use the runlevel(s) required at the moment. For instance, there is no need to start the runlevel 5 i.e., GUI when only the terminal is to be used.
FAQs about Linux runlevels:
Which Runlevel is Most Suitable for Most Users?
The suitability of a runlevel varies from user to user and the system. For instance, the runlevel 3 is a best suit for production and servers. Likewise, the runlevel 5 works best for a desktop.
Can a Custom Runlevel be Created?
Yes, a custom runlevel can be created by specifying the required services and the processes in that specific runlevel. However, it is not recommended for the noob users as it requires extensive knowledge of the Linux System Administration.
What is the Difference Between the Runlevels 3 and 5?
The runlevels 3 and 5 both support networking multi-user mode. However, the core difference between the two is that the runlevel 5 contains the GUI whereas it is not contained in the runlevel 3.
Is there any Advantage of Running Multiple Runlevels Simultaneously?
Executing multiple runlevels can be helpful in implementing GUI application and testing in the same environment, thereby minimizing the server load.
Can the Runlevels Be Switched Without System Reboot?
Yes, it is possible by applying the “init” command followed by the target runlevel:
sudo init 5
Here, “5” represents the runlevel to switch to.
Which Runlevel is Used For Maintenance?
The runlevel 1(also referred to as a single user mode) is used for repairing and maintaining the system which only starts the crucial services.
Conclusion
The run levels are used to define various operational states in a Linux system. There are 7 different runlevels that indicate dedicated processes that start or halt when the system enters or switches to that particular runlevel. In a nutshell, runlevels allow the users to control and fix the system abnormal behaviors.