What is the command to know the current system runlevel in Linux?

What is the command to know the current system runlevel in Linux?
What is the command to know the current system runlevel in Linux?
This example shows the correct ways to check run level on unix or linux server. The runlevel is a software configuration of the system which allows only a selected group of processes to exist. The processes spawned by init command/process for each of these runlevels are defined in the /etc/inittab file. Usually runlevel 0, 1 and 6 are the same and reserved for the following purposes :

0 – halt
1 – single mode
6 – reboot

Meanwhile runlevel 2,3,4 and 5 used for the following :

2 – Multi-User Mode
3 – Multi-User Mode with Networking
4 – Not used/User-definable
5 – Start the system normally with appropriate display manager. ( with GUI )

See also  How to backup MySQL database using PHPMyAdmin

1. Check and display runlevel using “who” command :

[root@centos62 ~]# who -r
         run-level 3  2012-07-07 09:58

2. Check and display current and previous system runlevel using “runlevel” command :

[root@centos62 ~]# runlevel
N 3

How to Switching or Changing Between Different Runlevels on Linux

You can boot through the GUI. There are multiple states in the runlevel, which are defined according to the current state of the system. Read this guide thoroughly if you also want to know about the runlevel and its states. This guide has all the information you need about the runlevel in Linux.

What is Runlevel in Linux?

Runlevel is a different mode used for the various tasks in Linux. There are seven types of runlevel which are numbered from zero to six. In Linux, runlevels zero, one, and six serve a specific purpose. But in runlevels two, three, and four runlevel, you can do any purpose decided by the distribution provider. The /etc/inittab file determines the system’s runlevel. You can manually switch from one runlevel to another as an admin.

There are some main reasons for defining the runlevel, such as:

  • Determining how the system is set up at boot, such as whether a GUI is available.
  • Describing the application or program that the system will need to execute upon booting.

Switching Between Runlevels

Before changing the runlevel, you should know your current runlevel state. Run the following command in the terminal:

$ runlevel

What is the command to know the current system runlevel in Linux?

According to the following output, the first number represents the previous runlevel that ran in your system. The second number represents its current runlevel. Here, “N” means that your system was not previously at a different runlevel. And “5” means that your system’s current runlevel is 5.

With the -r option, you can also find the runlevel with the who command:

$ who -r

What is the command to know the current system runlevel in Linux?

We always recommend that you get the information about the parameters before using the runlevel. You can get help at the runlevel by running the following commands:

$ runlevel --h

Or

$ runlevel --help

What is the command to know the current system runlevel in Linux?

To go to the man pages of the runlevel execute the following command:

man runlevel

What is the command to know the current system runlevel in Linux?

Each runlevel has its distinct function. The runlevels differ according to the operating systems, which range from zero to six. We recommend that you refer to the following table and understand the numbers used to define the runlevel:

RunlevelTargetDescription0poweroff.targetNothing runs at this runlevel. It is only used for shutting down the system.1rescue.targetIn the recovery mode, this runlevel is used. It is a single-user mode, so only the root can access it. It simply does not configure the network interface, and users can define it as the non-root users.2multi-user.targetIt runs in the multi-user mode but does not initiate network or daemon interfaces.3.Provides multi-user functionality without GUI. Here, just one CLI is used.4Usually, this runlevel is not used, and it is undefined. Users can specify it.5graphical.targetIn most Linux systems, this runlevel is used. It runs the system in multi-user mode with a graphical user interface.6reboot.targetAs soon as the runlevel command is executed, the system is rebooted.

Runlevel Files Location

Each runlevel has its directory located inside the /etc directory. Each runlevel has its specific environment executed through one particular set of scripts. Now, we will see where these scripts are stored.

Many configuration files and subdirectories are included in the /etc directory. Runlevel files are organized into these directories in rc0.d to rc6.d formation.

Each subdirectory is designed for a specific runlevel that holds the configuration files. The following command displays the subdirectories:

ls /etc

What is the command to know the current system runlevel in Linux?

A list of processes that run at each runlevel is also available. For example, we ‌see that runlevel 4 lists all the running processes. Let’s look at the files in the /etc/rc4.d subdirectory used for runlevel 4:

ls /etc/rc4.d/

What is the command to know the current system runlevel in Linux?

Changing the Runlevel

You can change the runlevel either from init or telinit command. Here are the following commands:

init <runlevel_value>

telinit <runlevel_value>

In the previous commands, change the with the runlevel you want to change. Both the init and telinit commands give the same output. Running both the previous commands in the terminal will restart your system quickly.

The systemctl command helps to find and change the current runlevel. First, run the following command to determine your runlevel:

systemctl get-default

What is the command to know the current system runlevel in Linux?

Running the previous command displays the “graphical.target” as an output. Once the present runlevel is detected, we change the runlevel through the following command using the systemctl command:

sudo systemctl isolate multi-user.target

After typing the command, press the Enter button. You will be redirected to the new window where you have to provide your system credentials. Once successful authentication is done, you are on the command line.

What is the command to know the current system runlevel in Linux?

Once again, execute the runlevel command to check the current state of the runlevel.

What is the command to know the current system runlevel in Linux?

Two types of runlevels are displayed in the output on getting the command run. There was a runlevel 5 used previously, and there is a runlevel 3 used now.

bTo go back to the GUI, execute the following command:

srudo systemctl isolate graphical.target

What is the command to know the current system runlevel in Linux?

After a successful authentication, you return to GUI mode.

What is the command to know the current system runlevel in Linux?

Conclusion

We have thoroughly explained the Linux Runlevel in this article. There are different ways to check the runlevel, but we only described one method so you can understand it well. If you want to know more related topics in this article or have questions in your mind, you can share your opinion in the comment box.

Which command displays the system's current run level?

Use the runlevel command /sbin/runlevel to find the current and previous runlevel of an operating system. Runlevels zero through six are generally delegated to single-user mode, multi-user mode with and without network services started, system shutdown and system reboot.

Which command configures the current runlevel?

To configure a different runlevel, specify one or more runlevels with the --level option. For example, the command ntsysv --level 345 configures runlevels 3, 4, and 5.

What is the default run level in Linux?

The default run level is specified in the /etc/inittab file as run level 3. To shut down the operating system so that it is safe to turn off power to the system. To run as a single user with all file systems mounted and accessible. To access all available file systems with user logins allowed.