The run level determines which services will run and which will be stopped during system initialization. The run levels are given below:

   0   Halt the system.
   1    Single-user mode (for system maintenance).
   2    Local Multiuser with Networking but without network service (like NFS)
   3    Full Multiuser with Networking
   4    Not Used
   5    Full Multiuser with Networking and X Windows(GUI)
   6    Reboot.

The sub-directories in /etc directory ranging from rc0.d to rc6.d contains a number of scripts each for killing and starting the processes. Hence, when a run level is determined, init process looks into the respective directory and run the scripts in sequence. Lets take an example of rc3.d directory which has the following files.

image

Please note that there are two type of directories, ones that start with ‘K’ and others that with ‘S’. ‘K’ means kill and ‘S’ means start. So, the files with K in the beginning will kill the respective processes as mentioned in their scripts and the files with S will be used to start the processes. These files are run in sequence as per their numbering.

You can change the run levels directly as a superuser by using ‘init’ command. For example, if your linux system is currently working in GUI mode, the run level probably would be 5. If you want to change it to command line, simple change the run level to 3 as below:

image

The ‘runlevel’ command will show the current and last run level used on the system. If your system boots for the first time and it has not changed the run level previously, it will be shown as ‘N’. In the above example, the current run level is 5 and it is then changed to 3 with init command.

System initially reads /etc/inittab file for loading the sytem in a default runlevel. If you want to change the default runlevel, you’ll have to modify this following line:

id:5:initdefault:

As you can see, the default runlevel is 5 at the moment, you can modify it at your consent but don’t change it to 0 or 6 or your system will never come up in a useable state since the run level 0 instructs the machine to halt and shutdown, so every time the system boots, it will shutdown again. Similar is the case with run level 6. For commercial servers, usually the run level is kept as 3 since the system performance is much better without GUI.

Adnan Khurshid

Adnan Khurshid, the author of this article, has been working in a telecommunication sector since 2007. He has worked there as a VAS (Value Added Services) engineer and has excelled remarkably in the field. Working in this field has been his passion and he has always made efforts to keep himself up to date. Find more about him on LinkedIn

More Posts

Tags: , ,

1 Comment on Changing run levels for Linux/Unix

Leave a Reply