xref: /freebsd/sbin/init/init.8 (revision 4cf49a43559ed9fdad601bdcccd2c55963008675)
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
52The
53.Nm
54program
55is the last stage of the boot process.
56It normally runs the automatic reboot sequence as described in
57.Xr rc 8 ,
58and if this succeeds, begins multi-user operation.
59If the reboot scripts fail,
60.Nm
61commences single-user operation by giving
62the super-user a shell on the console.
63The
64.Nm
65program may be passed parameters
66from the boot program to
67prevent the system from going multi-user and to instead execute
68a single-user shell without starting the normal daemons.
69The system is then quiescent for maintenance work and may
70later be made to go to multi-user by exiting the
71single-user shell (with ^D).
72This
73causes
74.Nm
75to run the
76.Pa /etc/rc
77start up command file in fastboot mode (skipping disk checks).
78.Pp
79If the
80.Em console
81entry in the
82.Xr ttys 5
83file is marked
84.Dq insecure ,
85then
86.Nm
87will require that the super-user password be
88entered before the system will start a single-user shell.
89The password check is skipped if the
90.Em console
91is marked as
92.Dq secure .
93.Pp
94The kernel runs with four different levels of security.
95Any super-user process can raise the security level, but no process
96can lower it.
97The security levels are:
98.Bl -tag -width flag
99.It Ic -1
100Permanently insecure mode \- always run the system in level 0 mode.
101This is the default initial value.
102.It Ic 0
103Insecure mode \- immutable and append-only flags may be turned off.
104All devices may be read or written subject to their permissions.
105.It Ic 1
106Secure mode \- the system immutable and system append-only flags may not
107be turned off;
108disks for mounted filesystems,
109.Pa /dev/mem ,
110and
111.Pa /dev/kmem
112may not be opened for writing.
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 filesystems by unmounting them,
119but also inhibits running
120.Xr newfs 8
121while the system is multi-user.
122.It Ic 3
123Network secure mode \- same as highly secure mode, plus
124IP packet filter rules (see
125.Xr ipfw 8
126and
127.Xr ipfirewall 4 )
128cannot be changed and
129.Xr dummynet 4
130configuration cannot be adjusted.
131.El
132.Pp
133If the security level is initially -1, then
134.Nm
135leaves it unchanged.
136Otherwise,
137.Nm
138arranges to run the system in level 0 mode while single-user
139and in level 1 mode while multi-user.
140If level 2 mode is desired while running multi-user,
141it can be set while single-user, e.g., in the startup script
142.Pa /etc/rc ,
143using
144.Xr sysctl 8
145to set the
146.Dq kern.securelevel
147variable to the required security level.
148.Pp
149In multi-user operation,
150.Nm
151maintains
152processes for the terminal ports found in the file
153.Xr ttys 5 .
154.Nm Init
155reads this file, and executes the command found in the second field.
156This command is usually
157.Xr getty 8 ;
158.Nm getty
159opens and initializes the tty line
160and
161executes the
162.Xr login 1
163program.
164The
165.Nm login
166program, when a valid user logs in,
167executes a shell for that user.  When this shell
168dies, either because the user logged out
169or an abnormal termination occurred (a signal),
170the
171.Nm
172program wakes up, deletes the user
173from the
174.Xr utmp 5
175file of current users and records the logout in the
176.Xr wtmp 5
177file.
178The cycle is
179then restarted by
180.Nm
181executing a new
182.Nm getty
183for the line.
184.Pp
185Line status (on, off, secure, getty, or window information)
186may be changed in the
187.Xr ttys 5
188file without a reboot by sending the signal
189.Dv SIGHUP
190to
191.Nm
192with the command
193.Dq Li "kill -HUP 1" .
194On receipt of this signal,
195.Nm
196re-reads the
197.Xr ttys 5
198file.
199When a line is turned off in
200.Xr ttys 5 ,
201.Nm
202will send a SIGHUP signal to the controlling process
203for the session associated with the line.
204For any lines that were previously turned off in the
205.Xr ttys 5
206file and are now on,
207.Nm
208executes a new
209.Nm getty
210to enable a new login.
211If the getty or window field for a line is changed,
212the change takes effect at the end of the current
213login session (e.g., the next time
214.Nm
215starts a process on the line).
216If a line is commented out or deleted from
217.Xr ttys 5 ,
218.Nm
219will not do anything at all to that line.
220However, it will complain that the relationship between lines
221in the
222.Xr ttys 5
223file and records in the
224.Xr utmp 5
225file is out of sync,
226so this practice is not recommended.
227.Pp
228.Nm Init
229will terminate multi-user operations and resume single-user mode
230if sent a terminate
231.Pq Dv TERM
232signal, for example,
233.Dq Li "kill \-TERM 1" .
234If there are processes outstanding that are deadlocked (because of
235hardware or software failure),
236.Nm
237will not wait for them all to die (which might take forever), but
238will time out after 30 seconds and print a warning message.
239.Pp
240.Nm Init
241will cease creating new
242.Nm getty Ns 's
243and allow the system to slowly die away, if it is sent a terminal stop
244.Pq Dv TSTP
245signal, i.e.
246.Dq Li "kill \-TSTP 1" .
247A later hangup will resume full
248multi-user operations, or a terminate will start a single-user shell.
249This hook is used by
250.Xr reboot 8
251and
252.Xr halt 8 .
253.Pp
254.Nm Init
255will terminate all possible processes (again, it will not wait
256for deadlocked processes) and reboot the machine if sent the interrupt
257.Pq Dv INT
258signal, i.e.
259.Dq Li "kill \-INT 1".
260This is useful for shutting the machine down cleanly from inside the kernel
261or from X when the machine appears to be hung.
262.Pp
263.Nm Init
264will do the same, except it will halt the machine if sent
265the user defined signal 1
266.Pq Dv USR1 ,
267or will halt and turn the power off (if hardware permits) if sent
268the user defined signal 2
269.Pq Dv USR2 .
270.Pp
271When shutting down the machine,
272.Nm
273will try to run the
274.Pa /etc/rc.shutdown
275script. This script can be used to cleanly terminate specific programs such
276as
277.Nm innd
278(the InterNetNews server).
279.Pp
280The role of
281.Nm
282is so critical that if it dies, the system will reboot itself
283automatically.
284If, at bootstrap time, the
285.Nm
286process cannot be located, the system will panic with the message
287.Dq "panic: init died (signal %d, exit %d)" .
288.Pp
289If run as a user process as shown in the second synopsis line,
290.Nm
291will emulate
292.At V
293behavior, i.e. super-user can specify the desired
294.Em run-level
295on a command line, and
296.Nm
297will signal the original
298.Pq PID 1
299.Nm
300as follows:
301.Bl -column Run-level SIGTERM
302.It Sy Run-level	Signal	Action
303.It Cm 0 Ta Dv SIGUSR2 Ta "Halt and turn the power off"
304.It Cm 1 Ta Dv SIGTERM Ta "Go to single-user mode"
305.It Cm 6 Ta Dv SIGINT Ta "Reboot the machine"
306.It Cm c Ta Dv SIGTSTP Ta "Block further logins"
307.It Cm q Ta Dv SIGHUP Ta Rescan the
308.Xr ttys 5
309file
310.El
311.Sh DIAGNOSTICS
312.Bl -diag
313.It "getty repeating too quickly on port %s, sleeping"
314A process being started to service a line is exiting quickly
315each time it is started.
316This is often caused by a ringing or noisy terminal line.
317.Em "Init will sleep for 30 seconds" ,
318.Em "then continue trying to start the process" .
319.Pp
320.It "some processes would not die; ps axl advised."
321A process
322is hung and could not be killed when the system was shutting down.
323This condition is usually caused by a process
324that is stuck in a device driver because of
325a persistent device error condition.
326.El
327.Sh FILES
328.Bl -tag -width /etc/rc.shutdown -compact
329.It Pa /dev/console
330system console device
331.It Pa /dev/tty*
332terminal ports found in
333.Xr ttys 5
334.It Pa /var/run/utmp
335record of current users on the system
336.It Pa /var/log/wtmp
337record of all logins and logouts
338.It Pa /etc/ttys
339the terminal initialization information file
340.It Pa /etc/rc
341system startup commands
342.It Pa /etc/rc.shutdown
343system shutdown commands
344.El
345.Sh SEE ALSO
346.Xr kill 1 ,
347.Xr login 1 ,
348.Xr sh 1 ,
349.Xr dummynet 4 ,
350.Xr ipfirewall 4 ,
351.Xr ttys 5 ,
352.Xr crash 8 ,
353.Xr getty 8 ,
354.Xr halt 8 ,
355.Xr ipfw 8 ,
356.Xr rc 8 ,
357.Xr reboot 8 ,
358.Xr shutdown 8 ,
359.Xr sysctl 8
360.Sh HISTORY
361An
362.Nm
363command appeared in
364.At v6 .
365.Sh CAVEATS
366Systems without
367.Xr sysctl
368behave as though they have security level \-1.
369.Pp
370Setting the security level above 1 too early in the boot sequence can
371prevent
372.Xr fsck 8
373from repairing inconsistent filesystems.  The
374preferred location to set the security level is at the end of
375.Pa /etc/rc
376after all multi-user startup actions are complete.
377