Description of the inittab File
Inittab file format:
Label: runlevel: Action: Process
Label:
1 ~ A 4-character tag. It can be a string consisting of any character and represents the input value. Some system labels contain 2 characters. Some specific labels are commonly used. The labels used in Red Hat Linux are:
ID is used to define the default init running level
Si is the process of system initialization.
In LN, N ranges from 1 ~ 6. indicates the runlevel level that can be used by the process.
UD is the upgrading process
CA indicates that the process is running when CTRL + ALT + DEL is pressed.
PF indicates the process that runs when the ups instance is powered off.
PR is the process to run when the ups sends a signal of power recovery before the system is actually shut down.
X is the process to run when the system is transferred to the X terminal.
Runlevel:
Defines the running level when this record item is called. It can be composed of one or more running levels, or it can be empty. If it is null, it indicates the running level 0 ~ 6.
When the init is requested to change the running level, processes that do not include the new running level in the rstate field will receive the sigterm warning signal and finally be killed; only commands started by A, B, and C (A, B, and C are not really running )????Action:
Defines the status of the process, that is, how to process the process specified by the process field.
Code:
Boot only processes such records when the system starts. It starts the corresponding process and ignores runlevel. It does not process the next record item until the processing is complete. When such a process is terminated, the system does not restart it.
After the bootwait system is started, it processes such records when it enters the multi-user mode for the first time from single-user mode. init starts such a process and waits until its processing ends, then the next record item is processed. When such a process is terminated, the system does not restart it.
Ctrlaltdel run when CTRL + ALT + DEL are pressed simultaneously, and the SIGINT signal is sent to init. Ignore runlevel
Initdefault specifies a default running level, which is scanned only when init is called at the beginning. If runlevel
The field specifies multiple running levels. The maximum number is the default running level.
The field is empty, and init considers the field to be 0123456, so it enters Level 6, so it falls into a loop. If the inittab file does not contain the initdefault record item, when the system starts, the user is requested to specify an initial running level for it.
Kbrequest runs when init receives a signal from the keyboard. The keyboard combination is required to comply with keyboardsigral (see/usr/share/doc/KBD-* Documents on the keyboard combination)
Off START process field specified process if the specified process is running, init sends it a sigterm warning signal, wait 5 seconds before it sends a signal sigkill to force it to end, if such a process does not exist, ignore this item.
Once, the next record item will be processed before the processing is completed. When such a process is terminated, it will not be restarted. When it enters the new running level, if such a process is still running, init will not restart it.
The OnDemand function is the same as the respawn function when the system specifies a specific running level A, B, and C.
Powerfail runs when init receives the sigpwr (power-off) Signal
Powerokwait runs when the sigpwd signal is received and the power status in the/etc/file contains OK
Powerwait runs when it receives the sigpwd signal and init waits for the process to end
The respawn restarts the process whenever the process is aborted, And the init continues to scan the subsequent process in the inittab until the start ends. If the process already exists, do nothing.
Sysinit runs before running the boot or bootwait process. The specified process is executed before accessing the console. Such record items are only used for initialization of certain devices, the purpose is to enable init to ask the user about the running level on such a device. init needs to wait until the process finishes running.
Wait starts the process specified by the Process Field and waits until the processing is completed to process the next record in the inittab.
The process field contains the process executed by init. The process adopts the same format as running the process on the command line. Therefore, the Process field starts with the name of the process, it is followed by the parameter to be passed to the process during running. For example,/sbin/shutdown-T3-R now, the process is executed when CTRL + ALT + DEL is pressed. You can also enter it in the command line to restart the system.
The process in the process field can be any waiting process, executable script, or program.
In addition, you can add new record items in the file inittab at any time. Level Q/Q does not change the current running level, and re-check the inittab file, you can run init Q or init Q to re-read the INIT process and process the inittab file.
Special purpose records
Take a closer look at the example file and learn how to apply the syntax format of inittab. Most of the content of this file can be ignored, because more than half of the content is annotated, and the remaining content is mainly used to implement some special functions:
The value of ID indicates that the default runlevel is 3.
The UD value can wake up the/sbin/update process. To ensure the integrity of the disk, the whole I/O buffer is cleared before I/O operations are performed on the disk.
The PF, PR, and Ca values are called only for specific interruptions.
If the system is a dedicated X terminal, only the input value of X is required.
The getty process provides services for virtual terminal devices. For example:
3: 2345: respawn:/sbin/mingetty tty3
The value of the tag field is 3, which is the digital Suffix of the device tty3. tty3 is associated with the corresponding process. The runlevel that the Getty process can start is 2, 3, 4, and 5, when the process is terminated, init immediately restarts it. The name of the startup process is/sbin/mingetty, which is the smallest version of Getty supported by the virtual terminal and provides the process for tty3 to start the virtual device.
Si: sysinit:/etc/rc. d/rc. sysinit
This value tells the INIT program to run/etc/rc. d/RC. the sysinit script file is used to initialize the system. The script file is similar to all started scripts. It is only an executable file containing Linux shell commands, note that the entered string must include the full path of the script. Different Versions of Linux store this script in different locations, but you don't have to remember these locations. You only need to view the/etc/inittab file, this file contains the exact location of the startup script file.
RedHat 9 default initab file content:
Default runlevel
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 a neworking)
3-full multiuser Mode
4-unused
5-X11
6-Reboot halt (do not set initdefault to this)
ID: 5: initdefault:
// By default, the running level of the INIT process is 5 (it cannot be set to 0 or 6, so that the system cannot start)
Si: sysinit:/etc/rc. d/rc. sysinit
// Si is the system initialization process. The INIT program runs the/etc/rc. d/rc. sysinit script file to initialize the system. init will continue to run the next process until the script stops running.
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
// For the corresponding running level, run the script/etc/rc. d/RC, and input the corresponding running level parameter 0 ~ 6
CA: ctrlaltdel:/sbin/shutdown-T3-R now
// Execute shutdown-T3-R now when pressing CTRL + ALT + DEL
PF: powerfail:/sbin/shutdown-f-h + 2
// When the UPS Power Supply prompts a power failure, it will also provide power supply for several minutes, in this case, the system executes shutdown-f-h + 2 (-F indicates that the file system check is skipped during restart)
PR: 12345: powerwait:/shutdown-C
// Cancel the shutdown command being executed when the power supply is restored.
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
// 2345 run level, run the corresponding terminal program
X: 5: respawn:/etc/X11/preofdm-nodaemon
// The program to run in X terminal mode
Linux Automatic startup script
After Linux is started, it runs an INIT program. First, it reads the inittab configuration file and determines the operating mode of the system. When reading inittab, it runs rc0.d ~ Run scripts in the rc6.d directory, and then execute/etc/rc. Local;
Because the rc0.d ~ The run-level script in the rc6.d directory is executed by the/etc/rc. d/RC Script. Let's take a look at this script.
/Etc/rc. d/RC Script description:
#! /Bin/bash
#
# RC this file is responsible for starting/stopping
# Services when the runlevel changes.
#
# Original Author:
# Miquel van smoorenburg, <miquels@drinkel.nl.mugnet.org>
#
# Check a file to be a correct runlevel script
Check_runlevel ()
{
# Check if the file exists at all.
# Determine whether a file exists and can be executed
[-X "$1"] | return 1
# Reject Backup files and files generated by rpm.
# Reject the file name in the backup file format
Case "$1" in
*. Rpmsave | *. rpmorig | *. rpmnew | *~ | *. Orig)
Return 1
;;
Esac
Return 0
}
# Now find out what the current and what the previous runlevel are.
# Obtain the running level, such as/etc/rc. d/RC 0 ~ in inittab ~ 6. The running level is specified. The $1 parameter here is the parameter 0 ~ passed by the command in inittab ~ 6 digits
Argv1 = "$1"
Set '/sbin/runlevel'
Runlevel = $2
Previous = $1
Export runlevel previous
# Set the variable, current run level, last run level
# If there is no previous running level, previous = N
# Load the/etc/init. d/functions script and load the function definitions needed
./Etc/init. d/functions
# See if we want to be in user confirmation Mode
If ["$ previous" = "N"]; then
If [-F/var/run/confirm]/
| Grep-I confirm/proc/cmdline>/dev/NULL; then
Rm-F/var/run/confirm
Confirm = Yes
Export confirm
Echo $ "entering interactive startup"
Else
Echo $ "entering non-interactive startup"
Fi
Fi
# Get first argument. Set new runlevel to this argument.
# If $ argv1 is not an empty string, assign runlevel to the running level specified by argv1
[-N "$ argv1"] & runlevel = "$ argv1"
# Is there an RC directory for this new runlevel?
# If there is no directory for RC ($ runlevel). d at the corresponding level, the program exits.
[-D/etc/rc $ runlevel. d] | exit 0# First, run the kill scripts.
# In the RC ($ runlevel). d directory of the corresponding running level, traverse the files starting with K and retrieve them one by one
# After a series of judgments, execute the script and pass in the Stop Parameter
For I in/etc/rc $ runlevel. d/K *; do
Check_runlevel "$ I" | continue
# Determining whether a file exists
# Check if the subsystem is already up.
Subsys =$ {I #/etc/rc $ runlevel. d/K ??}
[-F/var/lock/subsys/$ subsys-o-F/var/lock/subsys/$ subsys. init]/
| Continue
# Bring the subsystem down.
# Check whether the file contains killproc and action words. If you select "-Q", the input is not displayed and only the status is returned.
# Run the script and pass in the Stop Parameter
If egrep-Q "(killproc | action)" $ I; then
$ I stop
Else
Action $ "Stopping $ subsys:" $ I stop
Fi
Done
# Now run the start scripts.
# Get the file starting with S in the/etc/rc ($ runlevel). d directory
# After checking each file, execute the script and pass in the Start Parameter
For I in/etc/rc $ runlevel. D/S *; do
Check_runlevel "$ I" | continue
# Check if the subsystem is already up.
Subsys =$ {I #/etc/rc $ runlevel. D/S ??}
[-F/var/lock/subsys/$ subsys-o-F/var/lock/subsys/$ subsys. init]/
& Continue
# If we're in confirmation mode, get user confirmation
If [-n "$ confirm"]; then
Confirm $ subsys
Case $? In
0 ):;;
2) Confirm = ;;
*) Continue ;;
Esac
Fi
# Bring the subsystem up.
If ["$ subsys" = "halt"-o "$ subsys" = "reboot"]; then
Export lc_all = C
Exec $ I start
Fi
If egrep-Q "(daemon | action | Success | failure)" $ I 2>/dev/null/
| ["$ Subsys" = "single"-o "$ subsys" = "local"]; then
$ I start
Else
Action $ "Starting $ subsys:" $ I start
Fi
Done
It is not difficult to understand why the above RC Script is used in RC0 ~ 6. The name starts with "S" in the d directory, and the Stop script must start with "RC0 ~ 6. The Directory D should start with K.
I wrote an article about Oracle Auto Start. All the startup scripts start with S, and all the closed scripts start with K. Therefore, if you are writing an Auto Start program, or, when the script of the program is automatically closed, it must meet the naming requirements to be correctly executed.