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