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