The init Process andetcinittab File


The init Process and/etc/inittab File

When a Linux system is booted, the first process that the kernel starts is /sbin/init. It is always process id (PID) 1 and has a parent process id (PPID) of 0. The init process is always running.

root      1      0  0 14:05 ?         00:00:08 init [3]


The /etc/inittab file is the configuration file for /sbin/init. /etc/inittab identifies the processes that init starts, and it can be customized as desired. Few environment variables are set when a process is started by init. The inittab lines have four colon-separated fields:

<id>:<runlevels>:<action>:<command>


Let's look at the meaning of each.

  • id The inittab id consists of one to four characters that identify the inittab line. The id must be unique.

  • runlevels The runlevels field contains one or more characters, usually numbers identifying the runlevels for which this process is started. Table 1-2 lists the runlevel meanings.

    Table 1-2. Runlevels

    Run Level

    Meaning

    0

    System halt

    1

    Single user mode

    2

    Local multiuser without remote network (e.g., NFS)

    3

    Multiuser with network

    4

    Not used

    5

    Multiuser with network and xdm

    6

    System reboot


  • action The keyword in this field tells init what action to take. The more common keywords are shown in Table 1-3.

    Table 1-3. inittab Keywords for the action Field

    Keyword

    Usage

    respawn

    Command is restarted whenever it terminates.

    wait

    Command is run once. init waits for it to terminate before continuing.

    once

    Command is run once.

    boot

    Command is run during boot up. The runlevels field is ignored.

    bootwait

    Command is run during boot up, and the runlevels field is ignored. init waits for the process to terminate before continuing.

    initdefault

    Specifies default runlevel of the Linux system

    powerwait

    Command is run when the power fails. init waits for the process to terminate before continuing.

    powerfail

    Command is run when the power fails. init does not wait for the process to terminate before continuing.

    powerokwait

    Command is run when power is restored. init waits for the process to terminate before continuing.

    powerfailnow

    Command is run when UPS signals that its battery is almost dead.


  • command This field specifies the path of the command that init executes.

See the inittab(8) man page for the complete list of inittab action keywords and a more detailed example of the /etc/inittab file. The following is a typical /etc/inittab file from a SUSE 9.0 system. The lines controlling startup and shutdown are bolded.

# # /etc/inittab # # Copyright (c) 1996-2002 SuSE Linux AG, Nuernberg, Germany. All rights # reserved. # # Author: Florian La Roche, 1996 # Please send feedback to http://www.suse.de/feedback # # This is the main configuration file of /sbin/init, which # is executed by the kernel on startup. It describes what # scripts are used for the different runlevels. # # All scripts for runlevel changes are in /etc/init.d/. # # This file may be modified by SuSEconfig unless CHECK_INITTAB # in /etc/sysconfig/suseconfig is set to "no" # # The default runlevel is defined here id:5:initdefault: # First script to be executed, if not booting in emergency (-b) mode si::bootwait:/etc/init.d/boot # /etc/init.d/rc takes care of runlevel handling # # runlevel 0 is System halt (Do not use this for initdefault!) # runlevel 1 is Single user mode # runlevel 2 is Local multiuser without remote network (e.g. NFS) # runlevel 3 is Full multiuser with network # runlevel 4 is Not used # runlevel 5 is Full multiuser with network and xdm # runlevel 6 is System reboot (Do not use this for initdefault!) # l0:0:wait:/etc/init.d/rc 0 l1:1:wait:/etc/init.d/rc 1 l2:2:wait:/etc/init.d/rc 2 l3:3:wait:/etc/init.d/rc 3 #l4:4:wait:/etc/init.d/rc 4 l5:5:wait:/etc/init.d/rc 5 l6:6:wait:/etc/init.d/rc 6 # what to do in single-user mode ls:S:wait:/etc/init.d/rc S ~~:S:respawn:/sbin/sulogin # what to do when CTRL-ALT-DEL is pressed ca::ctrlaltdel:/sbin/shutdown -r -t 4 now # special keyboard request (Alt-UpArrow) # look into the kbd-0.90 docs for this kb::kbrequest:/bin/echo "Keyboard Request -- edit /etc/inittab to let this work." # what to do when power fails/returns pf::powerwait:/etc/init.d/powerfail start pn::powerfailnow:/etc/init.d/powerfail now #pn::powerfail:/etc/init.d/powerfail now po::powerokwait:/etc/init.d/powerfail stop # for ARGO UPS sh:12345:powerfail:/sbin/shutdown -h now THE POWER IS FAILING # getty-programs for the normal runlevels # <id>:<runlevels>:<action>:<process> # The "id" field MUST be the same as the last # characters of the device (after "tty"). 1:2345:respawn:/sbin/mingetty --noclear 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 co:2345:respawn:/sbin/agetty -h -t 60 ttyS0 9600 vt102 # #S0:12345:respawn:/sbin/agetty -L 9600 ttyS0 vt102 # #  Note: Do not use tty7 in runlevel 3, this virtual line #  is occupied by the programm xdm. # #  This is for the package xdmsc; after installing and #  and configuration you should remove the comment character #  from the following line: #7:3:respawn:+/etc/init.d/rx tty7 # modem getty. # mo:235:respawn:/usr/sbin/mgetty -s 38400 modem # fax getty (hylafax) # mo:35:respawn:/usr/lib/fax/faxgetty /dev/modem # vbox (voice box) getty # I6:35:respawn:/usr/sbin/vboxgetty -d /dev/ttyI6 # I7:35:respawn:/usr/sbin/vboxgetty -d /dev/ttyI7 # end of /etc/inittab Up2p::respawn:/opt/uptime2/bin/uptime2+ Up2r::respawn:/opt/uptime2/lbin/Uptime2+.Restart


