1.\" $NetBSD: init.8,v 1.28 2003/08/07 10:04:25 agc 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 April 29, 2000 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 the 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 ``insecure'', then 123.Nm 124will require that the superuser password be 125entered before the system will start a single-user shell. 126The password check is skipped if the 127.Sq console 128is marked as ``secure''. 129.Pp 130The kernel runs with four different levels of security. 131Any superuser process can raise the security level, but only 132.Nm 133can lower it. 134Security levels are defined as follows: 135.Bl -tag -width flag 136.It Ic -1 137Permanently insecure mode \- always run system in level 0 mode. 138.It Ic 0 139Insecure mode \- immutable and append-only flags may be changed. 140All devices may be read or written subject to their permissions. 141.It Ic 1 142Secure mode \- system immutable and system append-only flags may not 143be turned off; disks for mounted filesystems, 144.Pa /dev/mem , 145and 146.Pa /dev/kmem 147are read-only. 148.It Ic 2 149Highly secure mode \- same as secure mode, plus disks are always 150read-only whether mounted or not, new disks may not be mounted, 151and existing mounts may only be downgraded from read-write to read-only. 152This level precludes tampering with filesystems by unmounting them, 153but also inhibits running 154.Xr newfs 8 155while the system is multi-user. 156.Pp 157The 158.Xr settimeofday 2 159system call can only advance the time. 160.Pp 161The state of 162.Xr ipf 8 163(the in-kernel IP filtering facility) may not be changed. 164.Pp 165Users may not change the per-process core name template format, only the 166default can be changed. 167.Pp 168Downgrading from highly secure mode to insecure mode (that is, to single-user 169mode) always requires the root password to be entered on the console, whether 170the console is marked as 'secure' in 171.Pa /etc/ttys 172or not. 173.El 174.Pp 175Normally, the system runs in level 0 mode while single user 176and in level 1 mode while multi-user. 177If the level 2 mode is desired while running multi-user, 178it can be set in the startup script 179.Pa /etc/rc 180using 181.Xr sysctl 8 . 182If it is desired to run the system in level 0 mode while multi-user, 183the administrator must build a kernel with 184.Sy options INSECURE 185in the kernel configuration file, which initializes the kernel's 186.Va securelevel 187variable to -1. 188See 189.Xr options 4 190and 191.Xr config 8 192for details. 193.Pp 194In multi-user operation, 195.Nm 196maintains 197processes for the terminal ports found in the file 198.Xr ttys 5 . 199.Nm 200reads this file, and executes the command found in the second field. 201This command is usually 202.Xr getty 8 ; 203it opens and initializes the tty line and executes the 204.Xr login 1 205program. 206The 207.Xr login 1 208program, when a valid user logs in, executes a shell for that user. 209When this shell dies, either because the user logged out or an 210abnormal termination occurred (a signal), the 211.Nm 212program wakes up, deletes the user from the 213.Xr utmp 5 214file of current users and records the logout in the 215.Xr wtmp 5 216file. 217The cycle is 218then restarted by 219.Nm 220executing a new 221.Xr getty 8 222for the line. 223.pl +1 224.Pp 225Line status (on, off, secure, getty, or window information) 226may be changed in the 227.Xr ttys 5 228file without a reboot by sending the signal 229.Dv SIGHUP 230to 231.Nm 232with the command 233.Dq Li "kill \-s HUP 1" . 234This is referenced in the table above as state 5. 235On receipt of this signal, 236.Nm 237re-reads the 238.Xr ttys 5 239file. 240When a line is turned off in 241.Xr ttys 5 , 242.Nm 243will send a 244.Dv SIGHUP 245signal to the controlling process 246for the session associated with the line. 247For any lines that were previously turned off in the 248.Xr ttys 5 249file and are now on, 250.Nm 251executes a new 252.Xr getty 8 253to enable a new login. 254If the getty or window field for a line is changed, 255the change takes effect at the end of the current 256login session (e.g., the next time 257.Nm 258starts a process on the line). 259If a line is commented out or deleted from 260.Xr ttys 5 , 261.Nm 262will not do anything at all to that line. 263However, it will complain that the relationship between lines 264in the 265.Xr ttys 5 266file and records in the 267.Xr utmp 5 268file is out of sync, 269so this practice is not recommended. 270.Pp 271.Nm 272will terminate multi-user operations and resume single-user mode 273if sent a terminate 274.Pq Dv TERM 275signal, for example, 276.Dq Li "kill \-s TERM 1" . 277If there are processes outstanding that are deadlocked (because of 278hardware or software failure), 279.Nm 280will not wait for them all to die (which might take forever), but 281will time out after 30 seconds and print a warning message. 282.Pp 283.Nm 284will cease creating new 285.Xr getty 8 Ns 's 286and allow the system to slowly die away, if it is sent a terminal stop 287.Pq Dv TSTP 288signal, i.e. 289.Dq Li "kill \-s TSTP 1" . 290A later hangup will resume full 291multi-user operations, or a terminate will start a single user shell. 292This hook is used by 293.Xr reboot 8 294and 295.Xr halt 8 . 296.Pp 297The role of 298.Nm 299is so critical that if it dies, the system will reboot itself 300automatically. 301If, at bootstrap time, the 302.Nm 303process cannot be located, the system will panic with the message 304``panic: "init died (signal %d, exit %d)''. 305.Sh FILES 306.Bl -tag -width /var/log/wtmp -compact 307.It Pa /dev/console 308System console device. 309.It Pa /dev/tty* 310Terminal ports found in 311.Xr ttys 5 . 312.It Pa /var/run/utmp 313Record of Current users on the system. 314.It Pa /var/log/wtmp 315Record of all logins and logouts. 316.It Pa /etc/ttys 317The terminal initialization information file. 318.It Pa /etc/rc 319System startup commands. 320.El 321.Sh DIAGNOSTICS 322.Bl -diag 323.It "getty repeating too quickly on port %s, sleeping" 324A process being started to service a line is exiting quickly 325each time it is started. 326This is often caused by a ringing or noisy terminal line. 327.Em "Init will sleep for 10 seconds" , 328.Em "then continue trying to start the process" . 329.Pp 330.It "some processes would not die; ps axl advised." 331A process 332is hung and could not be killed when the system was shutting down. 333This condition is usually caused by a process 334that is stuck in a device driver because of 335a persistent device error condition. 336.El 337.Sh SEE ALSO 338.Xr kill 1 , 339.Xr login 1 , 340.Xr sh 1 , 341.Xr options 4 , 342.Xr ttys 5 , 343.Xr config 8 , 344.Xr getty 8 , 345.Xr halt 8 , 346.Xr rc 8 , 347.Xr reboot 8 , 348.Xr shutdown 8 349.Sh HISTORY 350A 351.Nm 352command appeared in 353.At v6 . 354.Sh BUGS 355Systems without 356.Xr sysctl 8 357behave as though they have security level \-1. 358