xref: /freebsd/sbin/init/init.8 (revision d37ea99837e6ad50837fd9fe1771ddf1c3ba6002)
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.  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
127Network secure mode \- same as highly secure mode, plus
128IP packet filter rules (see
129.Xr ipfw 8
130and
131.Xr ipfirewall 4 )
132cannot be changed and
133.Xr dummynet 4
134configuration cannot be adjusted.
135.El
136.Pp
137If the security level is initially nonzero, then
138.Nm
139leaves it unchanged.
140Otherwise,
141.Nm
142raises the level to 1 before going multi-user for the first time.
143Since the level cannot be reduced, it will be at least 1 for
144subsequent operation, even on return to single-user.
145If a level higher than 1 is desired while running multi-user,
146it can be set before going multi-user, e.g., by the startup script
147.Xr rc 8 ,
148using
149.Xr sysctl 8
150to set the
151.Va kern.securelevel
152variable to the required security level.
153.Pp
154If
155.Nm
156is run in a jail, the security level of the
157.Dq host system
158will not be effected.
159Part of the information set up in the kernel to support a jail
160is a per-jail
161.Dq securelevel
162setting.
163This allows running a higher security level inside of a jail
164than that of the host system.
165See
166.Xr jail 8
167for more information about jails.
168.Pp
169In multi-user operation,
170.Nm
171maintains
172processes for the terminal ports found in the file
173.Xr ttys 5 .
174The
175.Nm
176utility reads this file and executes the command found in the second field,
177unless the first field refers to a device in
178.Pa /dev
179which is not configured.
180The first field is supplied as the final argument to the command.
181This command is usually
182.Xr getty 8 ;
183.Nm getty
184opens and initializes the tty line
185and
186executes the
187.Xr login 1
188program.
189The
190.Nm login
191program, when a valid user logs in,
192executes a shell for that user.  When this shell
193dies, either because the user logged out
194or an abnormal termination occurred (a signal),
195the
196.Nm
197utility wakes up, deletes the user
198from the
199.Xr utmp 5
200file of current users and records the logout in the
201.Xr wtmp 5
202file.
203The cycle is
204then restarted by
205.Nm
206executing a new
207.Nm getty
208for the line.
209.Pp
210The
211.Nm
212utility can also be used to keep arbitrary daemons running,
213automatically restarting them if they die.
214In this case, the first field in the
215.Xr ttys 5
216file must not reference the path to a configured device node
217and will be passed to the daemon
218as the final argument on its command line.
219This is similar to the facility offered in the
220.At V
221.Pa /etc/inittab .
222.Pp
223Line status (on, off, secure, getty, or window information)
224may be changed in the
225.Xr ttys 5
226file without a reboot by sending the signal
227.Dv SIGHUP
228to
229.Nm
230with the command
231.Dq Li "kill -HUP 1" .
232On receipt of this signal,
233.Nm
234re-reads the
235.Xr ttys 5
236file.
237When a line is turned off in
238.Xr ttys 5 ,
239.Nm
240will send a SIGHUP signal to the controlling process
241for the session associated with the line.
242For any lines that were previously turned off in the
243.Xr ttys 5
244file and are now on,
245.Nm
246executes the command specified in the second field.
247If the command or window field for a line is changed,
248the change takes effect at the end of the current
249login session (e.g., the next time
250.Nm
251starts a process on the line).
252If a line is commented out or deleted from
253.Xr ttys 5 ,
254.Nm
255will not do anything at all to that line.
256However, it will complain that the relationship between lines
257in the
258.Xr ttys 5
259file and records in the
260.Xr utmp 5
261file is out of sync,
262so this practice is not recommended.
263.Pp
264The
265.Nm
266utility will terminate multi-user operations and resume single-user mode
267if sent a terminate
268.Pq Dv TERM
269signal, for example,
270.Dq Li "kill \-TERM 1" .
271If there are processes outstanding that are deadlocked (because of
272hardware or software failure),
273.Nm
274will not wait for them all to die (which might take forever), but
275will time out after 30 seconds and print a warning message.
276.Pp
277The
278.Nm
279utility will cease creating new processes
280and allow the system to slowly die away, if it is sent a terminal stop
281.Pq Dv TSTP
282signal, i.e.\&
283.Dq Li "kill \-TSTP 1" .
284A later hangup will resume full
285multi-user operations, or a terminate will start a single-user shell.
286This hook is used by
287.Xr reboot 8
288and
289.Xr halt 8 .
290.Pp
291The
292.Nm
293utility will terminate all possible processes (again, it will not wait
294for deadlocked processes) and reboot the machine if sent the interrupt
295.Pq Dv INT
296signal, i.e.\&
297.Dq Li "kill \-INT 1".
298This is useful for shutting the machine down cleanly from inside the kernel
299or from X when the machine appears to be hung.
300.Pp
301The
302.Nm
303utility will do the same, except it will halt the machine if sent
304the user defined signal 1
305.Pq Dv USR1 ,
306or will halt and turn the power off (if hardware permits) if sent
307the user defined signal 2
308.Pq Dv USR2 .
309.Pp
310When shutting down the machine,
311.Nm
312will try to run the
313.Pa /etc/rc.shutdown
314script.
315This script can be used to cleanly terminate specific programs such
316as
317.Nm innd
318(the InterNetNews server).
319.Pp
320The role of
321.Nm
322is so critical that if it dies, the system will reboot itself
323automatically.
324If, at bootstrap time, the
325.Nm
326process cannot be located, the system will panic with the message
327.Dq "panic: init died (signal %d, exit %d)" .
328.Pp
329If run as a user process as shown in the second synopsis line,
330.Nm
331will emulate
332.At V
333behavior, i.e. super-user can specify the desired
334.Em run-level
335on a command line, and
336.Nm
337will signal the original
338(PID 1)
339.Nm
340as follows:
341.Bl -column Run-level SIGTERM
342.It Sy "Run-level	Signal	Action
343.It Cm 0 Ta Dv SIGUSR2 Ta "Halt and turn the power off"
344.It Cm 1 Ta Dv SIGTERM Ta "Go to single-user mode"
345.It Cm 6 Ta Dv SIGINT Ta "Reboot the machine"
346.It Cm c Ta Dv SIGTSTP Ta "Block further logins"
347.It Cm q Ta Dv SIGHUP Ta Rescan the
348.Xr ttys 5
349file
350.El
351.Sh DIAGNOSTICS
352.Bl -diag
353.It "getty repeating too quickly on port %s, sleeping."
354A process being started to service a line is exiting quickly
355each time it is started.
356This is often caused by a ringing or noisy terminal line.
357.Bf -emphasis
358Init will sleep for 30 seconds,
359then continue trying to start the process.
360.Ef
361.It "some processes would not die; ps axl advised."
362A process
363is hung and could not be killed when the system was shutting down.
364This condition is usually caused by a process
365that is stuck in a device driver because of
366a persistent device error condition.
367.El
368.Sh FILES
369.Bl -tag -width /etc/rc.shutdown -compact
370.It Pa /dev/console
371system console device
372.It Pa /dev/tty*
373terminal ports found in
374.Xr ttys 5
375.It Pa /var/run/utmp
376record of current users on the system
377.It Pa /var/log/wtmp
378record of all logins and logouts
379.It Pa /etc/ttys
380the terminal initialization information file
381.It Pa /etc/rc
382system startup commands
383.It Pa /etc/rc.shutdown
384system shutdown commands
385.El
386.Sh SEE ALSO
387.Xr kill 1 ,
388.Xr login 1 ,
389.Xr sh 1 ,
390.Xr dummynet 4 ,
391.Xr ipfirewall 4 ,
392.Xr kld 4 ,
393.Xr ttys 5 ,
394.Xr crash 8 ,
395.Xr getty 8 ,
396.Xr halt 8 ,
397.Xr ipfw 8 ,
398.Xr jail 8 ,
399.Xr rc 8 ,
400.Xr reboot 8 ,
401.Xr shutdown 8 ,
402.Xr sysctl 8
403.Sh HISTORY
404An
405.Nm
406utility appeared in
407.At v6 .
408.Sh CAVEATS
409Systems without
410.Xr sysctl 8
411behave as though they have security level \-1.
412.Pp
413Setting the security level above 1 too early in the boot sequence can
414prevent
415.Xr fsck 8
416from repairing inconsistent file systems.  The
417preferred location to set the security level is at the end of
418.Pa /etc/rc
419after all multi-user startup actions are complete.
420