RUNLEVELS: It is nothing but a mode of operation in Linux OS.
- A runlevel is a software configuration of the 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: 0-6 and S or s. The runlevel is changed by a privileged user running telinit command, which sends appropriate signals to init, telling it which runlevel to change to.
- Runlevels 0, 1, and 6 are reserved.
- Runlevel 0 is used to halt the system, runlevel 6 is used to reboot the system, and runlevel 1 is used to get the system down into single user mode i.e into a state where administrative tasks can be performed; this is the default if neither the -h or -r flag is given to shutdown.
- Runlevel 5 is full desktop mode with X sessions enabled providing graphical user interface.
- Text based systems are defaulted to boot up with runlevel 3(Multiuser mode with network access).
- Runlevel S is not really meant to be used directly, but more for the scripts that are executed when entering runlevel 1.
- Runlevels 7-9 are also valid, though not really documented. This is because "traditional" Unix variants don't use them. In case you're curious, runlevels S and s are in fact the same. Internally they are aliases for the same runlevel.
Runlevels and their meaning:
Runlevels |
System Configuration |
0 |
System halt (Do not use this for initdefault!) |
1 |
Single user mode |
2 |
Local multiuser without remote network (e.g. NFS) |
3 |
Full multiuser with network |
4 |
Not used |
5 |
Full multiuser with network and xdm(Graphical mode with X session enabled.) |
6 |
System reboot (Do not use this for initdefault!) |
- SHUDOWN does its job by signalling the init process, asking it to change the runlevel.
- To see which actions are taken on halt or reboot see the appropriate entries for these runlevels in the file /etc/inittab.
# The default runlevel of a system in which it will boot up is defined here in /etc/inittab file:
20 id:3:initdefault:
To change the runlevel temporarily we can use init command. For eg. to change to runlevel 2 from 3, use:
But again after system reboot the system will go the default runlevel i.e 3. To change runlevel permanently, edit the /etc/initab file and change the runlevel value in the above line.
- To Check the current runlevel of the system
runlevel -- find the current and previous system runlevel.
localhost:>runlevel
N 3
Also you can use who -r to check runlevel of the system.
localhost:/sbin:>who -r
run-level 3 2014-10-27 18:40 last=S
- To find what services and processes are running in a particular runlevel, we can use chkconfig command.
localhost:/etc:>chkconfig|more
SuSEfirewall2_init off
SuSEfirewall2_setup off
aaeventd off
acpid on
apache2 on
arpd off
To get previous runlevel of the system
PREVLEVEL
To get previous runlevel (It is useful after a runlevel switch is done).
SYNOPSIS
runlevel [utmp]
- Runlevel reads the system utmp file (typically /var/run/utmp) to locate the runlevel record, and then prints the previous and current system runlevel on its standard output, separated by a single space.
- If there is no previous system runlevel, the letter N will be printed instead.
- If no utmp file exists, or if no runlevel record can be found, runlevel prints the word unknown and exits with an error.
- Runlevel can be used in rc scripts as a substitute for the System-V who -r command. However, in newer versions of init(8) this information is also available in the environment variables RUNLEVEL and PREVLEVEL.
More on runlevel: Booting
After init is invoked as the last step of the kernel boot sequence, it looks for the file /etc/inittab to see if there is an entry of the type initdefault (see inittab(5)). The initdefault entry determines the initial runlevel of the system. If there is no such entry (or no /etc/inittab at all), a runlevel must be entered at the system console.
Runlevel S or s bring the system to single user mode and do not require an /etc/inittab file. In single user mode, /sbin/sulogin is invoked on /dev/console.
When entering single user mode, init initializes the consoles stty settings to sane values. Clocal mode is set. Hardware speed and handshaking are not changed.
When entering a multi-user mode for the first time, init performs the boot and bootwait entries to allow file systems to be mounted before users can log in. Then all entries matching the runlevel are processed.
|