1800e7495SMitchell Horne.\" $NetBSD: boot.9,v 1.2 1996/09/24 07:01:26 ghudson Exp $ 2800e7495SMitchell Horne.\" 3*d55c1877SMitchell Horne.\" SPDX-License-Identifier: BSD-4-Clause 4*d55c1877SMitchell 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.\" 11*d55c1877SMitchell Horne.\" Copyright (c) 2021,2023 The FreeBSD Foundation 12*d55c1877SMitchell Horne.\" 13*d55c1877SMitchell Horne.\" Portions of this documentation were written by Mitchell Horne 14*d55c1877SMitchell Horne.\" under sponsorship from the FreeBSD Foundation. 15*d55c1877SMitchell 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. 28*d55c1877SMitchell 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.\" 44*d55c1877SMitchell Horne.Dd March 20, 2023 45*d55c1877SMitchell Horne.Dt REBOOT 9 46800e7495SMitchell Horne.Os 47800e7495SMitchell Horne.Sh NAME 48800e7495SMitchell Horne.Nm kern_reboot 49*d55c1877SMitchell Horne.Nd reboot, halt, or power off the system 50800e7495SMitchell Horne.Sh SYNOPSIS 51800e7495SMitchell Horne.In sys/types.h 52800e7495SMitchell Horne.In sys/systm.h 53800e7495SMitchell Horne.In sys/reboot.h 54*d55c1877SMitchell Horne.Vt extern int rebooting; 55800e7495SMitchell Horne.Ft void 56800e7495SMitchell Horne.Fn kern_reboot "int howto" 57800e7495SMitchell Horne.In sys/eventhandler.h 58800e7495SMitchell Horne.Fn EVENTHANDLER_REGISTER "shutdown_pre_sync" "shutdown_fn" "private" "priority" 59800e7495SMitchell Horne.Fn EVENTHANDLER_REGISTER "shutdown_post_sync" "shutdown_fn" "private" "priority" 60800e7495SMitchell Horne.Fn EVENTHANDLER_REGISTER "shutdown_final" "shutdown_fn" "private" "priority" 61800e7495SMitchell Horne.Sh DESCRIPTION 62800e7495SMitchell HorneThe 63800e7495SMitchell Horne.Fn kern_reboot 64*d55c1877SMitchell Hornefunction handles final system shutdown, and either halts, reboots, 65*d55c1877SMitchell Horneor powers down the system. 66800e7495SMitchell HorneThe exact action to be taken is determined by the flags passed in 67*d55c1877SMitchell Horne.Fa howto . 68800e7495SMitchell Horne.Pp 69*d55c1877SMitchell HorneThe relevant flags are: 70*d55c1877SMitchell Horne.Bl -tag -compact -offset indent -width "RB_POWERCYCLE" 71*d55c1877SMitchell Horne.It Dv RB_HALT 72*d55c1877SMitchell HorneHalt the system in-place rather than restarting. 73*d55c1877SMitchell Horne.It Dv RB_POWEROFF 74*d55c1877SMitchell HornePower down the system rather than restarting. 75*d55c1877SMitchell Horne.It Dv RB_POWERCYCLE 76*d55c1877SMitchell HorneRequest a power-cycle in addition to restarting. 77*d55c1877SMitchell Horne.It Dv RB_NOSYNC 78*d55c1877SMitchell HorneDo not sync filesystems during shutdown. 79*d55c1877SMitchell Horne.It Dv RB_DUMP 80*d55c1877SMitchell HorneDump kernel memory during shutdown. 81*d55c1877SMitchell Horne.El 82*d55c1877SMitchell Horne.Pp 83*d55c1877SMitchell HorneThe 84*d55c1877SMitchell Horne.Fa howto 85*d55c1877SMitchell Hornefield, and its full list of flags are described in additional detail by 86*d55c1877SMitchell Horne.Xr reboot 2 . 87*d55c1877SMitchell Horne.Pp 88800e7495SMitchell Horne.Fn kern_reboot 89*d55c1877SMitchell Horneperforms the following actions: 90800e7495SMitchell Horne.Bl -enum -offset indent 91800e7495SMitchell Horne.It 92*d55c1877SMitchell HorneSet the 93*d55c1877SMitchell Horne.Va rebooting 94*d55c1877SMitchell Hornevariable to 95*d55c1877SMitchell Horne.Dv 1 , 96*d55c1877SMitchell Horneindicating that the reboot process has begun and cannot be stopped. 97*d55c1877SMitchell Horne.It 98*d55c1877SMitchell HorneSet the 99*d55c1877SMitchell Horne.Va kdb_active 100*d55c1877SMitchell Hornevariable to 101*d55c1877SMitchell Horne.Dv 0 , 102*d55c1877SMitchell Horneindicating that execution has left the kernel debugger, if it was previously 103*d55c1877SMitchell Horneactive. 104*d55c1877SMitchell Horne.It 105*d55c1877SMitchell HorneUnless the 106800e7495SMitchell Horne.Dv RB_NOSYNC 107*d55c1877SMitchell Horneflag is set in 108800e7495SMitchell Horne.Fa howto , 109*d55c1877SMitchell Hornesync and unmount the system's disks by calling 110800e7495SMitchell Horne.Xr vfs_unmountall 9 . 111800e7495SMitchell Horne.It 112*d55c1877SMitchell HorneIf rebooting after a panic 113*d55c1877SMitchell Horne.Po 114800e7495SMitchell Horne.Dv RB_DUMP 115800e7495SMitchell Horneis set in 116800e7495SMitchell Horne.Fa howto , 117800e7495SMitchell Hornebut 118800e7495SMitchell Horne.Dv RB_HALT 119*d55c1877SMitchell Horneis not set 120*d55c1877SMitchell Horne.Pc , 121*d55c1877SMitchell Horneinitiate a system crash dump via 122*d55c1877SMitchell Horne.Fn doadump . 123800e7495SMitchell Horne.It 124*d55c1877SMitchell HornePrint a message indicating that the system is about to be halted 125*d55c1877SMitchell Horneor rebooted, and a report of the total system uptime. 126800e7495SMitchell Horne.It 127*d55c1877SMitchell HorneExecute all registered shutdown hooks. 128800e7495SMitchell Horne.It 129*d55c1877SMitchell HorneAs a last resort, if none of the shutdown hooks handled the reboot, call the 130*d55c1877SMitchell Hornemachine-dependent 131*d55c1877SMitchell Horne.Fn cpu_reset 132*d55c1877SMitchell Hornefunction. 133*d55c1877SMitchell HorneIn the unlikely case that this is not supported, 134*d55c1877SMitchell Horne.Fn kern_reboot 135*d55c1877SMitchell Hornewill loop forever at the end of the function. 136*d55c1877SMitchell HorneThis requires a manual reset of the system. 137800e7495SMitchell Horne.El 138800e7495SMitchell Horne.Pp 139800e7495SMitchell Horne.Fn kern_reboot 140*d55c1877SMitchell Hornemay be called from a typical kernel execution context, when the system is 141*d55c1877SMitchell Hornerunning normally. 142*d55c1877SMitchell HorneIt may also be called as the final step of a kernel panic, or from the kernel 143*d55c1877SMitchell Hornedebugger. 144*d55c1877SMitchell HorneTherefore, the code in this function is subject to restrictions described by 145*d55c1877SMitchell Hornethe 146*d55c1877SMitchell Horne.Sx EXECUTION CONTEXT 147*d55c1877SMitchell Hornesection of the 148*d55c1877SMitchell Horne.Xr panic 9 149*d55c1877SMitchell Horneman page. 150800e7495SMitchell Horne.Sh RETURN VALUES 151800e7495SMitchell HorneThe 152800e7495SMitchell Horne.Fn kern_reboot 153800e7495SMitchell Hornefunction does not return. 154800e7495SMitchell Horne.Sh SEE ALSO 15532068667SChristian Brueffer.Xr reboot 2 , 15632068667SChristian Brueffer.Xr EVENTHANDLER 9 , 157*d55c1877SMitchell Horne.Xr panic 9 , 158800e7495SMitchell Horne.Xr vfs_unmountall 9 159