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.\" %sccs.include.redist.roff% 8.\" 9.\" @(#)init.8 8.3 (Berkeley) 04/18/94 10.\" 11.Dd 12.Dt INIT 8 13.Os BSD 4 14.Sh NAME 15.Nm init 16.Nd process control initialization 17.Sh SYNOPSIS 18.Nm init 19.Sh DESCRIPTION 20The 21.Nm init 22program 23is the last stage of the boot process. 24It normally runs the automatic reboot sequence as described in 25.Xr reboot 8 , 26and if this succeeds, begins multi-user operation. 27If the reboot scripts fail, 28.Nm init 29commences single user operation by giving 30the super-user a shell on the console. 31The 32.Nm init 33program may be passed parameters 34from the boot program to 35prevent the system from going multi-user and to instead execute 36a single user shell without starting the normal daemons. 37The system is then quiescent for maintenance work and may 38later be made to go to multi-user by exiting the 39single-user shell (with ^D). 40This 41causes 42.Nm init 43to run the 44.Pa /etc/rc 45start up command file in fastboot mode (skipping disk checks). 46.Pp 47If the 48.Nm console 49entry in the 50.Xr ttys 5 51file is marked ``insecure'', 52then 53.Nm init 54will require that the superuser password be 55entered before the system will start a single-user shell. 56The password check is skipped if the 57.Nm console 58is marked as ``secure''. 59.Pp 60The kernel runs with four different levels of security. 61Any superuser process can raise the security level, but only 62.Nm init 63can lower it. 64Security levels are defined as follows: 65.Bl -tag -width flag 66.It Ic -1 67Permanently insecure mode \- always run system in level 0 mode. 68.It Ic 0 69Insecure mode \- immutable and append-only flags may be turned off. 70All devices may be read or written subject to their permissions. 71.It Ic 1 72Secure mode \- immutable and append-only flags may not be changed; 73disks for mounted filesystems, 74.Pa /dev/mem , 75and 76.Pa /dev/kmem 77are read-only. 78.It Ic 2 79Highly secure mode \- same as secure mode, plus disks are always 80read-only whether mounted or not. 81This level precludes tampering with filesystems by unmounting them, 82but also inhibits running 83.Xr newfs 8 84while the system is multi-user. 85.El 86.Pp 87Normally, the system runs in level 0 mode while single user 88and in level 1 mode while multiuser. 89If the level 2 mode is desired while running multiuser, 90it can be set in the startup script 91.Pa /etc/rc 92using 93.Xr sysctl 8 . 94If it is desired to run the system in level 0 mode while multiuser, 95the administrator must build a kernel with the variable 96.Nm securelevel 97defined in the file 98.Pa /sys/compile/MACHINE/param.c 99and initialize it to -1. 100.Pp 101In multi-user operation, 102.Nm init 103maintains 104processes for the terminal ports found in the file 105.Xr ttys 5 . 106.Nm Init 107reads this file, and executes the command found in the second field. 108This command is usually 109.Xr getty 8 ; 110.Xr getty 111opens and initializes the tty line 112and 113executes the 114.Xr login 115program. 116The 117.Xr login 118program, when a valid user logs in, 119executes a shell for that user. When this shell 120dies, either because the user logged out 121or an abnormal termination occurred (a signal), 122the 123.Nm init 124program wakes up, deletes the user 125from the 126.Xr utmp 5 127file of current users and records the logout in the 128.Xr wtmp 129file. 130The cycle is 131then restarted by 132.Nm init 133executing a new 134.Xr getty 135for the line. 136.Pp 137Line status (on, off, secure, getty, or window information) 138may be changed in the 139.Xr ttys 140file without a reboot by sending the signal 141.Dv SIGHUP 142to 143.Nm init 144with the command 145.Dq Li "kill -HUP 1" . 146On receipt of this signal, 147.Nm init 148re-reads the 149.Xr ttys 150file. 151When a line is turned off in 152.Xr ttys , 153.Nm init 154will send a SIGHUP signal to the controlling process 155for the session associated with the line. 156For any lines that were previously turned off in the 157.Xr ttys 158file and are now on, 159.Nm init 160executes a new 161.Xr getty 162to enable a new login. 163If the getty or window field for a line is changed, 164the change takes effect at the end of the current 165login session (e.g., the next time 166.Nm init 167starts a process on the line). 168If a line is commented out or deleted from 169.Xr ttys , 170.Nm init 171will not do anything at all to that line. 172However, it will complain that the relationship between lines 173in the 174.Xr ttys 175file and records in the 176.Xr utmp 177file is out of sync, 178so this practice is not recommended. 179.Pp 180.Nm Init 181will terminate multi-user operations and resume single-user mode 182if sent a terminate 183.Pq Dv TERM 184signal, for example, 185.Dq Li "kill \-TERM 1" . 186If there are processes outstanding that are deadlocked (because of 187hardware or software failure), 188.Xr init 189will not wait for them all to die (which might take forever), but 190will time out after 30 seconds and print a warning message. 191.Pp 192.Nm Init 193will cease creating new 194.Xr getty Ns 's 195and allow the system to slowly die away, if it is sent a terminal stop 196.Pq Dv TSTP 197signal, i.e. 198.Dq Li "kill \-TSTP 1" . 199A later hangup will resume full 200multi-user operations, or a terminate will start a single user shell. 201This hook is used by 202.Xr reboot 8 203and 204.Xr halt 8 . 205.Pp 206The role of 207.Nm init 208is so critical that if it dies, the system will reboot itself 209automatically. 210If, at bootstrap time, the 211.Xr init 212process cannot be located, the system will panic with the message 213``panic: "init died (signal %d, exit %d)''. 214.Sh DIAGNOSTICS 215.Bl -diag 216.It "getty repeating too quickly on port %s, sleeping" 217A process being started to service a line is exiting quickly 218each time it is started. 219This is often caused by a ringing or noisy terminal line. 220.Em "Init will sleep for 10 seconds" , 221.Em "then continue trying to start the process" . 222.Pp 223.It "some processes would not die; ps axl advised." 224A process 225is hung and could not be killed when the system was shutting down. 226This condition is usually caused by a process 227that is stuck in a device driver because of 228a persistent device error condition. 229.El 230.Sh FILES 231.Bl -tag -width /var/log/wtmp -compact 232.It Pa /dev/console 233System console device. 234.It Pa /dev/tty* 235Terminal ports found in 236.Xr ttys . 237.It Pa /var/run/utmp 238Record of Current users on the system. 239.It Pa /var/log/wtmp 240Record of all logins and logouts. 241.It Pa /etc/ttys 242The terminal initialization information file. 243.It Pa /etc/rc 244System startup commands. 245.El 246.Sh SEE ALSO 247.Xr login 1 , 248.Xr kill 1 , 249.Xr sh 1 , 250.Xr ttys 5 , 251.Xr crash 8 , 252.Xr getty 8 , 253.Xr rc 8 , 254.Xr reboot 8 , 255.Xr halt 8 , 256.Xr shutdown 8 257.Sh HISTORY 258A 259.Nm 260command appeared in 261.At v6 . 262.Sh BUGS 263Systems without 264.Xr sysctl 265behave as though they have security level \-1. 266