Tuesday, July 12, 2011

inittab file and the init process

A, init process
(1) init is started by the kernel user-level process, the kernel starts (has been loaded into memory, running, and has initialized all device drivers and data structures, etc.), you start a user-level programs through init way to start other user-level process or service. So init is always the first process (the PID is always: 1 ), all the parent process. init program through / etc / inittab configuration file
(2) the kernel will be used in the past init in several places to find it, it's the correct position (on Linuxsystems) is / sbin / init. If the kernel can not find init , it will try to run / bin / SH , if you fail, the system will fail to start
Two, / etc / inittab file Detailed
Content format ( 4 -stage): Label: runlevel: action: command (Process)
label
label registration key identifier is an arbitrary specified ( 1-4 ) character sequence label, in this document must be unique, some systems support only 2 -character labels. For this reason, most people will label the number of characters limited to 2 months or less. The label can be any character string, but in fact, certain labels are used, in red Hat Linux using the label as follows:
id
Used to define the default init run level
si
Is the system initialization process
ln
Where from 1 to 6, indicating that the process can use runlevel level
ud
The upgrade process
ca
Specified when you press the Ctrl + Alt + Del is a running process
pf
Means that when the UPS power to run the process that
pr
Before the system is really close, UPS issued a signal when power is restored to run the process
x
Is the system into X terminals to run the process

runlevel
1 ) to effectively meet the system run level configuration of the process
2 ) by the init command to start each process is assigned one or more of the process can be found in the runlevel
3 ) run level from 0-9 to indicate the number
a. 
If the system is in run level 1 , only in the run level field are 1 of those entries is started 
b.
 If the run level field is empty, then those entries will be applied all run-level start system
4 ) request init to change run levels so that when the entry in the runlevel field does not match the target run level all processes will receive a warning signal (SIGTERM) , in the process of being removed symbol [ kill Signal (SIGKILL)] forced termination ago, 20 -second grace period
5 ) run level field can define multiple run levels of a process can be 0-9 in any combination. If no run level is specified, the process is assumed valid at all run levels
6 ) other four values ​​will appear in the runlevel field, even if they are not true run levels: a, b, c and H . In the run level field entries of these characters only in the telinit command requests them to be run (with the current system runlevel). They differ from init command's run level, init command can never enter a, b, c, h run level. And all of these processes are not running the request to change the current run level. In addition, init command to change the level, by a, b, c command to start the process does not disconnect ( killed ). Only when the / etc / inittab file line in their action field is marked off , their line from / etc / inittab file is completely deleted, or init command to enter single user mode, these processes will be interrupted ( killed )
Note: The field specifies the runlevel level. You can specify more than one runlevel level, you can not runlevel field to specify a particular value

action 
(role: inform the init command how to handle the process field to specify the process)
1 ) respawnif the process does not exist, start the process. Do not wait for process termination (continue scanning the / etc / inittab file). If it dies, then restart the process. If the process exists, continue scanning the / etc / inittab file
For example: "5:2345: respawn: / sbin / mingetty TTY5 "
Explained: init will open a local terminal, when the terminal over time no one login or too long no one keystroke, this terminal will not be executed, respawn that tells init re-run the terminal, otherwise, after a period of time We will find that this terminal is gone, can not use ALT + F5 switch
2 ) waitwhen the init command to enter matches the entry's run level, start the process and wait for the process to terminate. When the init command in the same run level, all of the / etc / inittab file will cause the next read init command to ignore this entry
3 ) oncewhen the init command to enter matches the entry's run level, start the process, and do not wait for the termination. When it dies, do not restart the process. When the system enters a new run level, the process continues from the previous run level change operation, do not restart the program
4 ) bootonly run during system boot entry, these processes are system startup, init command from / etc / inittab file to read, so runlevel value of its invalid. Start the process, do not wait for its termination, and the process dies, do not restart the process. Meaningful guidance followed, should be the default run level, or it must boot init command's run level match. This action restarts the system after the hardware initialization is useful
5 ) bootwaitsystem boot, init command from a single user to multi-user state, the first run of the entries. Start the process, and so its end, the process dies, do not restart the process. If the initdefault is 2 , the system is run directly after the boot process
6 ) powerfailonly when the init command receives a power fail signal (SIGPWr) only when the implementation process associated with this entry, but init will not wait for the end of the process is running ( rH Linux default this option is not listed)
7 ) powerwaitonly when the init command receives a power fail signal (SIGPWr) only when the implementation process associated with this entry, to close the system (of course, provided there is UPS and monitor UPS and informs init software power has been cut off ), and so the process terminates before continuing to process / etc / inittab file ( rH Linux default this option is not listed)
8 ) off
if the process associated with this entry is currently running, send a warning signal (SIGTERM) , then wait 20 seconds before kill signal ( SIGKILL ) to terminate the process. If the process is not running, ignore this entry
9 ) OnDemand
functionality and respawn the same, but this action application a, b, or c values, instead of run level
10 ) initdefault
init 
command is initially invoked when scanning with this action -related entries. If there is, init command uses this entry to determine the initial run level to enter, due to enter the corresponding run level will activate the corresponding level of process, so its designated process field has no meaning. Under normal circumstances, the use of run-level field, the highest run level specified as the initial state. If the run level field is empty, this is interpreted as 0123456789 ; Thus, init command enters run level 9 . In addition, if the init command in the / etc / inittab file not found initdefault entry in the guide when the user requests an initial run level
11 ) sysinit
this type of entries in the registry before the init command tries to access the console before being executed. The entry is only used to initialize the device, init command for these devices may ask the run level. These entries are executed, and wait to complete before continuing
12 ) CtrlAltDel
user at the console keyboard, press Ctrl + Alt + Del key combination, allow init to restart the system 
Note: If the system is in a public place, the system administrator can Ctrl + Alt + Del key combination to configure the other behavior, such as neglect, etc.
13 ) kbrequest
monitor to a specific keyboard combination is pressed to take action, now is not perfect


