]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sbin/init/init.8
This commit was generated by cvs2svn to compensate for changes in r55099,
[FreeBSD/FreeBSD.git] / sbin / init / init.8
1 .\" Copyright (c) 1980, 1991, 1993
2 .\"     The Regents of the University of California.  All rights reserved.
3 .\"
4 .\" This code is derived from software contributed to Berkeley by
5 .\" Donn Seeley at Berkeley Software Design, Inc.
6 .\"
7 .\" Redistribution and use in source and binary forms, with or without
8 .\" modification, are permitted provided that the following conditions
9 .\" are met:
10 .\" 1. Redistributions of source code must retain the above copyright
11 .\"    notice, this list of conditions and the following disclaimer.
12 .\" 2. Redistributions in binary form must reproduce the above copyright
13 .\"    notice, this list of conditions and the following disclaimer in the
14 .\"    documentation and/or other materials provided with the distribution.
15 .\" 3. All advertising materials mentioning features or use of this software
16 .\"    must display the following acknowledgement:
17 .\"     This product includes software developed by the University of
18 .\"     California, Berkeley and its contributors.
19 .\" 4. Neither the name of the University nor the names of its contributors
20 .\"    may be used to endorse or promote products derived from this software
21 .\"    without specific prior written permission.
22 .\"
23 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 .\" SUCH DAMAGE.
34 .\"
35 .\"     @(#)init.8      8.3 (Berkeley) 4/18/94
36 .\" $FreeBSD$
37 .\"
38 .Dd April 18, 1994
39 .Dt INIT 8
40 .Os BSD 4
41 .Sh NAME
42 .Nm init
43 .Nd process control initialization
44 .Sh SYNOPSIS
45 .Nm init
46 .Nm init
47 .Oo
48 .Cm 0 | 1 | 6 |
49 .Cm c | q
50 .Oc
51 .Sh DESCRIPTION
52 The
53 .Nm
54 program
55 is the last stage of the boot process.
56 It normally runs the automatic reboot sequence as described in
57 .Xr rc 8 ,
58 and if this succeeds, begins multi-user operation.
59 If the reboot scripts fail,
60 .Nm
61 commences single-user operation by giving
62 the super-user a shell on the console.
63 The
64 .Nm
65 program may be passed parameters
66 from the boot program to
67 prevent the system from going multi-user and to instead execute
68 a single-user shell without starting the normal daemons.
69 The system is then quiescent for maintenance work and may
70 later be made to go to multi-user by exiting the
71 single-user shell (with ^D).
72 This
73 causes
74 .Nm
75 to run the
76 .Pa /etc/rc
77 start up command file in fastboot mode (skipping disk checks).
78 .Pp
79 If the
80 .Em console
81 entry in the
82 .Xr ttys 5
83 file is marked
84 .Dq insecure ,
85 then
86 .Nm
87 will require that the super-user password be
88 entered before the system will start a single-user shell.
89 The password check is skipped if the 
90 .Em console
91 is marked as
92 .Dq secure .
93 .Pp
94 The kernel runs with four different levels of security.
95 Any super-user process can raise the security level, but no process
96 can lower it.
97 The security levels are:
98 .Bl -tag -width flag
99 .It Ic -1
100 Permanently insecure mode \- always run the system in level 0 mode.
101 This is the default initial value.
102 .It Ic 0
103 Insecure mode \- immutable and append-only flags may be turned off.
104 All devices may be read or written subject to their permissions.
105 .It Ic 1
106 Secure mode \- the system immutable and system append-only flags may not 
107 be turned off;
108 disks for mounted filesystems,
109 .Pa /dev/mem ,
110 and
111 .Pa /dev/kmem
112 may not be opened for writing.
113 .It Ic 2
114 Highly secure mode \- same as secure mode, plus disks may not be
115 opened for writing (except by
116 .Xr mount 2 )
117 whether mounted or not.
118 This level precludes tampering with filesystems by unmounting them,
119 but also inhibits running
120 .Xr newfs 8
121 while the system is multi-user.
122 .Pp
123 In addition, kernel time changes are restricted to less than or equal to one
124 second.  Attempts to change the time by more than this will log the message
125 .Dq Time adjustment clamped to +1 second .
126 .It Ic 3
127 Network secure mode \- same as highly secure mode, plus
128 IP packet filter rules (see
129 .Xr ipfw 8
130 and
131 .Xr ipfirewall 4 )
132 cannot be changed and
133 .Xr dummynet 4
134 configuration cannot be adjusted.
135 .El
136 .Pp
137 If the security level is initially -1, then
138 .Nm
139 leaves it unchanged.
140 Otherwise,
141 .Nm
142 arranges to run the system in level 0 mode while single-user
143 and in level 1 mode while multi-user.
144 If level 2 mode is desired while running multi-user,
145 it can be set while single-user, e.g., in the startup script
146 .Pa /etc/rc ,
147 using
148 .Xr sysctl 8 
149 to set the 
150 .Dq kern.securelevel
151 variable to the required security level.  
152 .Pp
153 In multi-user operation, 
154 .Nm
155 maintains
156 processes for the terminal ports found in the file
157 .Xr ttys 5 .
158 .Nm Init
159 reads this file and executes the command found in the second field,
160 unless the first field refers to a device in
161 .Pa /dev
162 which is not configured.
163 The first field is supplied as the final argument to the command.
164 This command is usually
165 .Xr getty 8 ;
166 .Nm getty
167 opens and initializes the tty line
168 and
169 executes the
170 .Xr login 1
171 program.
172 The
173 .Nm login
174 program, when a valid user logs in,
175 executes a shell for that user.  When this shell
176 dies, either because the user logged out
177 or an abnormal termination occurred (a signal),
178 the
179 .Nm
180 program wakes up, deletes the user
181 from the
182 .Xr utmp 5
183 file of current users and records the logout in the
184 .Xr wtmp 5
185 file.
186 The cycle is
187 then restarted by
188 .Nm
189 executing a new
190 .Nm getty
191 for the line.
192 .Pp
193 .Nm Init
194 can also be used to keep arbitrary daemons running,
195 automatically restarting them if they die.
196 In this case, the first field in the
197 .Xr ttys 5
198 file must not reference the path to a configured device node
199 and will be passed to the daemon
200 as the final argument on its command line.
201 This is similar to the facility offered in the
202 .At V
203 .Pa /etc/inittab .
204 .Pp
205 Line status (on, off, secure, getty, or window information)
206 may be changed in the
207 .Xr ttys 5
208 file without a reboot by sending the signal
209 .Dv SIGHUP
210 to
211 .Nm
212 with the command
213 .Dq Li "kill -HUP 1" .
214 On receipt of this signal,
215 .Nm
216 re-reads the
217 .Xr ttys 5
218 file.
219 When a line is turned off in
220 .Xr ttys 5 ,
221 .Nm
222 will send a SIGHUP signal to the controlling process
223 for the session associated with the line.
224 For any lines that were previously turned off in the
225 .Xr ttys 5
226 file and are now on,
227 .Nm
228 executes the command specified in the second field.
229 If the command or window field for a line is changed,
230 the change takes effect at the end of the current
231 login session (e.g., the next time 
232 .Nm
233 starts a process on the line).
234 If a line is commented out or deleted from
235 .Xr ttys 5 ,
236 .Nm
237 will not do anything at all to that line.
238 However, it will complain that the relationship between lines
239 in the
240 .Xr ttys 5
241 file and records in the
242 .Xr utmp 5
243 file is out of sync,
244 so this practice is not recommended.
245 .Pp
246 .Nm Init
247 will terminate multi-user operations and resume single-user mode
248 if sent a terminate
249 .Pq Dv TERM
250 signal, for example,
251 .Dq Li "kill \-TERM 1" .
252 If there are processes outstanding that are deadlocked (because of
253 hardware or software failure),
254 .Nm
255 will not wait for them all to die (which might take forever), but
256 will time out after 30 seconds and print a warning message.
257 .Pp
258 .Nm Init
259 will cease creating new processes
260 and allow the system to slowly die away, if it is sent a terminal stop
261 .Pq Dv TSTP
262 signal, i.e.
263 .Dq Li "kill \-TSTP 1" .
264 A later hangup will resume full
265 multi-user operations, or a terminate will start a single-user shell.
266 This hook is used by
267 .Xr reboot 8
268 and
269 .Xr halt 8 .
270 .Pp
271 .Nm Init
272 will terminate all possible processes (again, it will not wait
273 for deadlocked processes) and reboot the machine if sent the interrupt
274 .Pq Dv INT
275 signal, i.e.
276 .Dq Li "kill \-INT 1".
277 This is useful for shutting the machine down cleanly from inside the kernel
278 or from X when the machine appears to be hung.
279 .Pp
280 .Nm Init
281 will do the same, except it will halt the machine if sent
282 the user defined signal 1
283 .Pq Dv USR1 ,
284 or will halt and turn the power off (if hardware permits) if sent
285 the user defined signal 2
286 .Pq Dv USR2 .
287 .Pp
288 When shutting down the machine,
289 .Nm
290 will try to run the
291 .Pa /etc/rc.shutdown
292 script. This script can be used to cleanly terminate specific programs such
293 as
294 .Nm innd
295 (the InterNetNews server).
296 .Pp
297 The role of
298 .Nm
299 is so critical that if it dies, the system will reboot itself
300 automatically.
301 If, at bootstrap time, the
302 .Nm
303 process cannot be located, the system will panic with the message
304 .Dq "panic: init died (signal %d, exit %d)" .
305 .Pp
306 If run as a user process as shown in the second synopsis line,
307 .Nm
308 will emulate
309 .At V
310 behavior, i.e. super-user can specify the desired
311 .Em run-level
312 on a command line, and
313 .Nm
314 will signal the original
315 .Pq PID 1
316 .Nm
317 as follows:
318 .Bl -column Run-level SIGTERM
319 .It Sy Run-level        Signal  Action
320 .It Cm 0 Ta Dv SIGUSR2 Ta "Halt and turn the power off"
321 .It Cm 1 Ta Dv SIGTERM Ta "Go to single-user mode"
322 .It Cm 6 Ta Dv SIGINT Ta "Reboot the machine"
323 .It Cm c Ta Dv SIGTSTP Ta "Block further logins"
324 .It Cm q Ta Dv SIGHUP Ta Rescan the
325 .Xr ttys 5
326 file
327 .El
328 .Sh DIAGNOSTICS
329 .Bl -diag
330 .It "getty repeating too quickly on port %s, sleeping"
331 A process being started to service a line is exiting quickly
332 each time it is started.
333 This is often caused by a ringing or noisy terminal line.
334 .Em "Init will sleep for 30 seconds" ,
335 .Em "then continue trying to start the process" .
336 .Pp
337 .It "some processes would not die; ps axl advised."
338 A process
339 is hung and could not be killed when the system was shutting down.
340 This condition is usually caused by a process
341 that is stuck in a device driver because of
342 a persistent device error condition.
343 .El
344 .Sh FILES
345 .Bl -tag -width /etc/rc.shutdown -compact
346 .It Pa /dev/console
347 system console device
348 .It Pa /dev/tty*
349 terminal ports found in
350 .Xr ttys 5
351 .It Pa /var/run/utmp
352 record of current users on the system
353 .It Pa /var/log/wtmp
354 record of all logins and logouts
355 .It Pa /etc/ttys
356 the terminal initialization information file
357 .It Pa /etc/rc
358 system startup commands
359 .It Pa /etc/rc.shutdown
360 system shutdown commands
361 .El
362 .Sh SEE ALSO
363 .Xr kill 1 ,
364 .Xr login 1 ,
365 .Xr sh 1 ,
366 .Xr dummynet 4 ,
367 .Xr ipfirewall 4 ,
368 .Xr ttys 5 ,
369 .Xr crash 8 ,
370 .Xr getty 8 ,
371 .Xr halt 8 ,
372 .Xr ipfw 8 ,
373 .Xr rc 8 ,
374 .Xr reboot 8 ,
375 .Xr shutdown 8 ,
376 .Xr sysctl 8
377 .Sh HISTORY
378 An
379 .Nm
380 command appeared in
381 .At v6 .
382 .Sh CAVEATS
383 Systems without
384 .Xr sysctl
385 behave as though they have security level \-1.
386 .Pp
387 Setting the security level above 1 too early in the boot sequence can 
388 prevent 
389 .Xr fsck 8 
390 from repairing inconsistent filesystems.  The 
391 preferred location to set the security level is at the end of 
392 .Pa /etc/rc 
393 after all multi-user startup actions are complete.