Booting into a different runlevel can help solve certain problems. For example, if a change made in the X Window System configuration on a machine that has been set up to boot into a GUI has rendered the system unusable, it is possible to temporarily boot into a console i. The runlevel command can be used to find both the current runlevel and the previous runlevel by merely typing the following and pressing the Enter key:.
The runlevel executable file i. Thus, it is usually necessary to type the full path of the command as shown above rather than just the name of the command itself.
This file can be easily and safely read with a command such as cat , i. Conventionally, seven runlevels exist, numbered from zero to six. Unless the user specifies another value as a kernel boot parameter, the system will attempt to enter start the default runlevel. Most Linux servers lack a graphical user interface and therefore start in runlevel 3.
Servers with a GUI and desktop Unix systems start runlevel 5. When a server is issued a reboot command, it enters runlevel 6. Init short for initialization is the program on Unix and Unix-like systems that spawns all other processes. It runs as a daemon and typically has PID 1. This is the runlevel that a system will start up on upon reboot.
Within this directory there is a separate folder for each run level, eg rc0. The chkconfig tool is used in RedHat based systems like CentOS to control what services are started at which runlevels. Another method we can use to find the runlevel is by using the who command with the -r parameter:. We get two different runlevels here. We get the current runlevel along with another runlevel, which was the last runlevel.
If we had ever changed the runlevel from the default, it would be listed with the last parameter in the output. In our scenario, the last runlevel was 3, and the current one is 5.
We can also use the systemctl command, which we will look at later in this tutorial. Before using any command, it is always advisable to read through the help to understand its parameters. We can get the help on runlevels by using the following command:. Notice that the help also contains a reference to the man pages. We should be able to get more details on the runlevels. The man pages display a total of 7 runlevels, which range from 0 to 6. Each runlevel is designated to perform a specific task.
The man pages displayed a total of 7 runlevels, which are:. Now that we know what runlevels are, we must understand that each runlevel is a specific environment executed through a specific set of scripts. So, where are these scripts stored? The runlevel files are stored in their respective directories, which are named as:. Each of the subdirectories is designed to keep the configuration files for a specific runlevel.
The output of the ls command is now listed. We need to scroll back up to view the rc set of subdirectories. A set of configuration scripts and files are stored in this subdirectory. Just as a quick recap, we now know what a runlevel is, along with the directory and subdirectory where its configuration files are stored.
Whenever a LINUX system boots, firstly the init process is started which is actually responsible for running other start scripts which mainly involves initialization of you hardware, bringing up the network, starting the graphical interface.
Now, the init first finds the default runlevel of the system so that it could 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. Each runlevel designates a different system configuration and allows access to different combination of processes. The important thing to note here is that there are differences in the runlevels according to the operating system. 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.
0コメント