command
Should execute specific commands. Example, the figure in the / etc / init.d / rc command to start running level 2 processes should be run / command, and is responsible for the exit to terminate when run level (of course, enter the runlevel except in the program still running) . When the run level changes, and running the program does not run in the new run level is specified, then init will first send a SIGTErM signal termination, thenSIGKILL 2

inittab file as follows: 
# inittab          This file describes how the INIT Process should set up 
the System in a certain run-level. # Author: Miquel van Smoorenburg, miquels@drinkel.nl.mugnet.org Modified for RHS Linux by Marc Ewing and Donnie Barnes # Default runlevel. The runlevels used by RHS are: 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 networking) 3 - Full Multiuser mode 4 - unused 5 - X11 6 - reboot (Do NOT set initdefault to this) ID: 3: initdefault: # System initialization. Company:: sysinit: / etc / rc.d / rc.sysinit 10: 0: wait: / etc / rc.d / rc0l1:1: wait: / etc / rc.d / rc 1l2:2: wait: / etc / rc.d / rc 2l3:3: wait: / etc / rc.d / rc 3l4:4: wait: / etc / rc.d / rc 4l5:5: wait: / etc / rc.d / rc 5l6:6: wait: / etc / rc.d / rc 6 # Things to run in every runlevel ud:: once: / sbin / Update # Trap CTRL-ALT-DELETE ca:: CtrlAltDel: / sbin / shutdown-T3 - R now # When our UPS tells U.S. Power has failed, ASSUME We have a few minutes # of Power left. Schedule a shutdown for 2 minutes from now. # This does, of Course, Powerd ASSUME you have installed and your # UPS Connected and Working correctly. PF:: powerfail: / sbin / shutdown-f-H +2 "Power Failure; System Shutting Down" # If Power was restored before the shutdown kicked in, Cancel it. PR: 12345: powerokwait: / sbin / shutdown -c "Power restored; Shutdown Cancelled" # If Power was restored before the shutdown kicked in, Cancel it. PR: 12345: powerokwait: / sbin / shutdown-c "Power restored; Shutdown Cancelled" # run gettys runlevels in Standard 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
                           
  
Note: Case file comments are edited, in order to maintain the written consistency
[Understand runlevel ]

runlevel --- 
used to represent the init process after the end of the system state, the system's hardware is not fixed information that runlevel , it is simply a software architecture. init and inittab is runlevel affect the system state the only reason. In the above example inittab file comments in the initial stage is mainly used to describe the runlevel : 1 ) runlevel = 0 to init the system shut down and terminate all processes

2 ) runlevel = 1single-user mode, only the system administrator to enter in this mode have to deal with those in the case of logged-on user can not change the file, change the runlevel number one can also use the S or a single purpose: only minimal services running, so the run-level is often used for system maintenance

3 ) runlevel = 2multi-user mode, but does not support file sharing, this model is rarely used

4 ) runlevel = 3multi-user mode, but does support file sharing, but also the most server's default mode

5 ) runlevel = 4is generally not used by the system, users can design their own system state and apply it to runlevel 4 stages, although rarely used, but the use of the system can achieve some specific logon request

6 ) runlevel = 5the system is initialized to a dedicated X Window terminal. Of a powerful Linux system, this is not a good choice, but the user if desired so, it can be in runlevel start to implement the program

7 ) runlevel = 6Close all running processes and restart the system

process
This field contains the init execution process, which uses the format of the command line to run the process under the same format, so the process to the field are beginning the process name, followed by a run, followed by a run-time to passed to the process parameters. Such as / sbin / shutdown-T3-R now , the process by pressing Ctrl + Alt + Del is executed, the command line can also enter to restart the system