Startup in Multiuser Mode

Let's look at the inittab lines that affect startup in multiuser mode. The first noncomment line in inittab tells init the runlevel to move the system to at boot up. For example:

id:5:initdefault:


If the initdefault line is missing, the boot process pauses with a console prompt asking for the runlevel to be specified before continuing. The inittdefault line typically specifies runlevel 3 or 5.

The second non-comment line in inittab is probably the system initialization script or boot script. This script sets up the console, mounts filesystems, sets kernel parameters, and so on. In Red Hat 9.0, the line is:

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


For SUSE 9.0, it is:

si::bootwait:/etc/init.d/boot


The Red Hat boot script, /etc/rc.d/rc.sysinit, is a top-down script compared to SUSE's /etc/init.d/boot script. The SUSE script executes the scripts in /etc/init.d/boot.d/ to set up most system needs. You can get an idea of what gets done by looking at a listing of the boot.d directory. The boot.d directory consists of symbolic links to scripts in /etc/init.d.

#ll /etc/init.d/boot.d total 9 lrwxrwxrwx    1 root     root           12 Jul 6 12:19 S01boot.proc -> ../boot.proc lrwxrwxrwx    1 root     root           12 Jul 6 12:20 S01setserial -> ../setserial lrwxrwxrwx    1 root     root           10 Jul 6 12:20 S03boot.md -> ../boot.md lrwxrwxrwx    1 root     root           11 Jul 6 12:20 S04boot.lvm -> ../boot.lvm lrwxrwxrwx    1 root     root           15 Jul 6 12:20 S05boot.localfs -> ../boot.localfs lrwxrwxrwx    1 root     root           14 Jul 6 12:20 S06boot.crypto -> ../boot.crypto lrwxrwxrwx    1 root     root           19 Jul 6 12:20 S07boot.loadmodules -> ../boot.loadmodules lrwxrwxrwx    1 root     root           27 Jul 6 12:20 S07boot.restore_permissions -> ../boot.restore_permissions lrwxrwxrwx    1 root     root           12 Jul 6 12:20 S07boot.scpm -> ../boot.scpm lrwxrwxrwx    1 root     root           12 Jul 6 12:20 S07boot.swap -> ../boot.swap lrwxrwxrwx    1 root     root           13 Jul 6 12:20 S08boot.clock -> ../boot.clock lrwxrwxrwx    1 root     root           14 Jul 6 12:20 S08boot.idedma -> ../boot.idedma lrwxrwxrwx    1 root     root           16 Jul 6 12:20 S09boot.ldconfig -> ../boot.ldconfig lrwxrwxrwx    1 root     root           14 Jul 6 12:20 S10boot.isapnp -> ../boot.isapnp lrwxrwxrwx    1 root     root           16 Jul 6 12:20 S10boot.localnet -> ../boot.localnet lrwxrwxrwx    1 root     root           13 Jul 6 12:20 S10boot.sched -> ../boot.sched lrwxrwxrwx    1 root     root           16 Jul 6 12:20 S11boot.ipconfig -> ../boot.ipconfig lrwxrwxrwx    1 root     root           12 Jul 6 12:20 S11boot.klog -> ../boot.klog


If you have a SUSE distribution, you should read /etc/init.d/README, which further explains the SUSE boot strategy.

The runlevels consist of a set of processes that start at each runlevel. The processes are started by the /etc/rc.d/rc script. In SUSE, the rc.d directory is a symbolic link to /etc/init.d. The rc script is explained further in the next section.

The /etc/inittab file includes lines similar to the following to start the services for runlevels 0 through 6. Remember, the second field specifies the runlevel at which the line is executed. The following is from a Red Hat 9.0 system:

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


After the rc scripts finishes, the Linux startup is complete. The /etc/inittab file includes other lines to run getty processes, handle the powerfail condition, and so on. The lines that affect system startup and shutdown are those that run the /etc/rc.d/rc script.

The runlevel can be changed after boot up as well. The root user can move Linux to a different runlevel. The telinit command can be used to tell init to move to a new run-level. For example, the command telinit 5 tells init to move to runlevel 5. The telinit command is just a link to init:

#ls -al /sbin/telinit lrwxrwxrwx    1 root     root        4 Nov  6  2003 /sbin/telinit -> init


Looking at the previous /etc/inittab entries, we can see that the command telinit 5 causes init to execute /etc/rc.d/rc 5. The 5 argument tells /etc/rc.d(or init.d)/rc what runlevel scripts to execute.

The telinit command can also make init look for changes in /etc/inittab. The syntax is telinit q. See the telinit(8) man page for further details.

init errors

If the console shows errors such as the following, init has detected a problem while running a command from /etc/inittab.

INIT: Id "db" respawning too fast: disabled for 5 minutes


In this example, the message corresponds to the following line in /etc/inittab:

db:345:respawn:/usr/local/bin/dbmon


Remember that the respawn keyword in /etc/inittab means that init restarts any command whose process terminates. The previous message means init ran the command ten times, but the command keeps terminating, so init is giving up.

After the problem with the command is fixed, run telinit u to make init try again, or run telinit q if changes have been made to /etc/inittab. The init process logs its messages using the syslog facility,[3] and by default you can find init messages in the /var/log/messages file. The following is a sample message:

Dec 30 10:40:29 sawnee init: Re-reading inittab




Linux Troubleshooting for System Administrators and Power Users
Real World Mac Maintenance and Backups
ISBN: 131855158
EAN: 2147483647
Year: 2004
Pages: 129
Authors: Joe Kissell

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net