What is runlevels in linux

Run Levels in Linux

A run level is a state of init and the whole system defines what system services are operating. Run levels are identified by numbers. Runlevel is a mode or state in which a Linux system operates. It has a crucial role in the management of the Linux System.

  • Whenever a LINUX system boot, firstly the init process is started which is actually responsible for running other start scripts which mainly involves initialization of your hardware, bringing up the network, and starting the graphical interface.
  • Now, the init first finds the default runlevel of the system so that it can run the start scripts corresponding to the default run level.
  • A runlevel can simply be thought of as the state your system enters like if a system is in a single-user mode it will have a runlevel 1 while if the system is in a multi-user mode, it will have a runlevel 5.
  • A runlevel, in other words, can be defined as a preset single-digit integer for defining the operating state of your LINUX or UNIX-based operating system. Each runlevel designates a different system configuration and allows access to different combinations of processes.

The important thing to note here is that there are differences in the runlevels according to the operating system. The standard LINUX kernel supports these seven different runlevels :

Runlevel Description
0 System halt i.e., the system can be safely powered off with no activity.
1 Single user mode.
2 Multiple user mode with no NFS (network file system).
3 Multiple user modes under the command line interface and not under the graphical user interface.
4 User-definable.
5 Multiple user mode under GUI (graphical user interface) and this is the standard runlevel for most of the LINUX-based systems.
6 Reboot which is used to restart the system.

How to check Runlevel of our Linux system

We will discuss two easy ways to check runlevel in our linux system.

1) Using `runlevel` command

This command will show what runlevel we are.

2) Using `who` command

By default, most of the LINUX-based system boots to runlevel 3 or runlevel 5. In addition to the standard runlevels, users can modify the preset runlevels or even create new ones according to the requirement. Runlevels 2 and 4 are used for user-defined runlevels and runlevel 0 and 6 are used for halting and rebooting the system. Obviously, the start scripts for each run level will be different performing different tasks. These start scripts corresponding to each run level can be found in special files present under rc subdirectories. At /etc/rc.d directory there will be either a set of files named rc.0, rc.1, rc.2, rc.3, rc.4, rc.5, and rc.6, or a set of directories named rc0.d, rc1.d, rc2.d, rc3.d, rc4.d, rc5.d, and rc6.d. For example, run level 1 will have its start script either in file /etc/rc.d/rc.1 or any files in the directory /etc/rc.d/rc1.d.

Читайте также:  Where are linux driver

How to Change the Runlevel in Linux

init is the program responsible for altering the run level which can be called using the telinit command.

For example: To change the system to runlevel 3, you would use the following command:

This command will stop all non-essential services and processes and start all essential services and processes required for a basic system operation, including networking services.

For example: To change a runlevel from 3 to runlevel 5 which will actually allow the GUI to be started in multi-user mode the telinit command can be used as:

To set the default runlevel for your Linux system

Before in older version of Linux we used to modify the file “/etc/inittab” but in modern versions of Linux such as RHEL 9 and Ubuntu (starting from Ubuntu 15.04) use systemd as the init system instead of the traditional System V init. Therefore, the /etc/inittab file is no longer used.

Now we use `systemctl` command to ser default value of runlevel.

For Example: If we want to make our default runlevel 5 (Which is used as the graphical multi-user mode with networking), we can use the following command.

sudo systemctl set-default graphical.target

For Example: If we want to make our default runlevel (Which is used as the multi-user mode without a graphical interface), we can use the following command.

sudo systemctl set-default multi-user. Target

Frequently Asked Question

Can I create my own custom runlevel in Linux?

Yes, it is possible to create our own custom runlevel by defining the necessary services and processes to be started or stopped in that runlevel but to do so user should have Indepth and advanced knowledge in Linux System Administration.

What is the difference between runlevel 3 and runlevel 5?

Runlevel 5 and 3 are similar in functionality but the key difference is that runlevel 5 supports the graphical user interface (GUI) login prompt whereas runlevel 3 does not have graphical user interface (GUI) but both have multi-user mode with networking, where all essential services and processes required for a basic system operation, including networking services, are started.

What is the purpose of the single-user mode or maintenance mode (Runlevel 1)?

Runlevel 1 is also known as single-user mode or maintenance mode which is used for system maintance and repair. In this mode all other services and processes are stopped, only essential services and processes are started.

Can I switch between runlevels without rebooting the system?

Yes, we can do that by using `init` command with the appropriate runlevel number.

For Example: If we want to change to runlevel 3

Conclusion

In this article we have discussed ways to change or runlevel of our linux system. We have discussed two ways, runtime and Default changing. We have also discussed that Linux systems typically have seven runlevels, ranging from 0 to 6, and each runlevel corresponds to a specific set of services and processes that are started or stopped when the system enters that runlevel. Overall, by understanding this article anyone can effectively manage and maintain their Linux system.

Читайте также:  To count files in directory in linux

Источник

What is Runlevel in Linux

Linux systems operate or boot in a state called runlevel. When you boot a Linux system, it boots with predefined conditions that define its state. Typically, Linux systems are booted through the command line by the experts.

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:

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:

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:

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

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:

Runlevel Target Description
0 poweroff.target Nothing runs at this runlevel. It is only used for shutting down the system.
1 rescue.target In 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.
2 multi-user.target It 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.
4 Usually, this runlevel is not used, and it is undefined. Users can specify it.
5 graphical.target In most Linux systems, this runlevel is used. It runs the system in multi-user mode with a graphical user interface.
6 reboot.target As soon as the runlevel command is executed, the system is rebooted.
Читайте также:  Как открыть bat на linux

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:

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:

Changing the Runlevel

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

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:

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:

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.

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

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

After a successful authentication, you return to GUI mode.

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.

About the author

Prateek Jangid

A passionate Linux user for personal and professional reasons, always exploring what is new in the world of Linux and sharing with my readers.

Источник

Оцените статью
Adblock
detector