1.\" $NetBSD: init.8,v 1.59 2013/10/02 22:07:56 apb 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 October 2, 2013 36.Dt INIT 8 37.Os 38.Sh NAME 39.Nm init 40.Nd process control initialization 41.Sh SYNOPSIS 42.Nm 43.Op Fl s 44.Sh DESCRIPTION 45The 46.Nm 47program is the last stage of the boot process. 48It normally begins multi-user operation. 49.Pp 50.Nm 51is executed automatically by the kernel, 52after the kernel has initialised all devices 53and mounted the root file system. 54The kernel may try multiple possible paths for 55.Nm , 56including 57.Pa /sbin/init , 58.Pa /sbin/oinit , 59.Pa /sbin/init.bak , 60and 61.Pa /rescue/init . 62.Pp 63The following table describes the state machine used by 64.Nm : 65.Bl -enum 66.It 67Single user shell. 68If the kernel is booted in single user mode (see 69.Xr boothowto 9 ) , 70then the kernel will pass the 71.Fl s 72option to 73.Nm 74to prevent the system from going multi-user and 75to instead execute a single user shell without starting the normal 76daemons. 77If the kernel is in a secure mode, 78.Nm 79will downgrade it to securelevel 0 (insecure mode). 80The system is then quiescent for maintenance work and may 81later be made to go to state 2 (multi-user) by exiting the single-user 82shell (with ^D). 83.It 84Multi-user boot (default operation). 85Executes 86.Pa /etc/rc 87(see 88.Xr rc 8 ) . 89If this was the first state entered (as opposed to entering here after 90state 1), then 91.Pa /etc/rc 92will be invoked with its first argument being 93.Sq autoboot . 94If 95.Pa /etc/rc 96exits with a non-zero (error) exit code, commence single user 97operation by giving the super-user a shell on the console by going 98to state 1 (single user). 99Otherwise, proceed to state 3. 100.Pp 101If value of the 102.Dq init.root 103sysctl node is not equal to 104.Pa / 105at this point, the 106.Pa /etc/rc 107process will be run inside a 108.Xr chroot 2 109indicated by sysctl with the same error handling as above. 110.Pp 111If the administrator has not set the security level to \-1 112to indicate that the kernel should not run multiuser in secure 113mode, and the 114.Pa /etc/rc 115script has not set a higher level of security 116than level 1, then 117.Nm 118will put the kernel into securelevel mode 1. 119See 120.Xr rc.conf 5 121and 122.Xr secmodel_securelevel 9 123for more information. 124.It 125Set up ttys as specified in 126.Xr ttys 5 . 127See below for more information. 128On completion, continue to state 4. 129If we did chroot in state 2, each 130.Xr getty 8 131process will be run in the same 132.Xr chroot 2 133path as in 2 (that is, the value of 134.Dq init.root 135sysctl is not re-read). 136.It 137Multi-user operation. 138Depending upon the signal received, change state appropriately; 139on 140.Dv SIGTERM , 141go to state 7; 142on 143.Dv SIGHUP , 144go to state 5; 145on 146.Dv SIGTSTP , 147go to state 6. 148.It 149Clean-up mode; re-read 150.Xr ttys 5 , 151killing off the controlling processes on lines that are now 152.Sq off , 153and starting processes that are newly 154.Sq on . 155On completion, go to state 4. 156.It 157.Sq Boring 158mode; no new sessions. 159Signals as per state 4. 160.It 161Shutdown mode. 162Send 163.Dv SIGHUP 164to all controlling processes, reap the processes for 30 seconds, 165and then go to state 1 (single user); warning if not all the processes died. 166.El 167.Pp 168If the 169.Sq console 170entry in the 171.Xr ttys 5 172file is marked 173.Dq insecure , 174then 175.Nm 176will require that the superuser password be 177entered before the system will start a single-user shell. 178The password check is skipped if the 179.Sq console 180is marked as 181.Dq secure . 182.Pp 183It should be noted that while 184.Nm 185has the ability to start multi-user operation inside a 186.Xr chroot 2 187environment, the 188.Nm 189process itself will always run in the 190.Dq original root directory . 191This also implies that single-user mode is always started in the original 192root, giving the possibility to create multi-user sessions in different 193root directories over time. 194The 195.Dq init.root 196sysctl node is fabricated by 197.Nm 198at startup and re-created any time it's found to be missing. 199Type of the node is string capable of holding full pathname, and 200is only accessible by the superuser (unless explicitly destroyed 201and re-created with different specification). 202.Pp 203In multi-user operation, 204.Nm 205maintains 206processes for the terminal ports found in the file 207.Xr ttys 5 . 208.Nm 209reads this file, and executes the command found in the second field. 210This command is usually 211.Xr getty 8 ; 212it opens and initializes the tty line and executes the 213.Xr login 1 214program. 215The 216.Xr login 1 217program, when a valid user logs in, executes a shell for that user. 218When this shell dies, either because the user logged out or an 219abnormal termination occurred (a signal), the 220.Nm 221program wakes up, deletes the user from the 222.Xr utmp 5 223and 224.Xr utmpx 5 225files of current users and records the logout in the 226.Xr wtmp 5 227and 228.Xr wtmpx 5 229files. 230The cycle is 231then restarted by 232.Nm 233executing a new 234.Xr getty 8 235for the line. 236.Pp 237Line status (on, off, secure, getty, or window information) 238may be changed in the 239.Xr ttys 5 240file without a reboot by sending the signal 241.Dv SIGHUP 242to 243.Nm 244with the command 245.Dq Li "kill \-s HUP 1" . 246This is referenced in the table above as state 5. 247On receipt of this signal, 248.Nm 249re-reads the 250.Xr ttys 5 251file. 252When a line is turned off in 253.Xr ttys 5 , 254.Nm 255will send a 256.Dv SIGHUP 257signal to the controlling process 258for the session associated with the line. 259For any lines that were previously turned off in the 260.Xr ttys 5 261file and are now on, 262.Nm 263executes a new 264.Xr getty 8 265to enable a new login. 266If the getty or window field for a line is changed, 267the change takes effect at the end of the current 268login session (e.g., the next time 269.Nm 270starts a process on the line). 271If a line is commented out or deleted from 272.Xr ttys 5 , 273.Nm 274will not do anything at all to that line. 275However, it will complain that the relationship between lines 276in the 277.Xr ttys 5 278file and records in the 279.Xr utmp 5 280file is out of sync, 281so this practice is not recommended. 282.Pp 283.Nm 284will terminate multi-user operations and resume single-user mode 285if sent a terminate 286.Pq Dv TERM 287signal, for example, 288.Dq Li "kill \-s TERM 1" . 289If there are processes outstanding that are deadlocked (because of 290hardware or software failure), 291.Nm 292will not wait for them all to die (which might take forever), but 293will time out after 30 seconds and print a warning message. 294.Pp 295.Nm 296will cease creating new 297.Xr getty 8 Ns 's 298and allow the system to slowly die away, if it is sent a terminal stop 299.Pq Dv TSTP 300signal, i.e. 301.Dq Li "kill \-s TSTP 1" . 302A later hangup will resume full 303multi-user operations, or a terminate will start a single user shell. 304This hook is used by 305.Xr reboot 8 306and 307.Xr halt 8 . 308.Pp 309The role of 310.Nm 311is so critical that if it dies, the system will reboot itself 312automatically. 313If, at bootstrap time, the 314.Nm 315process cannot be located, or exits during its initialisation, 316the system will panic with the message 317.Dq panic: init died (signal %d, exit %d) . 318.Pp 319If 320.Pa /dev/console 321does not exist, 322.Nm 323will cd to 324.Pa /dev 325and run 326.Dq Li "MAKEDEV -MM init" . 327.Xr MAKEDEV 8 328will use 329.Xr mount_tmpfs 8 330or 331.Xr mount_mfs 8 332to create a memory file system mounted over 333.Pa /dev 334that contains the standard devices considered necessary to boot the system. 335.Sh FILES 336.Bl -tag -width /var/log/wtmp{,x} -compact 337.It Pa /dev/console 338System console device. 339.It Pa /dev/tty* 340Terminal ports found in 341.Xr ttys 5 . 342.It Pa /var/run/utmp{,x} 343Record of current users on the system. 344.It Pa /var/log/wtmp{,x} 345Record of all logins and logouts. 346.It Pa /etc/ttys 347The terminal initialization information file. 348.It Pa /etc/rc 349System startup commands. 350.El 351.Sh DIAGNOSTICS 352.Bl -diag 353.It "getty repeating too quickly on port %s, sleeping" 354A process being started to service a line is exiting quickly 355each time it is started. 356This is often caused by a ringing or noisy terminal line. 357.Em "Init will sleep for 10 seconds" , 358.Em "then continue trying to start the process" . 359.Pp 360.It "some processes would not die; ps axl advised." 361A process is hung and could not be killed when the system was 362shutting down. 363This condition is usually caused by a process that is stuck in a 364device driver because of a persistent device error condition. 365.El 366.Sh SEE ALSO 367.Xr config 1 , 368.Xr kill 1 , 369.Xr login 1 , 370.Xr sh 1 , 371.Xr options 4 , 372.Xr ttys 5 , 373.Xr getty 8 , 374.Xr halt 8 , 375.Xr MAKEDEV 8 , 376.Xr MAKEDEV.local 8 , 377.Xr mount_mfs 8 , 378.Xr mount_tmpfs 8 , 379.Xr rc 8 , 380.Xr reboot 8 , 381.Xr rescue 8 , 382.Xr shutdown 8 , 383.Xr sysctl 8 , 384.Xr secmodel_bsd44 9 , 385.Xr secmodel_securelevel 9 386.Sh HISTORY 387A 388.Nm 389command appeared in 390.At v6 . 391