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.\" Redistribution and use in source and binary forms, with or without 8.\" modification, are permitted provided that the following conditions 9.\" are met: 10.\" 1. Redistributions of source code must retain the above copyright 11.\" notice, this list of conditions and the following disclaimer. 12.\" 2. Redistributions in binary form must reproduce the above copyright 13.\" notice, this list of conditions and the following disclaimer in the 14.\" documentation and/or other materials provided with the distribution. 15.\" 3. Neither the name of the University nor the names of its contributors 16.\" may be used to endorse or promote products derived from this software 17.\" without specific prior written permission. 18.\" 19.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 20.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 23.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29.\" SUCH DAMAGE. 30.\" 31.\" @(#)init.8 8.3 (Berkeley) 4/18/94 32.\" $FreeBSD$ 33.\" 34.Dd August 15, 2018 35.Dt INIT 8 36.Os 37.Sh NAME 38.Nm init 39.Nd process control initialization 40.Sh SYNOPSIS 41.Nm 42.Nm 43.Oo 44.Cm 0 | 1 | 6 | 45.Cm c | q 46.Oc 47.Sh DESCRIPTION 48The 49.Nm 50utility 51is the last stage of the boot process. 52It normally runs the automatic reboot sequence as described in 53.Xr rc 8 , 54and if this succeeds, begins multi-user operation. 55If the reboot scripts fail, 56.Nm 57commences single-user operation by giving 58the super-user a shell on the console. 59The 60.Nm 61utility may be passed parameters 62from the boot program to 63prevent the system from going multi-user and to instead execute 64a single-user shell without starting the normal daemons. 65The system is then quiescent for maintenance work and may 66later be made to go to multi-user by exiting the 67single-user shell (with ^D). 68This 69causes 70.Nm 71to run the 72.Pa /etc/rc 73start up command file in fastboot mode (skipping disk checks). 74.Pp 75If the 76.Em console 77entry in the 78.Xr ttys 5 79file is marked 80.Dq insecure , 81then 82.Nm 83will require that the super-user password be 84entered before the system will start a single-user shell. 85The password check is skipped if the 86.Em console 87is marked as 88.Dq secure . 89Note that the password check does not protect from variables 90such as 91.Va init_script 92being set from the 93.Xr loader 8 94command line; see the 95.Sx SECURITY 96section of 97.Xr loader 8 . 98.Pp 99If the system security level (see 100.Xr security 7 ) 101is initially nonzero, then 102.Nm 103leaves it unchanged. 104Otherwise, 105.Nm 106raises the level to 1 before going multi-user for the first time. 107Since the level cannot be reduced, it will be at least 1 for 108subsequent operation, even on return to single-user. 109If a level higher than 1 is desired while running multi-user, 110it can be set before going multi-user, e.g., by the startup script 111.Xr rc 8 , 112using 113.Xr sysctl 8 114to set the 115.Va kern.securelevel 116variable to the required security level. 117.Pp 118If 119.Nm 120is run in a jail, the security level of the 121.Dq host system 122will not be affected. 123Part of the information set up in the kernel to support a jail 124is a per-jail security level. 125This allows running a higher security level inside of a jail 126than that of the host system. 127See 128.Xr jail 8 129for more information about jails. 130.Pp 131In multi-user operation, 132.Nm 133maintains 134processes for the terminal ports found in the file 135.Xr ttys 5 . 136The 137.Nm 138utility reads this file and executes the command found in the second field, 139unless the first field refers to a device in 140.Pa /dev 141which is not configured. 142The first field is supplied as the final argument to the command. 143This command is usually 144.Xr getty 8 ; 145.Nm getty 146opens and initializes the tty line 147and 148executes the 149.Xr login 1 150program. 151The 152.Nm login 153program, when a valid user logs in, 154executes a shell for that user. 155When this shell 156dies, either because the user logged out 157or an abnormal termination occurred (a signal), 158the cycle is restarted by 159executing a new 160.Nm getty 161for the line. 162.Pp 163The 164.Nm 165utility can also be used to keep arbitrary daemons running, 166automatically restarting them if they die. 167In this case, the first field in the 168.Xr ttys 5 169file must not reference the path to a configured device node 170and will be passed to the daemon 171as the final argument on its command line. 172This is similar to the facility offered in the 173.At V 174.Pa /etc/inittab . 175.Pp 176Line status (on, off, secure, getty, or window information) 177may be changed in the 178.Xr ttys 5 179file without a reboot by sending the signal 180.Dv SIGHUP 181to 182.Nm 183with the command 184.Dq Li "kill -HUP 1" . 185On receipt of this signal, 186.Nm 187re-reads the 188.Xr ttys 5 189file. 190When a line is turned off in 191.Xr ttys 5 , 192.Nm 193will send a SIGHUP signal to the controlling process 194for the session associated with the line. 195For any lines that were previously turned off in the 196.Xr ttys 5 197file and are now on, 198.Nm 199executes the command specified in the second field. 200If the command or window field for a line is changed, 201the change takes effect at the end of the current 202login session (e.g., the next time 203.Nm 204starts a process on the line). 205If a line is commented out or deleted from 206.Xr ttys 5 , 207.Nm 208will not do anything at all to that line. 209.Pp 210The 211.Nm 212utility will terminate multi-user operations and resume single-user mode 213if sent a terminate 214.Pq Dv TERM 215signal, for example, 216.Dq Li "kill \-TERM 1" . 217If there are processes outstanding that are deadlocked (because of 218hardware or software failure), 219.Nm 220will not wait for them all to die (which might take forever), but 221will time out after 30 seconds and print a warning message. 222.Pp 223The 224.Nm 225utility will cease creating new processes 226and allow the system to slowly die away, if it is sent a terminal stop 227.Pq Dv TSTP 228signal, i.e.\& 229.Dq Li "kill \-TSTP 1" . 230A later hangup will resume full 231multi-user operations, or a terminate will start a single-user shell. 232This hook is used by 233.Xr reboot 8 234and 235.Xr halt 8 . 236.Pp 237The 238.Nm 239utility will terminate all possible processes (again, it will not wait 240for deadlocked processes) and reboot the machine if sent the interrupt 241.Pq Dv INT 242signal, i.e.\& 243.Dq Li "kill \-INT 1". 244This is useful for shutting the machine down cleanly from inside the kernel 245or from X when the machine appears to be hung. 246.Pp 247The 248.Nm 249utility will do the same, except it will halt the machine if sent 250the user defined signal 1 251.Pq Dv USR1 , 252or will halt and turn the power off (if hardware permits) if sent 253the user defined signal 2 254.Pq Dv USR2 . 255.Pp 256When shutting down the machine, 257.Nm 258will try to run the 259.Pa /etc/rc.shutdown 260script. 261This script can be used to cleanly terminate specific programs such 262as 263.Nm innd 264(the InterNetNews server). 265If this script does not terminate within 120 seconds, 266.Nm 267will terminate it. 268The timeout can be configured via the 269.Xr sysctl 8 270variable 271.Va kern.init_shutdown_timeout . 272.Pp 273The role of 274.Nm 275is so critical that if it dies, the system will reboot itself 276automatically. 277If, at bootstrap time, the 278.Nm 279process cannot be located, the system will panic with the message 280.Dq "panic: init died (signal %d, exit %d)" . 281.Pp 282If run as a user process as shown in the second synopsis line, 283.Nm 284will emulate 285.At V 286behavior, i.e., super-user can specify the desired 287.Em run-level 288on a command line, and 289.Nm 290will signal the original 291(PID 1) 292.Nm 293as follows: 294.Bl -column Run-level SIGTERM 295.It Sy "Run-level Signal Action" 296.It Cm 0 Ta Dv SIGUSR1 Ta "Halt" 297.It Cm 0 Ta Dv SIGUSR2 Ta "Halt and turn the power off" 298.It Cm 0 Ta Dv SIGWINCH Ta "Halt and turn the power off and then back on" 299.It Cm 1 Ta Dv SIGTERM Ta "Go to single-user mode" 300.It Cm 6 Ta Dv SIGINT Ta "Reboot the machine" 301.It Cm c Ta Dv SIGTSTP Ta "Block further logins" 302.It Cm q Ta Dv SIGHUP Ta Rescan the 303.Xr ttys 5 304file 305.El 306.Sh KERNEL ENVIRONMENT VARIABLES 307The following 308.Xr kenv 2 309variables are available as 310.Xr loader 8 311tunables: 312.Bl -tag -width indent 313.It Va init_chroot 314If set to a valid directory in the root file system, it causes 315.Nm 316to perform a 317.Xr chroot 2 318operation on that directory, making it the new root directory. 319That happens before entering single-user mode or multi-user 320mode (but after executing the 321.Va init_script 322if enabled). 323This functionality has generally been eclipsed by rerooting. 324See 325.Xr reboot 8 326.Fl r 327for details. 328.It Va init_exec 329If set to a valid file name in the root file system, 330instructs 331.Nm 332to directly execute that file as the very first action, 333replacing 334.Nm 335as PID 1. 336.It Va init_script 337If set to a valid file name in the root file system, 338instructs 339.Nm 340to run that script as the very first action, 341before doing anything else. 342Signal handling and exit code interpretation is similar to 343running the 344.Pa /etc/rc 345script. 346In particular, single-user operation is enforced 347if the script terminates with a non-zero exit code, 348or if a SIGTERM is delivered to the 349.Nm 350process (PID 1). 351This functionality has generally been eclipsed by rerooting. 352See 353.Xr reboot 8 354.Fl r 355for details. 356.It Va init_shell 357Defines the shell binary to be used for executing the various shell scripts. 358The default is 359.Dq Li /bin/sh . 360It is used for running the 361.Va init_exec 362or 363.Va init_script 364if set, as well as for the 365.Pa /etc/rc 366and 367.Pa /etc/rc.shutdown 368scripts. 369The value of the corresponding 370.Xr kenv 2 371variable is evaluated every time 372.Nm 373calls a shell script, so it can be changed later on using the 374.Xr kenv 1 375utility. 376In particular, if a non-default shell is used for running an 377.Va init_script , 378it might be desirable to have that script reset the value of 379.Va init_shell 380back to the default, so that the 381.Pa /etc/rc 382script is executed with the standard shell 383.Pa /bin/sh . 384.Sh FILES 385.Bl -tag -width /var/log/init.log -compact 386.It Pa /dev/console 387system console device 388.It Pa /dev/tty* 389terminal ports found in 390.Xr ttys 5 391.It Pa /etc/ttys 392the terminal initialization information file 393.It Pa /etc/rc 394system startup commands 395.It Pa /etc/rc.shutdown 396system shutdown commands 397.It Pa /var/log/init.log 398log of 399.Xr rc 8 400output if the system console device is not available 401.El 402.Sh DIAGNOSTICS 403.Bl -diag 404.It "getty repeating too quickly on port %s, sleeping." 405A process being started to service a line is exiting quickly 406each time it is started. 407This is often caused by a ringing or noisy terminal line. 408.Bf -emphasis 409Init will sleep for 30 seconds, 410then continue trying to start the process. 411.Ef 412.It "some processes would not die; ps axl advised." 413A process 414is hung and could not be killed when the system was shutting down. 415This condition is usually caused by a process 416that is stuck in a device driver because of 417a persistent device error condition. 418.El 419.Sh SEE ALSO 420.Xr kill 1 , 421.Xr login 1 , 422.Xr sh 1 , 423.Xr ttys 5 , 424.Xr security 7 , 425.Xr getty 8 , 426.Xr halt 8 , 427.Xr jail 8 , 428.Xr rc 8 , 429.Xr reboot 8 , 430.Xr shutdown 8 , 431.Xr sysctl 8 432.Sh HISTORY 433An 434.Nm 435utility appeared in 436.At v1 . 437.Sh CAVEATS 438Systems without 439.Xr sysctl 8 440behave as though they have security level \-1. 441.Pp 442Setting the security level above 1 too early in the boot sequence can 443prevent 444.Xr fsck 8 445from repairing inconsistent file systems. 446The 447preferred location to set the security level is at the end of 448.Pa /etc/rc 449after all multi-user startup actions are complete. 450