Loading Linux Services The init Process

The init process, which is process number one, is the mother of all processes. After the kernel initializes all of the devices, the init program runs and starts all of the software. The init program is configured by the /etc/inittab file. Listing 1.4 shows the inittab file that comes with Red Hat 7.2:

Listing 1.4: The inittab File

# inittab This file describes how the INIT process should set up

# the system in a certain run-level.

# Author: Miquel van Smoorenburg, <[email protected]>

# Modified for RHS Linux by Marc Ewing and Donnie Barnes

# Default runlevel. The runlevels used by RHS are:

# 2 - Multiuser, without NFS (The same as 3, if you do not have networking)

# 3 - Full multiuser mode

# 6 - reboot (Do NOT set initdefault to this)


# System initialization. si::sysinit:/etc/rc.d/rc.sysinit l0:0:wait:/etc/rc.d/rc 0

# Things to run in every runlevel. ud::once:/sbin/update


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

# When our UPS tells us power has failed, schedule a shutdown for 2 minutes. pf::powerfail:/sbin/shutdown -f -h +2 "Power Failure; System Shutting Down"

# If power was restored before the shutdown, cancel it.

pr:12345:powerokwait:/sbin/shutdown -c "Power Restored; Shutdown Cancelled"

# Run gettys in standard runlevels 1:2345:respawn:/sbin/mingetty ttyl 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

# xdm is now a separate service x:5:respawn:/etc/X11/prefdm -nodaemon

Note The comments in this sample file were edited slightly to better fit on a book page. They are a reduced version of the actual comments from the Red Hat inittab file. Understanding Runlevels

To understand the init process and the inittab file, you need to understand runlevels, which are used to indicate the state of the system when the init process is complete. There is nothing inherent in the system hardware that recognizes runlevels; they are purely a software construct. init and inittab are the only reasons why the runlevels affect the state of the system. Because of this, the way runlevels are used varies from distribution to distribution. This section uses Red Hat Linux as an example.

The Linux startup process is very similar to the startup process used by System V Unix. It is more complex than the initialization on a BSD Unix system, but it is also more flexible. Like System V, Linux defines several runlevels that run the full gamut of possible system states from not-running (halted) to running multiple processes for multiple users. The comments at the beginning of the sample inittab file describe the runlevels:

• Runlevel 0 causes init to shut down all running processes and halt the system.

• Runlevel 1 is used to put the system in single-user mode. Single-user mode is used by the system administrator to perform maintenance that cannot be done when users are logged in. This runlevel may also be indicated by the letter S instead of the number 1.

• Runlevel 2 is a special multiuser mode that supports multiple users but does not support file sharing.

• Runlevel 3 is used to provide full multiuser support with the full range of services. It is the default mode used on servers that use the "text only" console logon.

• Runlevel 4 is unused by the system. You can design your own system state and implement it through runlevel 4.

• Runlevel 5 initializes the system as a dedicated X Windows terminal. This runlevel is widely used as an alternative for systems configured to launch an X desktop environment at startup. In fact, runlevel 5 is the default runlevel for most Red Hat systems because most systems are desktop clients that use an X Windows console logon.

• Runlevel 6 causes init to shut down all running processes and reboot the system.

All of the lines in the inittab file that begin with a sharp sign (#) are comments. A liberal dose of comments is needed to interpret the file because the syntax of actual inittab configuration lines is terse and somewhat arcane. An inittab entry has this general format:


The label is a one- to four-character tag that identifies the entry. Some systems support only two-character labels. For this reason, most people limit all labels to two characters. The labels can be any arbitrary character string, but in practice, certain labels are commonly used. The label for a getty or other login process is usually the numeric suffix of the tty to which the process is attached. Other labels used in the Red Hat Linux distribution are

• id for the line that defines the default runlevel used by init

• si for the system initialization process

• ln where n is a number from 1 to 6 that indicates the runlevel being initialized by this process

• ud for the update process

• ca for the process run when Ctrl+Alt+Del is pressed

• pf for the process run when the UPS indicates a power failure

• pr for the process run when power is restored by the UPS before the system is fully shut down

• x for the process that turns the system into an X terminal

The runlevel field indicates the runlevels to which the entry applies. For example, if the field contains a 3, the process identified by the entry must be run for the system to initialize runlevel 3. More than one runlevel can be specified, as illustrated in the sample file by the pr entry. Entries that have an empty runlevel field are not involved in initializing specific runlevels. For example, an entry that is invoked by a special event, such as the three-finger salute (Ctrl+Alt+Del), does not have a value in the runlevel field.

The action field defines the conditions under which the process is run. Table 1.1 lists all of the valid action values and the meaning of each one.

Table 1.1: Valid Action Values




Runs when the system boots. Ignores runlevel.


Runs when the system boots, and init waits for the process to complete. Runlevels are ignored.


Runs when Ctrl+Alt+Del is pressed, which passes the SIGINT signal to init. Runlevels are ignored.


Doesn't execute a process. It sets the default runlevel.


Runs when init receives a signal from the keyboard. This requires that a key combination be mapped to KeyBoardSignal.


Disables the entry so the process is not run.


Runs one time for every runlevel.


Runs when the system enters one of the special runlevels A, B, or C.


Runs when init receives the SIGPWR signal.


Runs when init receives the SIGPWR signal and the file /etc/ powerstatus contains the word OK.


Runs when init receives the SIGPWR signal, and init waits for the process to complete.


Restarts the process whenever it terminates.


Runs before any boot or bootwait processes.


Runs the process upon entering the run mode, and init waits for the process to complete.

The last field in an inittab entry is the process field. It contains the process that init executes. The process appears in the exact format that is used to execute the process from the command line. Therefore, the process field starts with the name of the process that is to be executed, and follows it with the arguments that will be passed to that process. For example, /sbin/shutdown -t3 -r now, which is the process executed when Ctrl+Alt+Del is pressed, is the same command that could be typed at the shell prompt to reboot the system.

Was this article helpful?

0 0

Post a comment