xref: /netbsd-src/sbin/init/init.8 (revision e5548b402ae4c44fb816de42c7bba9581ce23ef5)
1.\"	$NetBSD: init.8,v 1.37 2005/11/13 18:39:53 elad 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 November 13, 2005
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.It
82Set up ttys as specified in
83.Xr ttys 5 .
84See below for more information.
85On completion, continue to state 4.
86.It
87Multi-user operation.
88Depending upon the signal received, change state appropriately;
89on
90.Dv SIGTERM ,
91go to state 7;
92on
93.Dv SIGHUP ,
94go to state 5;
95on
96.Dv SIGTSTP ,
97go to state 6.
98.It
99Clean-up mode; re-read
100.Xr ttys 5 ,
101killing off the controlling processes on lines that are now
102.Sq off ,
103and starting processes that are newly
104.Sq on .
105On completion, go to state 4.
106.It
107.Sq Boring
108mode; no new sessions.
109Signals as per state 4.
110.It
111Shutdown mode.
112Send
113.Dv SIGHUP
114to all controlling processes, reap the processes for 30 seconds,
115and then go to state 1 (single user); warning if not all the processes died.
116.El
117.Pp
118If the
119.Sq console
120entry in the
121.Xr ttys 5
122file is marked
123.Dq insecure ,
124then
125.Nm
126will require that the superuser password be
127entered before the system will start a single-user shell.
128The password check is skipped if the
129.Sq console
130is marked as
131.Dq secure .
132.Pp
133The kernel runs with four different levels of security.
134Any superuser process can raise the security level, but only
135.Nm
136can lower it.
137.Pp
138The security level mechanism is intended to allow the administrator
139to protect the persistent code and data on the system, or a subset
140thereof, from modification, even by the superuser.
141In order for this protection to be effective, the administrator
142must ensure that no program that is run while the security level
143is 0 or lower, nor any data or configuration file used by any such
144program, can be modified while the security level is greater than
1450.
146This may be achieved through the careful use of the
147.Dq immutable
148file flag to define and protect a Trusted Computing Base (TCB)
149consisting of all such programs and data, or by ensuring that all
150such programs and data are on filesystems that are mounted read-only
151and running at security level 2 or higher.
152.Em Particular care must be taken to ensure, if relying upon
153.Em security level 1 and the use of file flags, that the integrity of the
154.Em TCB cannot be compromised through the use of modifications to the
155.Em disklabel or access to overlapping disk partitions, including the
156.Em raw partition .
157.Pp
158Do not overlook the fact that shell scripts (or anything else fed to an
159interpreter, through any mechanism) and the kernel itself are "programs
160that run while the security level is 0" and must be considered part of
161the TCB.
162.Pp
163Security levels are defined as follows:
164.Bl -tag -width flag
165.It Ic -1
166Permanently insecure mode \- always run system in level 0 mode.
167.It Ic 0
168Insecure mode \- immutable and append-only flags may be changed.
169All devices may be read or written subject to their permissions.
170.It Ic 1
171Secure mode \- system immutable and system append-only flags may not
172be turned off; disks for mounted filesystems,
173.Pa /dev/mem ,
174and
175.Pa /dev/kmem
176are read-only.
177.It Ic 2
178Highly secure mode \- same as secure mode, plus disks are always
179read-only whether mounted or not, new disks may not be mounted,
180and existing mounts may only be downgraded from read-write to read-only.
181This level precludes tampering with filesystems by unmounting them,
182but also inhibits running
183.Xr newfs 8
184while the system is multi-user.
185.Pp
186The
187.Xr settimeofday 2
188system call can only advance the time.
189.Pp
190The state of
191.Xr ipf 8
192(the in-kernel IP filtering facility) may not be changed.
193.Pp
194Users may not change the per-process core name template format, only the
195default can be changed.
196.Pp
197Downgrading from highly secure mode to insecure mode (that is, to single-user
198mode) always requires the root password to be entered on the console, whether
199the console is marked as
200.Dq secure
201in
202.Pa /etc/ttys
203or not.
204.El
205.Pp
206Normally, the system runs in level 0 mode while single user
207and in level 1 mode while multi-user.
208If the level 2 mode is desired while running multi-user,
209it can be set in the startup script
210.Pa /etc/rc
211using
212.Xr sysctl 8 .
213If it is desired to run the system in level 0 mode while multi-user,
214the administrator must build a kernel with
215.Sy options INSECURE
216in the kernel configuration file, which initializes the kernel's
217.Va securelevel
218variable to -1.
219See
220.Xr config 1
221and
222.Xr options 4
223for details.
224.Pp
225In multi-user operation,
226.Nm
227maintains
228processes for the terminal ports found in the file
229.Xr ttys 5 .
230.Nm
231reads this file, and executes the command found in the second field.
232This command is usually
233.Xr getty 8 ;
234it opens and initializes the tty line and executes the
235.Xr login 1
236program.
237The
238.Xr login 1
239program, when a valid user logs in, executes a shell for that user.
240When this shell dies, either because the user logged out or an
241abnormal termination occurred (a signal), the
242.Nm
243program wakes up, deletes the user from the
244.Xr utmp 5
245file of current users and records the logout in the
246.Xr wtmp 5
247file.
248The cycle is
249then restarted by
250.Nm
251executing a new
252.Xr getty 8
253for the line.
254.pl +1
255.Pp
256Line status (on, off, secure, getty, or window information)
257may be changed in the
258.Xr ttys 5
259file without a reboot by sending the signal
260.Dv SIGHUP
261to
262.Nm
263with the command
264.Dq Li "kill \-s HUP 1" .
265This is referenced in the table above as state 5.
266On receipt of this signal,
267.Nm
268re-reads the
269.Xr ttys 5
270file.
271When a line is turned off in
272.Xr ttys 5 ,
273.Nm
274will send a
275.Dv SIGHUP
276signal to the controlling process
277for the session associated with the line.
278For any lines that were previously turned off in the
279.Xr ttys 5
280file and are now on,
281.Nm
282executes a new
283.Xr getty 8
284to enable a new login.
285If the getty or window field for a line is changed,
286the change takes effect at the end of the current
287login session (e.g., the next time
288.Nm
289starts a process on the line).
290If a line is commented out or deleted from
291.Xr ttys 5 ,
292.Nm
293will not do anything at all to that line.
294However, it will complain that the relationship between lines
295in the
296.Xr ttys 5
297file and records in the
298.Xr utmp 5
299file is out of sync,
300so this practice is not recommended.
301.Pp
302.Nm
303will terminate multi-user operations and resume single-user mode
304if sent a terminate
305.Pq Dv TERM
306signal, for example,
307.Dq Li "kill \-s TERM 1" .
308If there are processes outstanding that are deadlocked (because of
309hardware or software failure),
310.Nm
311will not wait for them all to die (which might take forever), but
312will time out after 30 seconds and print a warning message.
313.Pp
314.Nm
315will cease creating new
316.Xr getty 8 Ns 's
317and allow the system to slowly die away, if it is sent a terminal stop
318.Pq Dv TSTP
319signal, i.e.
320.Dq Li "kill \-s TSTP 1" .
321A later hangup will resume full
322multi-user operations, or a terminate will start a single user shell.
323This hook is used by
324.Xr reboot 8
325and
326.Xr halt 8 .
327.Pp
328The role of
329.Nm
330is so critical that if it dies, the system will reboot itself
331automatically.
332If, at bootstrap time, the
333.Nm
334process cannot be located, the system will panic with the message
335.Dq panic: init died (signal %d, exit %d) .
336.Pp
337If
338.Pa /dev/console
339does not exist,
340.Nm
341will create a MFS (memory based file system) mounted over
342.Pa /dev .
343Then it will create a
344.Pa /dev/console
345device so you can see things happening.
346The
347.Xr MAKEDEV 8
348and
349.Pa MAKEDEV.local
350scripts are placed in the new
351.Pa /dev
352directory.
353Then
354.Nm
355changes the working directory to
356.Pa /dev
357and runs the scripts using the
358.Dq init
359special target.
360This creates the standard devices considered necessary to boot the
361system.
362.Sh FILES
363.Bl -tag -width /var/log/wtmp -compact
364.It Pa /dev/console
365System console device.
366.It Pa /dev/tty*
367Terminal ports found in
368.Xr ttys 5 .
369.It Pa /var/run/utmp
370Record of Current users on the system.
371.It Pa /var/log/wtmp
372Record of all logins and logouts.
373.It Pa /etc/ttys
374The terminal initialization information file.
375.It Pa /etc/rc
376System startup commands.
377.El
378.Sh DIAGNOSTICS
379.Bl -diag
380.It "getty repeating too quickly on port %s, sleeping"
381A process being started to service a line is exiting quickly
382each time it is started.
383This is often caused by a ringing or noisy terminal line.
384.Em "Init will sleep for 10 seconds" ,
385.Em "then continue trying to start the process" .
386.Pp
387.It "some processes would not die; ps axl advised."
388A process is hung and could not be killed when the system was
389shutting down.
390This condition is usually caused by a process that is stuck in a
391device driver because of a persistent device error condition.
392.El
393.Sh SEE ALSO
394.Xr config 1 ,
395.Xr kill 1 ,
396.Xr login 1 ,
397.Xr sh 1 ,
398.Xr options 4 ,
399.Xr ttys 5 ,
400.Xr MAKEDEV 8 ,
401.Xr getty 8 ,
402.Xr halt 8 ,
403.Xr mfs 8 ,
404.Xr rc 8 ,
405.Xr reboot 8 ,
406.Xr shutdown 8
407.Sh HISTORY
408A
409.Nm
410command appeared in
411.At v6 .
412.Sh BUGS
413Systems without
414.Xr sysctl 8
415behave as though they have security level \-1.
416.Pp
417The security level 2 restrictions relating to TCB integrity protection
418should be enforced at security level 1.
419Restrictions dependent upon security level but not relating to TCB
420integrity protection should be selected by
421.Xr sysctl 8
422settings available only at security level 0 or lower.
423