Different Run levels in Linux and how to switch
between them
What are different Run levels in Linux and how to switch between
them?
Run levels:-Run levels define what processes or services to run
automatically while the system boots up. This is defined in /etc/inittab file.
N. B: – The init process is the last step in the boot procedure
and has pid of ‘1’.’ “init” is responsible for starting system processes as per
defined in the /etc/inittab file.
“init” process checks which default run level
is defined in /etc/inittab and starts the system in that run level which means all
the services defined for that run level gets executed.
There are 7 different run levels present (run level 0-6) in
Linux system for different purpose. The descriptions are given below.
0: Halt System (To shutdown the system)
1: Single user mode
2: Basic multi user mode without NFS
3: Full multi user mode (text based)
4: unused
5: Multi user mode with Graphical User Interface
6: Reboot System
1: Single user mode
2: Basic multi user mode without NFS
3: Full multi user mode (text based)
4: unused
5: Multi user mode with Graphical User Interface
6: Reboot System
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 as it is advisable not to install
graphical windows in a server as lots of space goes waste and also it takes lot
of resource to run.
Each run level is defined inside its own
directory structure. These directories are located in the /etc/rc.d/ directory,
under which you have rc1.d, rc2.d… rc6.d directories where the number from 0 to
6 corresponds to the specific run level. Inside each directory symbolic links
are defined to a to master initscripts found in /etc/init.d or
/etc/rc.d/init.d.
Switching or Changing
between different runlevels:-
Method-1: Changing run level temporarily without reboot.
We can use init command to change rune levels
without rebooting the system.
Ex:-if we are currently in run level 3 and want to go to run
level 1, just we need to execute
# init 1
Or if you want to shutdown a machine you can take help of run
level ‘0’ .Just you need to execute
#init 0
Remember this change is not permanent and on next reboot you
will get your default runlevel.
Method-2: Changing run level permanently
If you want to change your default run level then
Open the file /etc/inittab and edit entry initdefault:
# vi /etc/inittab
Let’s set initdefault to 5, so that you can boot to X next time
when Linux comes up:
id:5:initdefault:
Method-3:-Change run level at boot time
You can also change the run level at boot time. If your system
uses LILO as the boot manager, you can append the run level to the boot
command:
LILO: linux 3 or
LILO: linux 5
LILO: linux 5
If your system uses GRUB, you can change the boot runlevel by
pressing the `e’ key to edit the boot configuration. Append the run level(in
our case 5) to the end of the boot command as shown:
kernel /vmlinuz-2.6.18-164.el5 ro root=LABEL=/ rhgb quiet
5
Linux
Runlevels Explained
A runlevel is one of the modes that a Unix -based
operating system will run in. Each runlevel has a certain number of services
stopped or started, giving the user control over the behavior of the machine.
Conventionally, seven runlevels exist, numbered from zero to six.
After the Linux kernel has booted, the init program reads the /etc/inittab file to determine the behavior for each runlevel. Unless the user specifies another value as a kernel boot parameter, the system will attempt to enter (start) the default runlevel.
After the Linux kernel has booted, the init program reads the /etc/inittab file to determine the behavior for each runlevel. Unless the user specifies another value as a kernel boot parameter, the system will attempt to enter (start) the default runlevel.
Run
Level
|
Mode
|
Action
|
0
|
Halt
|
Shuts down system
|
1
|
Single-User Mode
|
Does not configure network interfaces, start
daemons, or allow non-root logins
|
2
|
Multi-User Mode
|
Does not configure network interfaces or start
daemons.
|
3
|
Multi-User Mode with Networking
|
Starts the system normally.
|
4
|
Undefined
|
Not used/User-definable
|
5
|
X11
|
As runlevel 3 + display manager(X)
|
6
|
Reboot
|
Reboots the system
|
Standard run levels for Red Hat based
distributions
|
Most Linux servers
lack a graphical user interface and therefore start in runlevel 3. Servers with
a GUI & desktop Unix systems start runlevel 5.When a server is issued a
reboot command, it enters runlevel 6.
Init scripts
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.
The /etc/inittab file is used to set the default run level
for the system. This is the runlevel that a system will start up on upon
reboot. The applications that are started by init are located in the /etc/rc.d folder.
Within this directory there is a separate folder for each run level, eg rc0.d, rc1.d, and so on.
chkconfig
The chkconfig tool is used in Red Hat based systems
(like CentOS) to control what services are started at which runlevels. Running
the command chkconfig –list will display a list of services
whether they are enabled or disabled for each runlevel.
root@host:~ # chkconfig
--list
filelimits
0:off 1:off 2:on 3:on 4:on 5:on 6:off
syslog
0:off 1:off 2:on 3:on 4:on 5:on 6:off
gpm 0:off
1:off 2:on 3:on 4:on 5:on 6:off
cpanel
0:off 1:off 2:off 3:on 4:on 5:on 6:off
kudzu
0:off 1:off 2:off 3:on 4:on 5:on 6:off
ntpd
0:off 1:off 2:off 3:off 4:off 5:off 6:off
netfs
0:off 1:off 2:off 3:on 4:on 5:on 6:off
network
0:off 1:off 2:on 3:on 4:on 5:on 6:off
netplugd
0:off 1:off 2:off 3:off 4:off 5:off 6:off
rawdevices
0:off 1:off 2:off 3:on 4:on 5:on 6:off
ipchains
0:off 1:off 2:on 3:on 4:on 5:on 6:off
iptables
0:off 1:off 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
anacron
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
xfs 0:off
1:off 2:on 3:on 4:on 5:on 6:off
xinetd
0:off 1:off 2:off 3:on 4:on 5:on 6:off
httpd
0:off 1:off 2:off 3:on 4:off 5:on 6:off
Single User mode is a mode
that a multi-user system (like a Linux server) can be booted into the operating
system as a superuser. Booting a system into this mode does not start
networking, but can be used to make changes to any configuration files on the
server. One of the most common usages for single-user mode is to change the root
password for a server on which the current password is unknown.
Runlevels are an important part of the core of the Linux
operating system. While not something the average administrator will work with
on a daily basis, understanding runlevels gives the administrator another layer
of control and flexibility over the servers they manage.
No comments:
Post a Comment