Run
level in Linux
A runlevel is
a preset operating state on a Unix-like operating
system. A system can
be booted
into (i.e.,
started up into) any of several runlevels, each of which is represented by a
single digit integer. Each runlevel designates a different system configuration
and allows access to a different combination of processes (i.e., instances of executing programs).
There
are differences in the runlevels according to the operating system. Seven
runlevels are supported in the standard Linux kernel (i.e., core of the operating
system).
If
you are moving to higher run levels, you may make additional services available
to users, while moving to a lower run level will causes to services (daemons)
to become unavailable. On the production server run level 3 is the normally
used and rarely changed. However, some administrative tasks require the
administrator to move system to run level 1 i.e single user mode.
Find
current run level
[root@linux1 ~]# who -r
run-level 5 2016-05-31 17:41 last=S
[root@linux1 ~]#
You can
also runlevel command to find out your current run level.
[root@linux1 ~]# runlevel
N 5
[root@linux1 ~]#
Runlevel
and Its Usage
The
Init is the parent of all processes with PID # 1. Its primary purpose is to
create processes from a script stored in the file /etc/inittab file. This file
usually has entries which cause init to spawn gettys on each line that users
can log in. A runlevel is nothing but a software configuration of the Linux
system which allows only a selected group of processes to exist. The processes
spawned by init for each of these runlevels are defined in the /etc/inittab
file. Init can be in one of eight runlevels as follows:
·
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])
·
Runlevel
6 is for rebooting system
Note: telinit or init can be used to change
the run level but you will lost the connection, so think twice before changing
the runlevel command.
By default
Linux boots either to runlevel 3 or to runlevel 5. The former permits the
system to run all services except for a GUI. The latter allows all services
including a GUI.
For
example, typing the init 3 command will move system to run level 3:
# init 3
Default
runlevel. The runlevels used by RHS are:
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)
It is
always wise to make a backup copy of /etc/inittab or any other configuration
file before attempting to modify it manually.
# vi /etc/inittab
Set
initdefault to 5, so that you can boot to X next time when Linux comes up:
id:5:initdefault:
Save and
close the file. Reboot the system to see changes:
# reboot