UNIX / Linux Tutorial

2.3.1 The /etc/inittab file

2.3.1 The /etc/inittab file

Immediately after Linux boots and the kernel mounts the root file system, the first
program that the system executes is init. This program is responsible for starting the
system startup scripts, and modifies the system operating from its initial boot-up state to
its standard, multi-user state. init also spawns the login: shells for all of the tty devices
on the system, and specifies other startup and shutdown procedures.

After startup, init remains quietly in the background, monitoring and if necessary
altering the running state of the system. There are many details that the init program 
must see to. These tasks are defined in the /etc/inittab file. A sample /etc/inittab
file is shown below.

Modifying the /etc/inittab file incorrectly can prevent you from logging in to 
your system. At the very least, when changing the /etc/inittab file, keep on hand
a copy of the original, correct file, and a boot/root emergency floppy in case you make 
a mistake :

#
# inittab
This file describes how the INIT process should set up
# the system in a certain run-level.
#
# Version: @(#)inittab 2.04 17/05/93 MvS
# 2.10 02/10/95 PV
#
# Author:
Miquel van Smoorenburg, 
# Modified by: Patrick J. Volkerding, 
# Minor modifications by:
# Robert Kiesling, 
#
# Default runlevel.
id:3:initdefault:

# System initialization (runs when system boots).
si:S:sysinit:/etc/rc.d/rc.S

# Script to run when going single user (runlevel 1).
su:1S:wait:/etc/rc.d/rc.K

# Script to run when going multi user.
rc:23456:wait:/etc/rc.d/rc.M

# What to do at Ctrl-Alt-Del
ca::ctrlaltdel:/sbin/shutdown -t5 -rfn now

# Runlevel 0 halts the system.
l0:0:wait:/etc/rc.d/rc.0

# Runlevel 6 reboots the system.
l6:6:wait:/etc/rc.d/rc.6

# What to do when power fails (shutdown to single user).
pf::powerfail:/sbin/shutdown -f +5 "THE POWER IS FAILING"

# If power is back before shutdown, cancel the running shutdown.
pg:0123456:powerokwait:/sbin/shutdown -c "THE POWER IS BACK"

# If power comes back in single user mode, return to multi user mode.
ps:S:powerokwait:/sbin/init 5

# The getties in multi user mode on consoles an serial lines.
#
# NOTE NOTE NOTE adjust this to your getty or you will not be
# able to login !!
#
# Note: for 'agetty' you use linespeed, line.
# for 'getty_ps' you use line, linespeed and also use 'gettydefs'
c1:1235:respawn:/sbin/agetty 38400 tty1 linux
c2:1235:respawn:/sbin/agetty 38400 tty2 linux
c3:1235:respawn:/sbin/agetty 38400 tty3 linux
c4:1235:respawn:/sbin/agetty 38400 tty4 linux
c5:1235:respawn:/sbin/agetty 38400 tty5 linux
c6:12345:respawn:/sbin/agetty 38400 tty6 linux

# Serial lines
# s1:12345:respawn:/sbin/agetty -L 9600 ttyS0 vt100
s2:12345:respawn:/sbin/agetty -L 9600 ttyS1 vt100

# Dialup lines
d1:12345:respawn:/sbin/agetty -mt60 56000,38400,19200,9600,2400,1200 ttyS0 vt100
#d2:12345:respawn:/sbin/agetty -mt60 56000,38400,19200,9600,2400,1200 ttyS1 vt100

# Runlevel 4 used to be for an X-window only system, until we discovered
# that it throws init into a loop that keeps your load avg at least 1 all
# the time. Thus, there is now one getty opened on tty6. Hopefully no one
# will notice. ;ˆ)
# It might not be bad to have one text console anyway, in case something
# happens to X.
x1:4:wait:/etc/rc.d/rc.4

# End of /etc/inittab

At startup, this /etc/inittab starts six virtual consoles, a login: prompt on
the modem attached to /dev/ttyS0,andalogin: prompt on a character terminal
connected via a RS-232 serial line to /dev/ttyS1.

Briefly, init steps through a series of run levels, which correspond to various operational
states of the system. Run level 1 is entered immediately after the system boots,
run levels 2 and 3 are the normal, multi-user operation modes of the system, run level 4
starts the X Window System via the X display manager xdm, and run level 6 reboots the
system. The run level(s) associated with each command are the second item in each line of
the /etc/inittab file.

For example, the line:

                     s2:12345:respawn:/sbin/agetty -L 9600 ttyS1 vt100

will maintain a login prompt on a serial terminal for runlevels 1–5. The "s2" before 
the first colon is a symbolic identifier used internally by init. respawn is an init keyword
that is often used in conjunction with serial terminals. If, after a certain period of time, 
the agetty program, which spawns the terminal's login: prompt, does not receive input
at the terminal, the program times out and terminates execution. "respawn" tells init
to re-execute agetty, ensuring that there is always a login: prompt at the terminal,
regardless of whether someone has logged in. The remaining parameters are passed directly
to agetty and instruct it to spawn the login shell, the data rate of the serial line, the
serial device, and the terminal type, as defined in /etc/termcap or /etc/terminfo.

The /sbin/agetty program handles many details related to terminal I/O on the
system. There are several different versions that are commonly in use on Linux systems.

They include mgetty, psgetty, or simply, getty.
In the case of the /etc/inittab line:

d1:12345:respawn:/sbin/agetty -mt60
38400,19200,9600,2400,1200 ttyS0 vt100

which allows users to log in via a modem connected to serial line /dev/ttyS0, the
/sbin/agetty parameters "-mt60" allow the system to step through all of the modem
speeds that a caller dialing into the system might use, and to shut down /sbin/agetty
if there is no connection after 60 seconds. This is called negotiating a connection. The
supported modem speeds are enumerated on the command line also, as well as the serial
line to use, and the terminal type. Of course, both of the modems must support the data
rate which is finally negotiated by both machines.

Many important details have been glossed over in this section. The tasks that
/etc/inittab maintains would comprise a book of their own. For further information,
the manual pages of the init and agetty programs, and the Linux Documentation
Project's Serial HOW TO, are starting points.

HOME

1.1 Introduction   1.2.10 Referring To Home Directories   1.3.4  Copying Files

1.6 Exploring The File System   1.8   Wildcards   1.9.3 Pipes   1.10.3 Permissions Dependencies

1.12.4  Stopping And Restarting Jobs   1.13.3 Inserting Text   1.13.9 Including Other Files

1.14.3 Shell Initialization Scripts   System Administration   2.3.1 The /etc/imitate file

2.4 Managing File Systems   2.6 Managing Users  2.6.5 Groups   2.7.2 gzip and compress

2.8.3 Making Backups To Tape Devices   2.9.1 Upgrading The Kernel   

2.9.3 Installing A Device Driver Module

BOOK: LINUX QUICK COMMAND REFERENCE

http://personal.atl.bellsouth.net/~psadler

© copyright KnowledgeWorks, Inc. (2001)