Understanding /etc/inittab



 

 


The Startup process is governed by the configuration specified in the /etc/inittab (initialization table) file. The inittab file contains configuration items that specify several important aspects of the startup process. These include the following items:

Note: As of Fedora 11, the inittab file is used only to specify the default runlevel. All of the other functions have been replaced by the new upstart Startup manager.

However, starting with Fedora 14, upstart was replaced by systemd and the inittab file is no longer used at all. What is left is merely a stub to indicate that it is no longer used.

 

  • The default runlevel
  • The name and location of the system initialization script
  • The directories containing the runlevel scripts
  • Traps for key sequences such as ctrl-alt-delete
  • UPS power failure and restore scripts
  • GETTY definitions

A typical inittab file looks like this:

#
# inittab       This file describes how the INIT process should set up
#               the system in a certain run-level.
#
# Author:       Miquel van Smoorenburg, <miquels@drinkel.nl.mugnet.org>
#               Modified for RHS Linux by Marc Ewing and Donnie Barne
#
# 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

Default Runlevel

The default runlevel is defined by the line:

id:5:initdefault:

This specifies that the default is runlevel 5, which is graphical mode. Typical default run levels are 3 and 5. Refer to Understanding Run Levels for more information.

System Initialization Program

The following line specifies the system initialization program. In this case, the script /etc/rc.d/rc.sysinit.

si::sysinit:/etc/rc.d/rc.sysinit

The rc.sysinit script performs many important functions including activating SELinux, if it is configured, enabling swap partitions, activating RAID and Logical Volume Manager devices and disk quotas. It also checks and mounts the other filesystems.

The leading “si” is merely an identifier. The third field is the action field and contains “sysinit” which specifies the purpose of the line, and the rest of the line is the fully qualified path and file name.

Run Level Descriptors

The next several lines define the run levels and the locations of the start scripts for each run level.

 

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

Again, the first column is a text identifier. The second column is the number of the run level. The fourth column is the path and filename of the script that runs the start scripts with the numeric parameter representing the run level.

The action field in these lines is “wait” which means that init launches the process once and then waits for it to complete before continuing.

Traps

Traps allow init to capture certain actions and react in specific ways to them.

Ctrl-Alt-Del

ca::ctrlaltdel:/sbin/shutdown -t3 -r now

This first line traps the Ctrl-Alt-Del key combination and reboots the computer after waiting 3 seconds. This allows Linux to react to Ctrl-Alt-Del in the same way as other operating systems. If you do not want your computer to respond to Ctrl-Alt-Del in this way, you can change the action field of this line.

Power Failure

The init process can react to a power failure as well. This assumes that the computer is connected to a UPS and that the computer is running software which communicates with the UPS and understands when a power failure has occurred. I use the Open Source APCUPSD program for communicating with my APC UPS’es.

pf::powerfail:/sbin/shutdown -f -h +2 “Power Failure; System Shutting Down”
pr:12345:powerokwait:/sbin/shutdown -c “Power Restored; Shutdown Canceled”

The first of these two lines shuts down the system to a complete halt and power off after a wait of two minutes. The second cancels the shutdown if power returns during the 2 minute wait. The text in the quotes is displayed on every terminal to all users so that they can be forewarned.

The gettys

A getty is a process that waits for a login connection on a text mode “tty.” When a login connection is made, the getty turns over control of the virtual terminal to a terminal session and the shell running in it. When the user of the session logs out, the shell and terminal session are terminated and init respawns a new getty to wait for the next connection.

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

Each of the gettys defined in the lines above waits on one of the text mode virtual terminals for a login. The second field specifies that the getty is to run in run levels 2 through 5.

Use the key combination Ctrl-Alt-FX, where X is a number from 1 to 6, to switch your Linux screen to one of the virtual terminal login sessions. Depending upon which release of Fedora you are using, terminals 1 or 7 may be your GUI.

They term “getty” is a historical one that literally means “get tty” or “get teletype.” When Unix was in its heyday, a teletype was the standard way to connect to a computer.

X

The final line in inttab is the line that specifies the X (the X Window System) login program for run level 5.

x:5:respawn:/etc/X11/prefdm -nodaemon

This works in very much the same way that the getty lines do for text mode logins. The prefdm program is run and launches a default program for a graphical login. This graphical login program waits for a login and turns over control to X. The init program waits until the user logs out and then respawns another copy of the prefdm program, which in turn launches the default graphical login program to wait for another login.