Various run levels in Redhat

This entry was posted in Unix and tagged on June 17, 2012, by

What is Run level?

The mode of operation in operating system is know as Run levels.

Following are the various run levels in redhat.

ID Description
0 Halt
1 Single-User mode
2 Multi-user mode console logins only (without networking)
3 Multi-User mode, console logins only
4 Not used/User-definable
5 Multi-User mode, with display manager as well as console logins (X11)
6 Reboot

The default run level to start to and stop is stored in /etc/inittab.

Following is the format of /etc/inittab file

id:runlevels:action:process

* id : A unique character which identifies an entry in inittab

* runlevel : List the runlevel on which specific action should be taken.

* action : Describes what kind of action should be taken. Following are some of the valid actions

  • respawn – process will restart whenever it is terminated
  • wait – process will be started when specific runlevel is entered and init will wait for its termination
  • once – The process will be executed once when spscified run level is entered
  • boot – the process will executed during system boot
  • bootwait – Same as “boot” above, but init waits for its termination.
  • off – This does nothing.
  • ondemand – This process will be executed whenever the specified ondemand runlevel is called.
  • initdefault – Specifies the runlevel which should be entered after system boot. If none exists, init will ask for a runlevel on the console. The process field is ignored.
  • sysinit – The process will be executed during system boot. It will be executed before any boot or bootwait entries. The runlevels field is ignored.
  • powerwait – The process will be executed when init receives the SIGPWR signal. Init will wait for the process to finish before continuing.
  • powerfail – Same as powerwait but init does not wait for the process to complete.
  • powerokwait – The process will be executed when init receives the SIGPWR signal provided there is a file called “/etc/powerstatus” containing the word “OK”. This means that the power has come back again.
  • ctrlaltdel – This process is executed when init receives the SIGINT signal. This means someone on the system console has pressed the “CTRL-ALT-DEL” key combination.
  • kbrequest – The process will be executed when init receives a signal from the keyboard handler that a special key combination was pressed on the console keyboard.
  • process – Specifies the process to be executed

Following is the sample of /etc/inittab file.

# more /etc/inittab
#
# inittab       This file describes how the INIT process should set up
#               the system in a certain run-level.
#
# Author:       Miquel van Smoorenburg,
#               Modified for RHS Linux by Marc Ewing and Donnie Barnes
#

# 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)
#
id:5:initdefault:

# System initialization.
si::sysinit:/etc/rc.d/rc.sysinit

l0:0:wait:/etc/rc.d/rc 0
l1:1:wait:/etc/rc.d/rc 1
l2:2:wait:/etc/rc.d/rc 2
l3:3:wait:/etc/rc.d/rc 3
l4:4:wait:/etc/rc.d/rc 4
l5:5:wait:/etc/rc.d/rc 5
l6:6:wait:/etc/rc.d/rc 6

# Trap CTRL-ALT-DELETE
ca::ctrlaltdel:/sbin/shutdown -t3 -r now

# When our UPS tells us power has failed, assume we have a few minutes
# of power left.  Schedule a shutdown for 2 minutes from now.
# This does, of course, assume you have powerd installed and your
# UPS connected and working correctly.
pf::powerfail:/sbin/shutdown -f -h +2 “Power Failure; System Shutting Down”

# If power was restored before the shutdown kicked in, cancel it.
pr:12345:powerokwait:/sbin/shutdown -c “Power Restored; Shutdown Cancelled”

# Run gettys in standard runlevels
1:2345:respawn:/sbin/mingetty tty1
2:2345:respawn:/sbin/mingetty tty2
3:2345:respawn:/sbin/mingetty tty3
4:2345:respawn:/sbin/mingetty tty4
5:2345:respawn:/sbin/mingetty tty5
6:2345:respawn:/sbin/mingetty tty6

# Run xdm in runlevel 5
x:5:respawn:/etc/X11/prefdm -nodaemon

 

  • On line 1 above you see “id:5:initdefault:”. The id is “id” which stands for initdefault. Note that it is unique on all the numbered lines. The runlevel is 5 which sets the default starting runlevel to runlevel 5.
  • Line 2 tells init to run the program “/etc/rc.d/rc.sysinit” during system boot, before any other processes.
  • Lines 3 through 9 tell init to run the program “/etc/rc.d/rc” for runlevels 0 through 6.
  • Line 10 sets up the program “/sbin/shutdown” to run when someone on the system console has pressed the “CTRL-ALT-DEL” key combination.
  • Line 11 specifies “/sbin/shutdown” to run if the power fails.
  • Line 12 specified “/sbin/shutdown” will run if power is restored for any of runlevels 1 through 5.
  • Lines 13 through 18 specifies the “/sbin/mingetty” program to run on 6 different terminals for runlevels 2 through 5. This means that you can run 6 virtual terminals from your keyboard simultaneously by pressing “ALT-F1” through “ALT-F6”. Note pressing “ALT-F7” or above will do nothing, but the screen will not change from your current terminal.

Leave a Reply

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

Copyright 2017 ©Aceadmins. All rights reserved.