xref: /netbsd-src/sbin/init/init.8 (revision 8b0f9554ff8762542c4defc4f70e1eb76fb508fa)
1.\"	$NetBSD: init.8,v 1.49 2007/12/09 09:24:55 apb Exp $
2.\"
3.\" Copyright (c) 1980, 1991, 1993
4.\"	The Regents of the University of California.  All rights reserved.
5.\"
6.\" This code is derived from software contributed to Berkeley by
7.\" Donn Seeley at Berkeley Software Design, Inc.
8.\"
9.\" Redistribution and use in source and binary forms, with or without
10.\" modification, are permitted provided that the following conditions
11.\" are met:
12.\" 1. Redistributions of source code must retain the above copyright
13.\"    notice, this list of conditions and the following disclaimer.
14.\" 2. Redistributions in binary form must reproduce the above copyright
15.\"    notice, this list of conditions and the following disclaimer in the
16.\"    documentation and/or other materials provided with the distribution.
17.\" 3. Neither the name of the University nor the names of its contributors
18.\"    may be used to endorse or promote products derived from this software
19.\"    without specific prior written permission.
20.\"
21.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31.\" SUCH DAMAGE.
32.\"
33.\"     @(#)init.8	8.6 (Berkeley) 5/26/95
34.\"
35.Dd December 9, 2007
36.Dt INIT 8
37.Os
38.Sh NAME
39.Nm init
40.Nd process control initialization
41.Sh SYNOPSIS
42.Nm
43.Sh DESCRIPTION
44The
45.Nm
46program is the last stage of the boot process (after the kernel loads
47and initializes all the devices).
48It normally begins multi-user operation.
49.Pp
50The following table describes the state machine used by
51.Nm :
52.Bl -enum
53.It
54Single user shell.
55.Nm
56may be passed
57.Fl s
58from the boot program to prevent the system from going multi-user and
59to instead execute a single user shell without starting the normal
60daemons.
61The system is then quiescent for maintenance work and may
62later be made to go to state 2 (multi-user) by exiting the single-user
63shell (with ^D).
64.It
65Multi-user boot (default operation).
66Executes
67.Pa /etc/rc
68(see
69.Xr rc 8 ) .
70If this was the first state entered (as opposed to entering here after
71state 1), then
72.Pa /etc/rc
73will be invoked with its first argument being
74.Sq autoboot .
75If
76.Pa /etc/rc
77exits with a non-zero (error) exit code, commence single user
78operation by giving the super-user a shell on the console by going
79to state 1 (single user).
80Otherwise, proceed to state 3.
81.Pp
82If value of the
83.Dq init.root
84sysctl node is not equal to
85.Pa /
86at this point, the
87.Pa /etc/rc
88process will be run inside a
89.Xr chroot 2
90indicated by sysctl with the same error handling as above.
91.It
92Set up ttys as specified in
93.Xr ttys 5 .
94See below for more information.
95On completion, continue to state 4.
96If we did chroot in state 2, each
97.Xr getty 8
98process will be run in the same
99.Xr chroot 2
100path as in 2 (that is, the value of
101.Dq init.root
102sysctl is not re-read).
103.It
104Multi-user operation.
105Depending upon the signal received, change state appropriately;
106on
107.Dv SIGTERM ,
108go to state 7;
109on
110.Dv SIGHUP ,
111go to state 5;
112on
113.Dv SIGTSTP ,
114go to state 6.
115.It
116Clean-up mode; re-read
117.Xr ttys 5 ,
118killing off the controlling processes on lines that are now
119.Sq off ,
120and starting processes that are newly
121.Sq on .
122On completion, go to state 4.
123.It
124.Sq Boring
125mode; no new sessions.
126Signals as per state 4.
127.It
128Shutdown mode.
129Send
130.Dv SIGHUP
131to all controlling processes, reap the processes for 30 seconds,
132and then go to state 1 (single user); warning if not all the processes died.
133.El
134.Pp
135If the
136.Sq console
137entry in the
138.Xr ttys 5
139file is marked
140.Dq insecure ,
141then
142.Nm
143will require that the superuser password be
144entered before the system will start a single-user shell.
145The password check is skipped if the
146.Sq console
147is marked as
148.Dq secure .
149.Pp
150It should be noted that while
151.Nm
152has the ability to start multi-user operation inside a
153.Xr chroot 2
154environment, the
155.Nm
156process itself will always run in the
157.Dq original root directory .
158This also implies that single-user mode is always started in the original
159root, giving the possibility to create multi-user sessions in different
160root directories over time.
161The
162.Dq init.root
163sysctl node is fabricated by
164.Nm
165at startup and re-created any time it's found to be missing.
166Type of the node is string capable of holding full pathname, and
167is only accessible by the superuser (unless explicitly destroyed
168and re-created with different specification).
169.Pp
170In multi-user operation,
171.Nm
172maintains
173processes for the terminal ports found in the file
174.Xr ttys 5 .
175.Nm
176reads this file, and executes the command found in the second field.
177This command is usually
178.Xr getty 8 ;
179it opens and initializes the tty line and executes the
180.Xr login 1
181program.
182The
183.Xr login 1
184program, when a valid user logs in, executes a shell for that user.
185When this shell dies, either because the user logged out or an
186abnormal termination occurred (a signal), the
187.Nm
188program wakes up, deletes the user from the
189.Xr utmp 5
190file of current users and records the logout in the
191.Xr wtmp 5
192file.
193The cycle is
194then restarted by
195.Nm
196executing a new
197.Xr getty 8
198for the line.
199.pl +1
200.Pp
201Line status (on, off, secure, getty, or window information)
202may be changed in the
203.Xr ttys 5
204file without a reboot by sending the signal
205.Dv SIGHUP
206to
207.Nm
208with the command
209.Dq Li "kill \-s HUP 1" .
210This is referenced in the table above as state 5.
211On receipt of this signal,
212.Nm
213re-reads the
214.Xr ttys 5
215file.
216When a line is turned off in
217.Xr ttys 5 ,
218.Nm
219will send a
220.Dv SIGHUP
221signal to the controlling process
222for the session associated with the line.
223For any lines that were previously turned off in the
224.Xr ttys 5
225file and are now on,
226.Nm
227executes a new
228.Xr getty 8
229to enable a new login.
230If the getty or window field for a line is changed,
231the change takes effect at the end of the current
232login session (e.g., the next time
233.Nm
234starts a process on the line).
235If a line is commented out or deleted from
236.Xr ttys 5 ,
237.Nm
238will not do anything at all to that line.
239However, it will complain that the relationship between lines
240in the
241.Xr ttys 5
242file and records in the
243.Xr utmp 5
244file is out of sync,
245so this practice is not recommended.
246.Pp
247.Nm
248will terminate multi-user operations and resume single-user mode
249if sent a terminate
250.Pq Dv TERM
251signal, for example,
252.Dq Li "kill \-s TERM 1" .
253If there are processes outstanding that are deadlocked (because of
254hardware or software failure),
255.Nm
256will not wait for them all to die (which might take forever), but
257will time out after 30 seconds and print a warning message.
258.Pp
259.Nm
260will cease creating new
261.Xr getty 8 Ns 's
262and allow the system to slowly die away, if it is sent a terminal stop
263.Pq Dv TSTP
264signal, i.e.
265.Dq Li "kill \-s TSTP 1" .
266A later hangup will resume full
267multi-user operations, or a terminate will start a single user shell.
268This hook is used by
269.Xr reboot 8
270and
271.Xr halt 8 .
272.Pp
273The role of
274.Nm
275is so critical that if it dies, the system will reboot itself
276automatically.
277If, at bootstrap time, the
278.Nm
279process cannot be located, or exits during its initialisation,
280the system will panic with the message
281.Dq panic: init died (signal %d, exit %d) .
282.Pp
283If
284.Pa /dev/console
285does not exist,
286.Nm
287will cd to
288.Pa /dev
289and run
290.Dq Li "MAKEDEV -MM init" .
291.Xr MAKEDEV 8
292will create an
293.Xr mfs 8
294file system mounted over
295.Pa /dev
296that contains the standard devices considered necessary to boot the system.
297.Sh FILES
298.Bl -tag -width /var/log/wtmp -compact
299.It Pa /dev/console
300System console device.
301.It Pa /dev/tty*
302Terminal ports found in
303.Xr ttys 5 .
304.It Pa /var/run/utmp
305Record of Current users on the system.
306.It Pa /var/log/wtmp
307Record of all logins and logouts.
308.It Pa /etc/ttys
309The terminal initialization information file.
310.It Pa /etc/rc
311System startup commands.
312.El
313.Sh DIAGNOSTICS
314.Bl -diag
315.It "getty repeating too quickly on port %s, sleeping"
316A process being started to service a line is exiting quickly
317each time it is started.
318This is often caused by a ringing or noisy terminal line.
319.Em "Init will sleep for 10 seconds" ,
320.Em "then continue trying to start the process" .
321.Pp
322.It "some processes would not die; ps axl advised."
323A process is hung and could not be killed when the system was
324shutting down.
325This condition is usually caused by a process that is stuck in a
326device driver because of a persistent device error condition.
327.El
328.Sh SEE ALSO
329.Xr config 1 ,
330.Xr kill 1 ,
331.Xr login 1 ,
332.Xr sh 1 ,
333.Xr options 4 ,
334.Xr ttys 5 ,
335.Xr MAKEDEV 8 ,
336.Xr MAKEDEV.local 8 ,
337.Xr getty 8 ,
338.Xr halt 8 ,
339.Xr mfs 8 ,
340.Xr rc 8 ,
341.Xr reboot 8 ,
342.Xr shutdown 8 ,
343.Xr sysctl 8 ,
344.Xr secmodel_bsd44 9
345.Sh HISTORY
346A
347.Nm
348command appeared in
349.At v6 .
350