update NEWS
[manpages-zh.git] / raw / man8 / init.8
blob7885720b339eb735d6700bc4bc321a6adf794d3b
1 .\"{{{}}}
2 .\"{{{  Title
3 .TH INIT 8 "18 April 2003" "" "Linux System Administrator's Manual"
4 .\"}}}
5 .\"{{{  Name
6 .SH NAME
7 init, telinit \- process control initialization
8 .\"}}}
9 .\"{{{  Synopsis
10 .SH SYNOPSIS
11 .B /sbin/init
12 .RB [ " -a " ]
13 .RB [ " -s " ]
14 .RB [ " -b " ]
15 .RB [ " -z xxx " ]
16 .RB [ " 0123456Ss " ]
17 .br
18 .B /sbin/telinit
19 .RB [ " \-t sec " ]
20 .RB [ " 0123456sSQqabcUu " ]
21 .\"}}}
22 .\"{{{  Description
23 .SH DESCRIPTION
24 .\"{{{  init
25 .SS Init
26 .B Init
27 is the parent of all processes.  Its primary role is to create processes
28 from a script stored in the file \fB/etc/inittab\fP (see
29 \fIinittab\fP(5)).  This file usually has entries which cause \fBinit\fP
30 to spawn \fBgetty\fPs on each line that users can log in.  It also
31 controls autonomous processes required by any particular system.
32 .PP
33 .\"{{{ Runlevels
34 .SH RUNLEVELS
35 A \fIrunlevel\fP is a software configuration of the system which allows
36 only a selected group of processes to exist.  The processes spawned by
37 \fBinit\fP for each of these runlevels are defined in the
38 \fB/etc/inittab\fP file.  \fBInit\fP can be in one of eight runlevels:
39 \fB0\(en6\fP and \fBS\fP or \fBs\fP.  The runlevel is
40 changed by having a privileged user run \fBtelinit\fP, which sends
41 appropriate signals to \fBinit\fP, telling it which runlevel to change
42 to.
43 .PP
44 Runlevels \fB0\fP, \fB1\fP, and \fB6\fP are reserved. Runlevel 0 is used to
45 halt the system, runlevel 6 is used to reboot the system, and runlevel
46 1 is used to get the system down into single user mode. Runlevel \fBS\fP
47 is not really meant to be used directly, but more for the scripts that are
48 executed when entering runlevel 1. For more information on this,
49 see the manpages for \fBshutdown\fP(8) and \fBinittab\fP(5).
50 .PP
51 Runlevels 7-9 are also valid, though not really documented. This is
52 because "traditional" Unix variants don't use them.
53 In case you're curious, runlevels \fIS\fP and \fIs\fP are in fact the same.
54 Internally they are aliases for the same runlevel.
55 .\"}}}
56 .PP
57 .SH BOOTING
58 After \fBinit\fP is invoked as the last step of the kernel boot sequence,
59 it looks for the file \fB/etc/inittab\fP to see if there is an entry of the
60 type \fBinitdefault\fP (see \fIinittab\fP(5)). The \fBinitdefault\fP entry
61 determines the initial runlevel of the system.  If there is no such
62 entry (or no \fB/etc/inittab\fP at all), a runlevel must be
63 entered at the system console.
64 .PP
65 Runlevel \fBS\fP or \fBs\fP bring the system to single user mode
66 and do not require an \fB/etc/inittab\fP file.  In single user mode,
67 a root shell is opened on \fB/dev/console\fP.
68 .PP
69 When entering single user mode, \fBinit\fP initializes the consoles
70 \fBstty\fP settings to sane values. Clocal mode is set. Hardware
71 speed and handshaking are not changed.
72 .PP
73 When entering a multi-user mode for the first time, \fBinit\fP performs the
74 \fBboot\fP and \fBbootwait\fP entries to allow file systems to be
75 mounted before users can log in.  Then all entries matching the runlevel
76 are processed.
77 .PP
78 When starting a new process, \fBinit\fP first checks whether the file
79 \fI/etc/initscript\fP exists. If it does, it uses this script to
80 start the process.
81 .PP
82 Each time a child terminates, \fBinit\fP records the fact and the reason
83 it died in \fB/var/run/utmp\fP and \fB/var/log/wtmp\fP,
84 provided that these files exist.
85 .SH CHANGING RUNLEVELS
86 After it has spawned all of the processes specified, \fBinit\fP waits
87 for one of its descendant processes to die, a powerfail signal, or until
88 it is signaled by \fBtelinit\fP to change the system's runlevel.  
89 When one of the above three conditions occurs, it re-examines
90 the \fB/etc/inittab\fP file.  New entries can be added to this file at
91 any time.  However, \fBinit\fP still waits for one of the above three
92 conditions to occur.  To provide for an instantaneous response, the
93 \fBtelinit Q\fP or \fBq\fP command can wake up \fBinit\fP to re-examine the
94 \fB/etc/inittab\fP file.
95 .PP
96 If \fBinit\fP is not in single user mode and receives a powerfail
97 signal (SIGPWR), it reads the file \fB/etc/powerstatus\fP. It then starts
98 a command based on the contents of this file:
99 .IP F(AIL)
100 Power is failing, UPS is providing the power. Execute the \fBpowerwait\fP
101 and \fBpowerfail\fP entries.
102 .IP O(K)
103 The power has been restored, execute the \fBpowerokwait\fP entries.
104 .IP L(OW)
105 The power is failing and the UPS has a low battery. Execute the
106 \fBpowerfailnow\fP entries.
108 If /etc/powerstatus doesn't exist or contains anything else then the
109 letters \fBF\fP, \fBO\fP or \fBL\fP, init will behave as if it has read
110 the letter \fBF\fP.
112 Usage of \fBSIGPWR\fP and \fB/etc/powerstatus\fP is discouraged. Someone
113 wanting to interact with \fBinit\fP should use the \fB/dev/initctl\fP
114 control channel - see the source code of the \fBsysvinit\fP package
115 for more documentation about this.
117 When \fBinit\fP is requested to change the runlevel, it sends the
118 warning signal \s-1\fBSIGTERM\fP\s0 to all processes that are undefined
119 in the new runlevel.  It then waits 5 seconds before forcibly
120 terminating these processes via the \s-1\fBSIGKILL\fP\s0 signal.
121 Note that \fBinit\fP assumes that all these processes (and their
122 descendants) remain in the same process group which \fBinit\fP
123 originally created for them.  If any process changes its process group
124 affiliation it will not receive these signals.  Such processes need to
125 be terminated separately.
126 .\"}}}
127 .\"{{{  telinit
128 .SH TELINIT
129 \fB/sbin/telinit\fP is linked to \fB/sbin/init\fP.  It takes a
130 one-character argument and signals \fBinit\fP to perform the appropriate
131 action.  The following arguments serve as directives to
132 \fBtelinit\fP:
133 .IP "\fB0\fP,\fB1\fP,\fB2\fP,\fB3\fP,\fB4\fP,\fB5\fP or \fB6\fP"
134 tell \fBinit\fP to switch to the specified run level.
135 .IP \fBa\fP,\fBb\fP,\fBc\fP
136 tell \fBinit\fP to process only those \fB/etc/inittab\fP file
137 entries having runlevel \fBa\fP,\fBb\fP or \fBc\fP.
138 .IP "\fBQ\fP or \fBq\fP"
139 tell \fBinit\fP to re-examine the \fB/etc/inittab\fP file.
140 .IP "\fBS\fP or \fBs\fP"
141 tell \fBinit\fP to switch to single user mode.
142 .IP "\fBU\fP or \fBu\fP"
143 tell \fBinit\fP to re-execute itself (preserving the state). No re-examining of 
144 \fB/etc/inittab\fP file happens. Run level should be one of \fBSs12345\fP,
145 otherwise request would be silently ignored.
147 \fBtelinit\fP can also tell \fBinit\fP how long it should wait
148 between sending processes the SIGTERM and SIGKILL signals.  The default
149 is 5 seconds, but this can be changed with the \fB-t sec\fP option.
151 \fBtelinit\fP can be invoked only by users with appropriate
152 privileges.
154 The \fBinit\fP binary checks if it is \fBinit\fP or \fBtelinit\fP by looking
155 at its \fIprocess id\fP; the real \fBinit\fP's process id is always \fB1\fP.
156 From this it follows that instead of calling \fBtelinit\fP one can also
157 just use \fBinit\fP instead as a shortcut.
158 .\"}}}
159 .\"}}}
160 .SH ENVIRONMENT
161 \fBInit\fP sets the following environment variables for all its children:
162 .IP \fBPATH\fP
163 \fI/usr/local/sbin:/sbin:/bin:/usr/sbin:/usr/bin\fP
164 .IP \fBINIT_VERSION\fP
165 As the name says. Useful to determine if a script runs directly from \fBinit\fP.
166 .IP \fBRUNLEVEL\fP
167 The current system runlevel.
168 .IP \fBPREVLEVEL\fP
169 The previous runlevel (useful after a runlevel switch).
170 .IP \fBCONSOLE\fP
171 The system console. This is really inherited from the kernel; however
172 if it is not set \fBinit\fP will set it to \fB/dev/console\fP by default.
173 .SH BOOTFLAGS
174 It is possible to pass a number of flags to \fBinit\fP from the
175 boot monitor (eg. LILO). \fBInit\fP accepts the following flags:
176 .TP 0.5i
177 .B -s, S, single
178 Single user mode boot. In this mode \fI/etc/inittab\fP is
179 examined and the bootup rc scripts are usually run before
180 the single user mode shell is started.
182 .TP 0.5i
183 .B 1-5
184 Runlevel to boot into.
186 .TP 0.5i
187 .B -b, emergency
188 Boot directly into a single user shell without running any
189 other startup scripts.
191 .TP 0.5i
192 .B -a, auto
193 The LILO boot loader adds the word "auto" to the command line if it
194 booted the kernel with the default command line (without user intervention).
195 If this is found \fBinit\fP sets the "AUTOBOOT" environment
196 variable to "yes". Note that you cannot use this for any security
197 measures - of course the user could specify "auto" or \-a on the
198 command line manually.
200 .TP 0.5i
201 .B -z xxx
202 The argument to -z is ignored. You can use this to expand the command
203 line a bit, so that it takes some more space on the stack. \fBInit\fP
204 can then manipulate the command line so that \fBps\fP(1) shows
205 the current runlevel.
207 .SH INTERFACE
208 Init listens on a \fIfifo\fP in /dev, \fI/dev/initctl\fP, for messages.
209 \fBTelinit\fP uses this to communicate with init. The interface is not
210 very well documented or finished. Those interested should study the
211 \fIinitreq.h\fP file in the \fIsrc/\fP subdirectory of the \fBinit\fP
212 source code tar archive.
213 .SH SIGNALS
214 Init reacts to several signals:
215 .TP 0.5i
216 .B SIGHUP
217 Has the same effect as \fBtelinit q\fP.
219 .TP 0.5i
220 .B SIGUSR1
221 On receipt of this signals, init closes and re-opens its control fifo,
222 \fB/dev/initctl\fP. Useful for bootscripts when /dev is remounted.
223 .TP 0.5i
224 .B SIGINT
225 Normally the kernel sends this signal to init when CTRL-ALT-DEL is
226 pressed. It activates the \fIctrlaltdel\fP action.
227 .TP 0.5i
228 .B SIGWINCH
229 The kernel sends this signal when the \fIKeyboardSignal\fP key is hit.
230 It activates the \fIkbrequest\fP action.
231 \"{{{  Conforming to
232 .SH CONFORMING TO
233 \fBInit\fP is compatible with the System V init. It works closely
234 together with the scripts in the directories
235 \fI/etc/init.d\fP and \fI/etc/rc{runlevel}.d\fP.
236 If your system uses this convention, there should be a \fIREADME\fP
237 file in the directory \fI/etc/init.d\fP explaining how these scripts work.
238 .\"}}}
239 .\"{{{  Files
240 .SH FILES
242 /etc/inittab
243 /etc/initscript
244 /dev/console
245 /var/run/utmp
246 /var/log/wtmp
247 /dev/initctl
249 .\"}}}
250 .\"{{{  Warnings
251 .SH WARNINGS
252 \fBInit\fP assumes that processes and descendants of processes
253 remain in the same process group which was originally created
254 for them.  If the processes change their group, \fBinit\fP can't
255 kill them and you may end up with two processes reading from one
256 terminal line.
257 .\"}}}
258 .\"{{{  Diagnostics
259 .SH DIAGNOSTICS
260 If \fBinit\fP finds that it is continuously respawning an entry
261 more than 10 times in 2 minutes, it will assume that there is an error
262 in the command string, generate an error message on the system console,
263 and refuse to respawn this entry until either 5 minutes has elapsed or
264 it receives a signal.  This prevents it from eating up system resources
265 when someone makes a typographical error in the \fB/etc/inittab\fP file
266 or the program for the entry is removed.
267 .\"}}}
268 .\"{{{  Author
269 .SH AUTHOR
270 Miquel van Smoorenburg (miquels@cistron.nl), initial manual
271 page by Michael Haardt (u31b3hs@pool.informatik.rwth-aachen.de).
272 .\"}}}
273 .\"{{{  See also
274 .SH "SEE ALSO"
275 .BR getty (1),
276 .BR login (1),
277 .BR sh (1),
278 .BR runlevel (8),
279 .BR shutdown(8),
280 .BR kill (1),
281 .BR inittab (5),
282 .BR initscript (5),
283 .BR utmp (5)
284 .\"}}}