1800e7495SMitchell Horne.\" $NetBSD: boot.9,v 1.2 1996/09/24 07:01:26 ghudson Exp $ 2800e7495SMitchell Horne.\" 3d55c1877SMitchell Horne.\" SPDX-License-Identifier: BSD-4-Clause 4d55c1877SMitchell Horne.\" 5800e7495SMitchell Horne.\" Copyright (c) 1997 6800e7495SMitchell Horne.\" Mike Pritchard. All rights reserved. 7800e7495SMitchell Horne.\" 8800e7495SMitchell Horne.\" Copyright (c) 1994 Christopher G. Demetriou 9800e7495SMitchell Horne.\" All rights reserved. 10800e7495SMitchell Horne.\" 11d55c1877SMitchell Horne.\" Copyright (c) 2021,2023 The FreeBSD Foundation 12d55c1877SMitchell Horne.\" 13d55c1877SMitchell Horne.\" Portions of this documentation were written by Mitchell Horne 14d55c1877SMitchell Horne.\" under sponsorship from the FreeBSD Foundation. 15d55c1877SMitchell Horne.\" 16800e7495SMitchell Horne.\" Redistribution and use in source and binary forms, with or without 17800e7495SMitchell Horne.\" modification, are permitted provided that the following conditions 18800e7495SMitchell Horne.\" are met: 19800e7495SMitchell Horne.\" 1. Redistributions of source code must retain the above copyright 20800e7495SMitchell Horne.\" notice, this list of conditions and the following disclaimer. 21800e7495SMitchell Horne.\" 2. Redistributions in binary form must reproduce the above copyright 22800e7495SMitchell Horne.\" notice, this list of conditions and the following disclaimer in the 23800e7495SMitchell Horne.\" documentation and/or other materials provided with the distribution. 24800e7495SMitchell Horne.\" 3. All advertising materials mentioning features or use of this software 25800e7495SMitchell Horne.\" must display the following acknowledgement: 26800e7495SMitchell Horne.\" This product includes software developed by Christopher G. Demetriou 27800e7495SMitchell Horne.\" for the NetBSD Project. 28d55c1877SMitchell Horne.\" 4. The name of the author may not be used to endorse or promote products 29800e7495SMitchell Horne.\" derived from this software without specific prior written permission 30800e7495SMitchell Horne.\" 31800e7495SMitchell Horne.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 32800e7495SMitchell Horne.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 33800e7495SMitchell Horne.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 34800e7495SMitchell Horne.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 35800e7495SMitchell Horne.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 36800e7495SMitchell Horne.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 37800e7495SMitchell Horne.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 38800e7495SMitchell Horne.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 39800e7495SMitchell Horne.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 40800e7495SMitchell Horne.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 41800e7495SMitchell Horne.\" 42800e7495SMitchell Horne.\" $FreeBSD$ 43800e7495SMitchell Horne.\" 44d55c1877SMitchell Horne.Dd March 20, 2023 45d55c1877SMitchell Horne.Dt REBOOT 9 46800e7495SMitchell Horne.Os 47800e7495SMitchell Horne.Sh NAME 48*b7caa912SMitchell Horne.Nm kern_reboot , 49*b7caa912SMitchell Horne.Nm shutdown_nice 50d55c1877SMitchell Horne.Nd reboot, halt, or power off the system 51800e7495SMitchell Horne.Sh SYNOPSIS 52800e7495SMitchell Horne.In sys/types.h 53800e7495SMitchell Horne.In sys/systm.h 54800e7495SMitchell Horne.In sys/reboot.h 55d55c1877SMitchell Horne.Vt extern int rebooting; 56800e7495SMitchell Horne.Ft void 57800e7495SMitchell Horne.Fn kern_reboot "int howto" 58*b7caa912SMitchell Horne.Ft void 59*b7caa912SMitchell Horne.Fn shutdown_nice "int howto" 60800e7495SMitchell Horne.In sys/eventhandler.h 61800e7495SMitchell Horne.Fn EVENTHANDLER_REGISTER "shutdown_pre_sync" "shutdown_fn" "private" "priority" 62800e7495SMitchell Horne.Fn EVENTHANDLER_REGISTER "shutdown_post_sync" "shutdown_fn" "private" "priority" 63800e7495SMitchell Horne.Fn EVENTHANDLER_REGISTER "shutdown_final" "shutdown_fn" "private" "priority" 64800e7495SMitchell Horne.Sh DESCRIPTION 65800e7495SMitchell HorneThe 66800e7495SMitchell Horne.Fn kern_reboot 67d55c1877SMitchell Hornefunction handles final system shutdown, and either halts, reboots, 68d55c1877SMitchell Horneor powers down the system. 69800e7495SMitchell HorneThe exact action to be taken is determined by the flags passed in 70d55c1877SMitchell Horne.Fa howto . 71800e7495SMitchell Horne.Pp 72d55c1877SMitchell HorneThe relevant flags are: 73d55c1877SMitchell Horne.Bl -tag -compact -offset indent -width "RB_POWERCYCLE" 74d55c1877SMitchell Horne.It Dv RB_HALT 75d55c1877SMitchell HorneHalt the system in-place rather than restarting. 76d55c1877SMitchell Horne.It Dv RB_POWEROFF 77d55c1877SMitchell HornePower down the system rather than restarting. 78d55c1877SMitchell Horne.It Dv RB_POWERCYCLE 79d55c1877SMitchell HorneRequest a power-cycle in addition to restarting. 80d55c1877SMitchell Horne.It Dv RB_NOSYNC 81d55c1877SMitchell HorneDo not sync filesystems during shutdown. 82d55c1877SMitchell Horne.It Dv RB_DUMP 83d55c1877SMitchell HorneDump kernel memory during shutdown. 84d55c1877SMitchell Horne.El 85d55c1877SMitchell Horne.Pp 86d55c1877SMitchell HorneThe 87d55c1877SMitchell Horne.Fa howto 88d55c1877SMitchell Hornefield, and its full list of flags are described in additional detail by 89d55c1877SMitchell Horne.Xr reboot 2 . 90d55c1877SMitchell Horne.Pp 91800e7495SMitchell Horne.Fn kern_reboot 92d55c1877SMitchell Horneperforms the following actions: 93800e7495SMitchell Horne.Bl -enum -offset indent 94800e7495SMitchell Horne.It 95d55c1877SMitchell HorneSet the 96d55c1877SMitchell Horne.Va rebooting 97d55c1877SMitchell Hornevariable to 98d55c1877SMitchell Horne.Dv 1 , 99d55c1877SMitchell Horneindicating that the reboot process has begun and cannot be stopped. 100d55c1877SMitchell Horne.It 101d55c1877SMitchell HorneSet the 102d55c1877SMitchell Horne.Va kdb_active 103d55c1877SMitchell Hornevariable to 104d55c1877SMitchell Horne.Dv 0 , 105d55c1877SMitchell Horneindicating that execution has left the kernel debugger, if it was previously 106d55c1877SMitchell Horneactive. 107d55c1877SMitchell Horne.It 108d55c1877SMitchell HorneUnless the 109800e7495SMitchell Horne.Dv RB_NOSYNC 110d55c1877SMitchell Horneflag is set in 111800e7495SMitchell Horne.Fa howto , 112d55c1877SMitchell Hornesync and unmount the system's disks by calling 113800e7495SMitchell Horne.Xr vfs_unmountall 9 . 114800e7495SMitchell Horne.It 115d55c1877SMitchell HorneIf rebooting after a panic 116d55c1877SMitchell Horne.Po 117800e7495SMitchell Horne.Dv RB_DUMP 118800e7495SMitchell Horneis set in 119800e7495SMitchell Horne.Fa howto , 120800e7495SMitchell Hornebut 121800e7495SMitchell Horne.Dv RB_HALT 122d55c1877SMitchell Horneis not set 123d55c1877SMitchell Horne.Pc , 124d55c1877SMitchell Horneinitiate a system crash dump via 125d55c1877SMitchell Horne.Fn doadump . 126800e7495SMitchell Horne.It 127d55c1877SMitchell HornePrint a message indicating that the system is about to be halted 128d55c1877SMitchell Horneor rebooted, and a report of the total system uptime. 129800e7495SMitchell Horne.It 130d55c1877SMitchell HorneExecute all registered shutdown hooks. 131800e7495SMitchell Horne.It 132d55c1877SMitchell HorneAs a last resort, if none of the shutdown hooks handled the reboot, call the 133d55c1877SMitchell Hornemachine-dependent 134d55c1877SMitchell Horne.Fn cpu_reset 135d55c1877SMitchell Hornefunction. 136d55c1877SMitchell HorneIn the unlikely case that this is not supported, 137d55c1877SMitchell Horne.Fn kern_reboot 138d55c1877SMitchell Hornewill loop forever at the end of the function. 139d55c1877SMitchell HorneThis requires a manual reset of the system. 140800e7495SMitchell Horne.El 141800e7495SMitchell Horne.Pp 142800e7495SMitchell Horne.Fn kern_reboot 143d55c1877SMitchell Hornemay be called from a typical kernel execution context, when the system is 144d55c1877SMitchell Hornerunning normally. 145d55c1877SMitchell HorneIt may also be called as the final step of a kernel panic, or from the kernel 146d55c1877SMitchell Hornedebugger. 147d55c1877SMitchell HorneTherefore, the code in this function is subject to restrictions described by 148d55c1877SMitchell Hornethe 149d55c1877SMitchell Horne.Sx EXECUTION CONTEXT 150d55c1877SMitchell Hornesection of the 151d55c1877SMitchell Horne.Xr panic 9 152d55c1877SMitchell Horneman page. 153*b7caa912SMitchell Horne.Pp 154*b7caa912SMitchell HorneThe 155*b7caa912SMitchell Horne.Fn shutdown_nice 156*b7caa912SMitchell Hornefunction is the intended path for performing a clean reboot or shutdown when 157*b7caa912SMitchell Hornethe system is operating under normal conditions. 158*b7caa912SMitchell HorneCalling this function will send a signal to the 159*b7caa912SMitchell Horne.Xr init 8 160*b7caa912SMitchell Horneprocess, instructing it to perform a shutdown. 161*b7caa912SMitchell HorneWhen 162*b7caa912SMitchell Horne.Xr init 8 163*b7caa912SMitchell Hornehas cleanly terminated its children, it will perform the 164*b7caa912SMitchell Horne.Xr reboot 2 165*b7caa912SMitchell Hornesystem call, which in turn calls 166*b7caa912SMitchell Horne.Fn kern_reboot . 167*b7caa912SMitchell Horne.Pp 168*b7caa912SMitchell HorneIf 169*b7caa912SMitchell Horne.Fn shutdown_nice 170*b7caa912SMitchell Horneis called before the 171*b7caa912SMitchell Horne.Xr init 8 172*b7caa912SMitchell Horneprocess has been spawned, or if the system has panicked or otherwise halted, 173*b7caa912SMitchell Horne.Fn kern_reboot 174*b7caa912SMitchell Hornewill be called directly. 175800e7495SMitchell Horne.Sh RETURN VALUES 176800e7495SMitchell HorneThe 177800e7495SMitchell Horne.Fn kern_reboot 178800e7495SMitchell Hornefunction does not return. 179*b7caa912SMitchell Horne.Pp 180*b7caa912SMitchell HorneThe 181*b7caa912SMitchell Horne.Fn shutdown_nice 182*b7caa912SMitchell Hornefunction will usually return to its caller, having initiated the asynchronous 183*b7caa912SMitchell Hornesystem shutdown. 184*b7caa912SMitchell HorneIt will not return when called from a panic or debugger context, or during 185*b7caa912SMitchell Horneearly boot. 186800e7495SMitchell Horne.Sh SEE ALSO 18732068667SChristian Brueffer.Xr reboot 2 , 188*b7caa912SMitchell Horne.Xr init 8 , 18932068667SChristian Brueffer.Xr EVENTHANDLER 9 , 190d55c1877SMitchell Horne.Xr panic 9 , 191800e7495SMitchell Horne.Xr vfs_unmountall 9 192