xref: /netbsd-src/sbin/init/init.8 (revision f82d7874c259b2a6cc59b714f844919f32bf7b51)
1.\"	$NetBSD: init.8,v 1.52 2008/02/09 04:50:57 dholland 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 February 8, 2008
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
190and
191.Xr utmpx 5
192files of current users and records the logout in the
193.Xr wtmp 5
194and
195.Xr wtmpx 5
196files.
197The cycle is
198then restarted by
199.Nm
200executing a new
201.Xr getty 8
202for the line.
203.pl +1
204.Pp
205Line status (on, off, secure, getty, or window information)
206may be changed in the
207.Xr ttys 5
208file without a reboot by sending the signal
209.Dv SIGHUP
210to
211.Nm
212with the command
213.Dq Li "kill \-s HUP 1" .
214This is referenced in the table above as state 5.
215On receipt of this signal,
216.Nm
217re-reads the
218.Xr ttys 5
219file.
220When a line is turned off in
221.Xr ttys 5 ,
222.Nm
223will send a
224.Dv SIGHUP
225signal to the controlling process
226for the session associated with the line.
227For any lines that were previously turned off in the
228.Xr ttys 5
229file and are now on,
230.Nm
231executes a new
232.Xr getty 8
233to enable a new login.
234If the getty or window field for a line is changed,
235the change takes effect at the end of the current
236login session (e.g., the next time
237.Nm
238starts a process on the line).
239If a line is commented out or deleted from
240.Xr ttys 5 ,
241.Nm
242will not do anything at all to that line.
243However, it will complain that the relationship between lines
244in the
245.Xr ttys 5
246file and records in the
247.Xr utmp 5
248file is out of sync,
249so this practice is not recommended.
250.Pp
251.Nm
252will terminate multi-user operations and resume single-user mode
253if sent a terminate
254.Pq Dv TERM
255signal, for example,
256.Dq Li "kill \-s TERM 1" .
257If there are processes outstanding that are deadlocked (because of
258hardware or software failure),
259.Nm
260will not wait for them all to die (which might take forever), but
261will time out after 30 seconds and print a warning message.
262.Pp
263.Nm
264will cease creating new
265.Xr getty 8 Ns 's
266and allow the system to slowly die away, if it is sent a terminal stop
267.Pq Dv TSTP
268signal, i.e.
269.Dq Li "kill \-s TSTP 1" .
270A later hangup will resume full
271multi-user operations, or a terminate will start a single user shell.
272This hook is used by
273.Xr reboot 8
274and
275.Xr halt 8 .
276.Pp
277The role of
278.Nm
279is so critical that if it dies, the system will reboot itself
280automatically.
281If, at bootstrap time, the
282.Nm
283process cannot be located, or exits during its initialisation,
284the system will panic with the message
285.Dq panic: init died (signal %d, exit %d) .
286.Pp
287If
288.Pa /dev/console
289does not exist,
290.Nm
291will cd to
292.Pa /dev
293and run
294.Dq Li "MAKEDEV -MM init" .
295.Xr MAKEDEV 8
296will use
297.Xr mount_tmpfs 8
298or
299.Xr mount_mfs 8
300to create a memory file system mounted over
301.Pa /dev
302that contains the standard devices considered necessary to boot the system.
303.Sh FILES
304.Bl -tag -width /var/log/wtmp{,x} -compact
305.It Pa /dev/console
306System console device.
307.It Pa /dev/tty*
308Terminal ports found in
309.Xr ttys 5 .
310.It Pa /var/run/utmp{,x}
311Record of current users on the system.
312.It Pa /var/log/wtmp{,x}
313Record of all logins and logouts.
314.It Pa /etc/ttys
315The terminal initialization information file.
316.It Pa /etc/rc
317System startup commands.
318.El
319.Sh DIAGNOSTICS
320.Bl -diag
321.It "getty repeating too quickly on port %s, sleeping"
322A process being started to service a line is exiting quickly
323each time it is started.
324This is often caused by a ringing or noisy terminal line.
325.Em "Init will sleep for 10 seconds" ,
326.Em "then continue trying to start the process" .
327.Pp
328.It "some processes would not die; ps axl advised."
329A process is hung and could not be killed when the system was
330shutting down.
331This condition is usually caused by a process that is stuck in a
332device driver because of a persistent device error condition.
333.El
334.Sh SEE ALSO
335.Xr config 1 ,
336.Xr kill 1 ,
337.Xr login 1 ,
338.Xr sh 1 ,
339.Xr options 4 ,
340.Xr ttys 5 ,
341.Xr MAKEDEV 8 ,
342.Xr MAKEDEV.local 8 ,
343.Xr getty 8 ,
344.Xr halt 8 ,
345.Xr mount_mfs 8 ,
346.Xr mount_tmpfs 8 ,
347.Xr rc 8 ,
348.Xr reboot 8 ,
349.Xr shutdown 8 ,
350.Xr sysctl 8 ,
351.Xr secmodel_bsd44 9
352.Sh HISTORY
353A
354.Nm
355command appeared in
356.At v6 .
357