In Linux, the “run level” defines the operating state of the system when they are booted. It defines services or processes that are initiated first when the computer is turned on. Sometimes, when the computer is turned on, the internet is connected by default because the rules are set in the run level of the operating system.
This post will help the users to understand the “Run Level” in the Linux system.
- What is Run Level in Linux, and How Does it Work?
- What are the States of the Run Level in Linux?
- How to Access the Run-Level Scripts?
- How to Change the Run-Level in Linux?
What is Run Level in Linux, and How Does it Work?
The init script is executed first when the computer is turned on (with the Linux OS installed). This execution will start different processes defined in the init script, whether related to hardware or network.
The kernel will find the run level, and according to the run level, it will execute the defined processes in the script. The different states defined in the init script for booting the operating system are known as the run-level states. There are different run-level states which are explained in the next section.
What are the States of the Run Level in Linux?
There are seven different run-level states which are started from the numeric digit 0 to 6. The functionality of all these seven states is defined in the table below:
|State of Run Level
|In this state, the machine can be turned off safely.
|This state defines that the machine is used by only one user.
|This state defines that multiple users are using the machine, restricting the Network File Sharing.
|This state defines the multiple users who are using the machine, restricting the Graphical User Interface mode.
|This state is user-defined and can be customizable.
|This state allows multiple users to operate the machine without the restriction of the GUI mode.
|This state is used to reboot or restart the machine.
All these states of the run-level are also known as the presets of the computer. If the Linux distribution is a server, it will be in the run-level state of 1,3 or 5 run-level states.
The run-level state of 0 and 6 are used to shut down or restart the computer. States 2 and 4 are user-defined. The “1” specifies the administrator operations.
How to Access the Run-Level Scripts?
There are different init scripts against the run-level. All the scripts are located in the /etc/ directory with the name rc0.d, rc1.d, and so on till rc6.d. To confirm the availability of these scripts, use the “ls” command:
$ ls /etc/
The output shows that the init scripts against the run-level have been displayed in the specified folder.
How to Change the Run-Level in Linux?
We will use the “telinit” command to change the run level in Linux. To display the current preset of the run-level, use the command:
$ who -r
The output shows that the run-level is at 5.
Change Run-Level 5 to 6
To reboot the system after booting, change the existing run level 6 to the 5 run level:
$ sudo telinit 6
The computer will get restarted:
In this way, the run levels have been changed.
Similarly, you can use the systemctl command to change the run-level by following the general syntax:
$ sudo systemctl isolate [run-level-target]
Replace the “run-level-target” with the target name of the preset.
A run level is a state which defines the behavior of initialization of the operating system in Linux. The boot of the OS follows some rules defined in a script named init (initialization), and the process responsible for following the rules is called run level. Users can change the run level upward or downward according to the requirement.
This post has explained the run-level in Linux with its usage and modification in Linux.