2.4. The joys of inittab

As promised we next take a closer look at /etc/inttab.

The file has the following structure:

id : runlevel : action : command

The id field can be anything up to 4 characters long. If a runlevel is specified then the command and the required action will be performed only at that specific runlevel. If no number is specified then the line is executed at any run level.

ActionDescription
bootPerformed only at boot time
crtlaltdelAssociate a command when SIGINT is caught by init
initdefaultDefine which runlevel to attain at boot time
respawnFollow process and respawn it when it dies
sysinitIs perform at boot only, before any boot requests
waitStarts the process and waits before starting a new one

Recognisable features in the /etc/inittab file

The default runlevel
This is set at the beginning of the file with the id id and the action initdefault. Notice that no command is given. This line simply tells init what the default runlevel is.
First program called by init

/etc/rc.d/rc.sysinit. This script sets system defaults such as the PATH variable, determines if networking is allowed, the hostname, etc

Default runlevel services

If the default runlevel is 3 then only the line l3 will be executed. The action is wait, no other program is launched until all services in run level 3 are running

The getty terminals

The lines with id's 1 to 6 launch the virtual terminals. This is where you can alter the number of virtual terminals

Runlevel 5

The final line in inittab launches the Xwindow manager if runlevel 5 is reached.

Figure 2.2. The /etc/inittab file

id:3: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
-----------------------snip--------------------------
# Trap CTRL-ALT-DELETE
ca::ctrlaltdel:/sbin/shutdown -t3 -r now
-----------------------snip--------------------------
# 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

Remarks

  1. You can set a modem to listen for connections in inittab. If your modem is linked to /dev/ttyS1 then the following line will allow data connections (no fax) after 2 rings

    S1:12345:respawn:/sbin/mgetty -D -x 2 /dev/ttyS1
  2. When making changes to /etc/inittab you need to force init to reread this configuration file. This can be done using:

    /sbin/init q