xref: /freebsd/sbin/init/init.8 (revision eda14cbc264d6969b02f2b1994cef11148e914f1)
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. 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 August 6, 2019
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 .
89Note that the password check does not protect from variables
90such as
91.Va init_script
92being set from the
93.Xr loader 8
94command line; see the
95.Sx SECURITY
96section of
97.Xr loader 8 .
98.Pp
99If the system security level (see
100.Xr security 7 )
101is initially nonzero, then
102.Nm
103leaves it unchanged.
104Otherwise,
105.Nm
106raises the level to 1 before going multi-user for the first time.
107Since the level cannot be reduced, it will be at least 1 for
108subsequent operation, even on return to single-user.
109If a level higher than 1 is desired while running multi-user,
110it can be set before going multi-user, e.g., by the startup script
111.Xr rc 8 ,
112using
113.Xr sysctl 8
114to set the
115.Va kern.securelevel
116variable to the required security level.
117.Pp
118If
119.Nm
120is run in a jail, the security level of the
121.Dq host system
122will not be affected.
123Part of the information set up in the kernel to support a jail
124is a per-jail security level.
125This allows running a higher security level inside of a jail
126than that of the host system.
127See
128.Xr jail 8
129for more information about jails.
130.Pp
131In multi-user operation,
132.Nm
133maintains
134processes for the terminal ports found in the file
135.Xr ttys 5 .
136The
137.Nm
138utility reads this file and executes the command found in the second field,
139unless the first field refers to a device in
140.Pa /dev
141which is not configured.
142The first field is supplied as the final argument to the command.
143This command is usually
144.Xr getty 8 ;
145.Nm getty
146opens and initializes the tty line
147and
148executes the
149.Xr login 1
150program.
151The
152.Nm login
153program, when a valid user logs in,
154executes a shell for that user.
155When this shell
156dies, either because the user logged out
157or an abnormal termination occurred (a signal),
158the cycle is restarted by
159executing a new
160.Nm getty
161for the line.
162.Pp
163The
164.Nm
165utility can also be used to keep arbitrary daemons running,
166automatically restarting them if they die.
167In this case, the first field in the
168.Xr ttys 5
169file must not reference the path to a configured device node
170and will be passed to the daemon
171as the final argument on its command line.
172This is similar to the facility offered in the
173.At V
174.Pa /etc/inittab .
175.Pp
176Line status (on, off, secure, getty, or window information)
177may be changed in the
178.Xr ttys 5
179file without a reboot by sending the signal
180.Dv SIGHUP
181to
182.Nm
183with the command
184.Dq Li "kill -HUP 1" .
185On receipt of this signal,
186.Nm
187re-reads the
188.Xr ttys 5
189file.
190When a line is turned off in
191.Xr ttys 5 ,
192.Nm
193will send a SIGHUP signal to the controlling process
194for the session associated with the line.
195For any lines that were previously turned off in the
196.Xr ttys 5
197file and are now on,
198.Nm
199executes the command specified in the second field.
200If the command or window field for a line is changed,
201the change takes effect at the end of the current
202login session (e.g., the next time
203.Nm
204starts a process on the line).
205If a line is commented out or deleted from
206.Xr ttys 5 ,
207.Nm
208will not do anything at all to that line.
209.Pp
210The
211.Nm
212utility will terminate multi-user operations and resume single-user mode
213if sent a terminate
214.Pq Dv TERM
215signal, for example,
216.Dq Li "kill \-TERM 1" .
217If there are processes outstanding that are deadlocked (because of
218hardware or software failure),
219.Nm
220will not wait for them all to die (which might take forever), but
221will time out after 30 seconds and print a warning message.
222.Pp
223The
224.Nm
225utility will cease creating new processes
226and allow the system to slowly die away, if it is sent a terminal stop
227.Pq Dv TSTP
228signal, i.e.\&
229.Dq Li "kill \-TSTP 1" .
230A later hangup will resume full
231multi-user operations, or a terminate will start a single-user shell.
232This hook is used by
233.Xr reboot 8
234and
235.Xr halt 8 .
236.Pp
237The
238.Nm
239utility will terminate all possible processes (again, it will not wait
240for deadlocked processes) and reboot the machine if sent the interrupt
241.Pq Dv INT
242signal, i.e.\&
243.Dq Li "kill \-INT 1".
244This is useful for shutting the machine down cleanly from inside the kernel
245or from X when the machine appears to be hung.
246.Pp
247The
248.Nm
249utility will do the same, except it will halt the machine if sent
250the user defined signal 1
251.Pq Dv USR1 ,
252or will halt and turn the power off (if hardware permits) if sent
253the user defined signal 2
254.Pq Dv USR2 .
255.Pp
256When shutting down the machine,
257.Nm
258will try to run the
259.Pa /etc/rc.shutdown
260script.
261This script can be used to cleanly terminate specific programs such
262as
263.Nm innd
264(the InterNetNews server).
265If this script does not terminate within 120 seconds,
266.Nm
267will terminate it.
268The timeout can be configured via the
269.Xr sysctl 8
270variable
271.Va kern.init_shutdown_timeout .
272.Pp
273.Nm init
274passes
275.Dq Li single
276as the argument to the shutdown script if return to single-user mode
277is requested.
278Otherwise,
279.Dq Li reboot
280argument is used.
281.Pp
282The role of
283.Nm
284is so critical that if it dies, the system will reboot itself
285automatically.
286If, at bootstrap time, the
287.Nm
288process cannot be located, the system will panic with the message
289.Dq "panic: init died (signal %d, exit %d)" .
290.Pp
291If run as a user process as shown in the second synopsis line,
292.Nm
293will emulate
294.At V
295behavior, i.e., super-user can specify the desired
296.Em run-level
297on a command line, and
298.Nm
299will signal the original
300(PID 1)
301.Nm
302as follows:
303.Bl -column Run-level SIGTERM
304.It Sy "Run-level	Signal	Action"
305.It Cm 0 Ta Dv SIGUSR1 Ta "Halt"
306.It Cm 0 Ta Dv SIGUSR2 Ta "Halt and turn the power off"
307.It Cm 0 Ta Dv SIGWINCH Ta "Halt and turn the power off and then back on"
308.It Cm 1 Ta Dv SIGTERM Ta "Go to single-user mode"
309.It Cm 6 Ta Dv SIGINT Ta "Reboot the machine"
310.It Cm c Ta Dv SIGTSTP Ta "Block further logins"
311.It Cm q Ta Dv SIGHUP Ta Rescan the
312.Xr ttys 5
313file
314.El
315.Sh KERNEL ENVIRONMENT VARIABLES
316The following
317.Xr kenv 2
318variables are available as
319.Xr loader 8
320tunables:
321.Bl -tag -width indent
322.It Va init_chroot
323If set to a valid directory in the root file system, it causes
324.Nm
325to perform a
326.Xr chroot 2
327operation on that directory, making it the new root directory.
328That happens before entering single-user mode or multi-user
329mode (but after executing the
330.Va init_script
331if enabled).
332This functionality has generally been eclipsed by rerooting.
333See
334.Xr reboot 8
335.Fl r
336for details.
337.It Va init_exec
338If set to a valid file name in the root file system,
339instructs
340.Nm
341to directly execute that file as the very first action,
342replacing
343.Nm
344as PID 1.
345.It Va init_script
346If set to a valid file name in the root file system,
347instructs
348.Nm
349to run that script as the very first action,
350before doing anything else.
351Signal handling and exit code interpretation is similar to
352running the
353.Pa /etc/rc
354script.
355In particular, single-user operation is enforced
356if the script terminates with a non-zero exit code,
357or if a SIGTERM is delivered to the
358.Nm
359process (PID 1).
360This functionality has generally been eclipsed by rerooting.
361See
362.Xr reboot 8
363.Fl r
364for details.
365.It Va init_shell
366Defines the shell binary to be used for executing the various shell scripts.
367The default is
368.Dq Li /bin/sh .
369It is used for running the
370.Va init_exec
371or
372.Va init_script
373if set, as well as for the
374.Pa /etc/rc
375and
376.Pa /etc/rc.shutdown
377scripts.
378The value of the corresponding
379.Xr kenv 2
380variable is evaluated every time
381.Nm
382calls a shell script, so it can be changed later on using the
383.Xr kenv 1
384utility.
385In particular, if a non-default shell is used for running an
386.Va init_script ,
387it might be desirable to have that script reset the value of
388.Va init_shell
389back to the default, so that the
390.Pa /etc/rc
391script is executed with the standard shell
392.Pa /bin/sh .
393.Sh FILES
394.Bl -tag -width /var/log/init.log -compact
395.It Pa /dev/console
396system console device
397.It Pa /dev/tty*
398terminal ports found in
399.Xr ttys 5
400.It Pa /etc/ttys
401the terminal initialization information file
402.It Pa /etc/rc
403system startup commands
404.It Pa /etc/rc.shutdown
405system shutdown commands
406.It Pa /var/log/init.log
407log of
408.Xr rc 8
409output if the system console device is not available
410.El
411.Sh DIAGNOSTICS
412.Bl -diag
413.It "getty repeating too quickly on port %s, sleeping."
414A process being started to service a line is exiting quickly
415each time it is started.
416This is often caused by a ringing or noisy terminal line.
417.Bf -emphasis
418Init will sleep for 30 seconds,
419then continue trying to start the process.
420.Ef
421.It "some processes would not die; ps axl advised."
422A process
423is hung and could not be killed when the system was shutting down.
424This condition is usually caused by a process
425that is stuck in a device driver because of
426a persistent device error condition.
427.El
428.Sh SEE ALSO
429.Xr kill 1 ,
430.Xr login 1 ,
431.Xr sh 1 ,
432.Xr ttys 5 ,
433.Xr security 7 ,
434.Xr getty 8 ,
435.Xr halt 8 ,
436.Xr jail 8 ,
437.Xr rc 8 ,
438.Xr reboot 8 ,
439.Xr shutdown 8 ,
440.Xr sysctl 8
441.Sh HISTORY
442An
443.Nm
444utility appeared in
445.At v1 .
446.Sh CAVEATS
447Systems without
448.Xr sysctl 8
449behave as though they have security level \-1.
450.Pp
451Setting the security level above 1 too early in the boot sequence can
452prevent
453.Xr fsck 8
454from repairing inconsistent file systems.
455The
456preferred location to set the security level is at the end of
457.Pa /etc/rc
458after all multi-user startup actions are complete.
459