1.\" $OpenBSD: rc.8,v 1.47 2024/06/30 23:57:31 jsg Exp $ 2.\" 3.\" Copyright (c) 1980, 1991, 1993 4.\" The Regents of the University of California. All rights reserved. 5.\" 6.\" Redistribution and use in source and binary forms, with or without 7.\" modification, are permitted provided that the following conditions 8.\" are met: 9.\" 1. Redistributions of source code must retain the above copyright 10.\" notice, this list of conditions and the following disclaimer. 11.\" 2. Redistributions in binary form must reproduce the above copyright 12.\" notice, this list of conditions and the following disclaimer in the 13.\" documentation and/or other materials provided with the distribution. 14.\" 3. Neither the name of the University nor the names of its contributors 15.\" may be used to endorse or promote products derived from this software 16.\" without specific prior written permission. 17.\" 18.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 19.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 22.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28.\" SUCH DAMAGE. 29.\" 30.\" @(#)rc.8 8.2 (Berkeley) 12/11/93 31.\" 32.Dd $Mdocdate: June 30 2024 $ 33.Dt RC 8 34.Os 35.Sh NAME 36.Nm rc , 37.Nm rc.firsttime , 38.Nm rc.local , 39.Nm rc.securelevel 40.Nd command scripts for system startup 41.Sh DESCRIPTION 42.Nm rc 43is the command script that is invoked by 44.Xr init 8 45when the system starts up. 46It performs system housekeeping chores and starts up system daemons. 47Additionally, 48.Nm rc 49is intricately tied to the 50.Xr netstart 8 51script, which runs commands and daemons pertaining to the network. 52.Nm rc 53is also used to execute any 54.Xr rc.d 8 55scripts defined in 56.Xr rc.conf.local 8 . 57The 58.Nm rc.securelevel , 59.Nm rc.firsttime , 60and 61.Nm rc.local 62scripts hold commands which are pertinent only to a specific site. 63.Pp 64All of these startup scripts are controlled to some 65extent by variables defined in 66.Xr rc.conf 8 , 67which specify which daemons and services to run. 68.Pp 69Before 70.Xr init 8 71starts 72.Nm rc , 73it sets the process priority, umask, and resource limits according to the 74.Dq daemon 75login class as described in 76.Xr login.conf 5 . 77It then starts 78.Nm rc 79and attempts to execute the sequence of commands therein. 80.Pp 81The first part of 82.Nm rc 83runs an 84.Xr fsck 8 85with option 86.Fl p 87to 88.Dq preen 89all disks of minor inconsistencies resulting 90from the last system shutdown and to check for serious inconsistencies 91caused by hardware or software failure. 92If this auto-check and repair succeeds, then the second part of 93.Nm rc 94is run. 95However, if the file 96.Pa /fastboot 97exists, 98fsck will not be invoked. 99The file is then removed so that fsck will be run on subsequent boots. 100.Pp 101The second part of 102.Nm rc 103then asks 104.Xr rc.conf 8 105for configuration variables, 106mounts filesystems, saves 107.Xr dmesg 8 108output to the file 109.Pa /var/run/dmesg.boot , 110starts system daemons, 111preserves editor files, 112clears the scratch directory 113.Pa /tmp , 114uses 115.Xr savecore 8 116to save any possible core image that might have been 117generated as a result of a system crash, 118and relinks kernel objects in a random order. 119.Pp 120If at any point the boot script fails, 121.Xr init 8 122enters single-user mode, 123allowing the superuser a shell on the console. 124On exiting this mode, 125init again invokes 126.Nm rc , 127but this time without performing the file system preen. 128.Pp 129Before 130.Nm rc 131starts most system daemons, 132.Xr netstart 8 133is executed. 134.Pp 135.Nm rc.securelevel 136is executed by 137.Nm rc 138to start daemons that must be run before the security level changes. 139Following this, 140.Nm rc 141then sets the security level to '1' if it wasn't set already by 142.Nm rc.securelevel . 143See 144.Xr securelevel 7 145for the effects of setting the security level. 146.Pp 147If 148.Nm rc.firsttime 149exists, it is executed once and then deleted. 150Any output is mailed to root. 151.Pp 152.Nm rc.local 153is executed towards the end of 154.Nm rc 155(it is not the very last as there are a few services that must be 156started at the very end). 157Normally, 158.Nm rc.local 159contains commands and daemons that are not part of the 160stock installation. 161.Sh FILES 162.Bl -tag -width "/etc/rc.securelevelXX" -compact 163.It Pa /etc/netstart 164Command script for network startup. 165.It Pa /etc/rc 166Command scripts for system startup. 167.It Pa /etc/rc.conf 168System daemon configuration database. 169.It Pa /etc/rc.conf.local 170Site specific daemon configuration database. 171.It Pa /etc/rc.d 172Directory to hold 173.Xr rc.d 8 174scripts. 175.It Pa /etc/rc.d/rc.subr 176Functions used by the 177.Xr rc.d 8 178scripts. 179.It Pa /etc/rc.firsttime 180Commands run on the first boot after creation. 181.It Pa /etc/rc.local 182Site specific command scripts for system startup. 183.It Pa /etc/rc.securelevel 184Commands run before the security level changes. 185.It Pa /etc/rc.shutdown 186Commands run at system shutdown. 187.It Pa /etc/examples/rc.* 188Examples of site specific scripts. 189.It Pa /fastboot 190Tells 191.Nm rc 192not to run 193.Xr fsck 8 194during the next boot. 195.It Pa /var/run/dmesg.boot 196Copy of 197.Xr dmesg 8 198saved by 199.Nm rc 200at boot time. 201.El 202.Sh SEE ALSO 203.Xr sysctl.conf 5 , 204.Xr securelevel 7 , 205.Xr init 8 , 206.Xr netstart 8 , 207.Xr rc.conf 8 , 208.Xr rc.d 8 , 209.Xr rc.shutdown 8 , 210.Xr rcctl 8 211.Sh HISTORY 212The 213.Nm 214command appeared in 215.At v4 . 216