AMP AMP

Runlevel command in Linux with Examples

Runlevel Command

Runlevel defines the state of the machine after boot. It has a certain number of services stopped or started, giving the user control over the behavior of the machine. Only one runlevel is executed on start up. It is numbered from zero to six.

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

Most desktop Linux distributions boot into run level 5, which starts up the Graphical Login Prompt. This allows the user to use the system with X-Windows server enabled. Most servers boot into run level 3, which starts the text based login prompt.

The default runlevel for an RHEL system is defined within the /etc/inittab file. To identify the current default level or change the default to a different setting on running refers the above mentioned path.

Default runlevel

# 0 - halt (Do NOT set initdefault to this)
# 1 - Single user mode
# 2 - Multiuser, without NFS (The same as 3, if you do not have networking)
# 3 - Full multiuser mode
# 4 - unused
# 5 - X11
# 6 - reboot (Do NOT set initdefault to this)
#id:5:initdefault:

To change the run level

To change the run level from any runlevel to another runlevel change the value present at the end of the page

id:3:initdefault:

To save changes

Save the changes and then reboot the system so that the changes take effect.

OR

There is also another way of changing the runlevel from the terminal using the init command. To perform this action enter the command init continued with the number of the runlevel value required.

[root@linuxhelp ~]$ init 3


Now it will be changed to the runlevel 3( Full multi-user mode)

OR

For GRUB, follow these steps
1. In the graphical GRUB boot loader screen before the OS goes to automatic boot press ‘ enter’ , select the CentOS (select your own OS) boot label and press ‘ e’ to edit it.
2. Use down arrow to move to the kernel line and press ’ e’ to edit it.
3. At the prompt, type the number of the runlevel you wish to boot (1 to 5) and press ‘ enter’ .
4. The GRUB screen reappears with the kernel information. Press the ‘ b’ key to boot the system.

To check the current run level

Example

[root@linuxhelp ~]# who -r 
 run-level 5  2016-02-27 15:16

You can see the output shows run level -5 that is multi-user with graphical mode. It is just the current run level and not the default run level.

To check the services which is enabled in different run levels

Here we use the chkconifg command to check the services available with run level

Example

[root@linuxhelp ~]# chkconfig --list 
NetworkManager     0:off    1:off    2:on    3:on    4:on    5:on    6:off
abrt-ccpp          0:off    1:off    2:off    3:on    4:off    5:on    6:off
abrtd              0:off    1:off    2:off    3:on    4:off    5:on    6:off
acpid              0:off    1:off    2:on    3:on    4:on    5:on    6:off
atd                0:off    1:off    2:off    3:on    4:on    5:on    6:off
auditd             0:off    1:off    2:on    3:on    4:on    5:on    6:off
autofs             0:off    1:off    2:off    3:on    4:on    5:on    6:off
blk-availability    0:off    1:on    2:on    3:on    4:on    5:on    6:off
bluetooth          0:off    1:off    2:off    3:on    4:on    5:on    6:off
certmonger         0:off    1:off    2:off    3:on    4:on    5:on    6:off
cpuspeed           0:off    1:on    2:on    3:on    4:on    5:on    6:off
crond              0:off    1:off    2:on    3:on    4:on    5:on    6:off
cups               0:off    1:off    2:on    3:on    4:on    5:on    6:off
dnsmasq            0:off    1:off    2:off    3:off    4:off    5:off    6:off
firstboot          0:off    1:off    2:off    3:off    4:off    5:off    6:off
.
.
.
.
wdaemon            0:off    1:off    2:off    3:off    4:off    5:off    6:off
winbind            0:off    1:off    2:off    3:off    4:off    5:off    6:off
wpa_supplicant     0:off    1:off    2:off    3:off    4:off    5:off    6:off
ypbind             0:off    1:off    2:off    3:off    4:off    5:off    6:off

In the above output 0.1..6 represents run level.

FAQ
Q
May i know the syntax of Run level command ?
A
The syntax for the runlevel command is runlevel [utmp]
Q
Where i can Find the Desktop mode Run level at linux Centos ?
A
on most Linux Desktop system default run level is 5. The default run level is defined by the initdefault line at the top of /etc/inittab file under CentOS / Fedora / Redhat / RHEL / Debian
Q
Can you let me know the uasge of Run levels for using in my machine ?
A
Pleae find the usage of the run level mentioned below: Runlevel 0 is halt Runlevel 1 is single-user Runlevels 2-5 are multi-user (some distro uses RUN level 5 to start X [KDE/Gnome]) Runleve
Q
What is the command to switch from one run level to another run level ?
A
Inorder to change the run level You can Use the init command to change rune levels: # init 1
Q
Can you please tell me how to check the Run level of my current Terminal ?
A
You can check the Run level of your Current terminal by using the Following command $ who -r