Runlevel in linux

Runlevel in linux

Runlevel is a state of init and the linux machine services works based on that. Each runlevel defines a different system configuration and with different process combination.

When the linux operating system boots the /etc/inittab file will decide the runlevel. Runlevel is been defined by numerical numbers in /etc/inittab file. The Linux runlevel are numbered from 0 to 6.

Using the runlevel linux administrators will determine whether X services will run or not whether network services will run or not and so on.

 

Runlevel In Numbers Runlevel Function
0 System halt or Shutdown the system.
1 Single-user mode. Can login only as root user.
2 Multiuser without network filesystem (NFS). Mostly not used
3 Multiuser with Networking and without X Windows(GUI).
4 Unused.
5 Multiuser with Networking and X Windows(GUI)
6 Reboot the machine.

 

 

The above table will explain much about runlevel nature. At the time of linux operating system boots the /etc/inittab file will determine at which runlevel the system should boot. Sample /etc/inittab file.

[root@client ~] cat /etc/inittab | head -n 18 | tail -n 1
id:5:initdefault:

 

The First field is simply a label. The second field determines the runlevel. The third field means that init should run the command in the fourth field.

 

The number “5” in the second field determines that system should boot in runlevel 5. Then content of the runlevel are located in either /etc/rcX.d or /etc/rc.d/rcX.d (X which determines the runlevel number). In each runlevel (/etc/rc.d/rc5.d) you can find series of soft link which is pointing to start-up scripts location in /etc/init.d.

 

The name of the soft links are either starts with “S” or “K” and followed by a number. The “S” indicates system start up scripts and the “K” indicated system shutdown scripts. The script begin with “S” are executed while the system boots and the script begins with “K” are executed at the time of system shutdown. The number following the K or S indicates the order in which the scripts will be run.

 

Runlevel in linux

 

 

How to find your current runlevel in linux.

 

#who -r
run-level 5  2002-01-01 05:30                   last=S

Another Method

#runlevel
N 5

 

Runlevel in linux

 

How to change your default runlevel permanently.

cat /etc/inittab | head -n 18 | tail -n 1
id:5:initdefault:

We need to edit the number “5” in the above line. Change the number from “5” to “3” and save the file and hit reboot. Then the machine will boots in runlevel 3 by default.

 

How to change your default runlevel temporarily.

The following command will change the runlevel to 1 temporarily
init 1

The following command will change the runlevel to 3 temporarily
init 3

 

Runlevel in Debian and Ubuntu operating system.

In Debian and Ubuntu operating system runlevel are bit different. The runlevel is also numbered from 0 to 6 in Debian and Ubuntu operating system. The functions of the runlevel are explained in the following table.

 

Runlevel In Numbers Runlevel Function
0 System halt or Shutdown the system.
1 Single-user mode. Can login only as root user.
2 Full multi-user mode (Default).
3 – 5 Same as 2.
6 Reboot.

 

How to change default runlevel in Ubuntu operating system.

 cat /etc/init/rc-sysinit.conf
#Change Default Runlevel 2 to 5
env DEFAULT_RUNLEVEL=2

Change the runlevel in “env DEFAULT_RUNLEVEL=1″ to boot in runlevel 1 by default.




Leave a Reply

Your email address will not be published. Required fields are marked *