[Midnightbsd-cvs] src [10472] trunk/sbin/reboot: add reroot support to reboot command

laffer1 at midnightbsd.org laffer1 at midnightbsd.org
Wed Jun 6 20:25:31 EDT 2018


Revision: 10472
          http://svnweb.midnightbsd.org/src/?rev=10472
Author:   laffer1
Date:     2018-06-06 20:25:30 -0400 (Wed, 06 Jun 2018)
Log Message:
-----------
add reroot support to reboot command

Modified Paths:
--------------
    trunk/sbin/reboot/boot_i386.8
    trunk/sbin/reboot/nextboot.8
    trunk/sbin/reboot/reboot.8
    trunk/sbin/reboot/reboot.c

Modified: trunk/sbin/reboot/boot_i386.8
===================================================================
--- trunk/sbin/reboot/boot_i386.8	2018-06-07 00:23:42 UTC (rev 10471)
+++ trunk/sbin/reboot/boot_i386.8	2018-06-07 00:25:30 UTC (rev 10472)
@@ -35,6 +35,7 @@
 .\"     @(#)boot_i386.8	8.2 (Berkeley) 4/19/94
 .\"
 .\" $MidnightBSD$
+.\" $FreeBSD: stable/10/sbin/reboot/boot_i386.8 293692 2016-01-11 20:10:14Z trasz $
 .\"
 .Dd July 1, 2013
 .Dt BOOT 8 i386
@@ -220,15 +221,14 @@
 option to force the kernel to use the serial port as its
 console device.
 The serial port driver
-.Xr uart 4
+.Xr sio 4
+(but not
+.Xr uart 4 )
 has a flag (0x20) to override this option.
 If that flag is set, the serial port will always be used as the console,
 regardless of the
 .Fl h
 option described here.
-See the man page for
-.Xr uart 4
-for more details.
 .It Fl m
 mute the console to suppress all console input and output during the
 boot.
@@ -349,9 +349,10 @@
 .Xr make.conf 5 ,
 .Xr ttys 5 ,
 .Xr boot0cfg 8 ,
-.Xr bsdlabel 8 ,
 .Xr btxld 8 ,
 .Xr config 8 ,
+.Xr gpart 8 ,
+.Xr gptboot 8 ,
 .Xr halt 8 ,
 .Xr loader 8 ,
 .Xr nextboot 8 ,

Modified: trunk/sbin/reboot/nextboot.8
===================================================================
--- trunk/sbin/reboot/nextboot.8	2018-06-07 00:23:42 UTC (rev 10471)
+++ trunk/sbin/reboot/nextboot.8	2018-06-07 00:25:30 UTC (rev 10472)
@@ -1,3 +1,4 @@
+.\" $MidnightBSD$
 .\" Copyright (c) 2002 Gordon Tetlow
 .\" All rights reserved.
 .\"
@@ -22,9 +23,9 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.\" $MidnightBSD$
+.\" $FreeBSD: stable/10/sbin/reboot/nextboot.8 307403 2016-10-16 22:02:50Z sevan $
 .\"
-.Dd November 19, 2012
+.Dd March 17, 2015
 .Dt NEXTBOOT 8
 .Os
 .Sh NAME
@@ -118,15 +119,21 @@
 .Fx 5.0 .
 .Sh AUTHORS
 This manual page was written by
-.An Gordon Tetlow Aq gordon at FreeBSD.org .
+.An Gordon Tetlow Aq Mt gordon at FreeBSD.org .
 .Sh BUGS
 The
 .Nm
 code is implemented in the
 .Xr loader 8 .
-It is not the most throughly tested code.
+It is not the most thoroughly tested code.
 It is also my first attempt to write in Forth.
 .Pp
 Finally, it does some evil things like writing to the file system before it
 has been checked.
 If it scrambles your file system, do not blame me.
+.Pp
+.Xr loader 8
+is only able to read ZFS, not write to it.
+.Pa nextboot.conf
+will NOT be reset in case of a kernel boot failure.
+

Modified: trunk/sbin/reboot/reboot.8
===================================================================
--- trunk/sbin/reboot/reboot.8	2018-06-07 00:23:42 UTC (rev 10471)
+++ trunk/sbin/reboot/reboot.8	2018-06-07 00:25:30 UTC (rev 10472)
@@ -1,3 +1,4 @@
+.\" $MidnightBSD$
 .\" Copyright (c) 1990, 1991, 1993
 .\"	The Regents of the University of California.  All rights reserved.
 .\"
@@ -26,9 +27,10 @@
 .\" SUCH DAMAGE.
 .\"
 .\"	@(#)reboot.8	8.1 (Berkeley) 6/9/93
-.\" $MidnightBSD$
+.\" $FreeBSD: stable/10/sbin/reboot/reboot.8 293744 2016-01-12 10:14:57Z trasz $
 .\"
-.Dd October 11, 2010
+.Dd May 22, 2015
+.Dd Jan 06, 2016
 .Dt REBOOT 8
 .Os
 .Sh NAME
@@ -39,16 +41,16 @@
 .Nd stopping and restarting the system
 .Sh SYNOPSIS
 .Nm halt
-.Op Fl lnpq
+.Op Fl lNnpq
 .Op Fl k Ar kernel
 .Nm
-.Op Fl dlnpq
+.Op Fl dlNnpqr
 .Op Fl k Ar kernel
 .Nm fasthalt
-.Op Fl lnpq
+.Op Fl lNnpq
 .Op Fl k Ar kernel
 .Nm fastboot
-.Op Fl dlnpq
+.Op Fl dlNnpq
 .Op Fl k Ar kernel
 .Sh DESCRIPTION
 The
@@ -94,6 +96,16 @@
 or
 .Nm halt
 and log this themselves.
+.It Fl N
+The file system cache is not flushed during the initial process clean-up,
+however the kernel level
+.Xr reboot 2
+is still processed with a sync.
+This option can be useful for performing a
+.Dq best-effort
+reboot when devices might be unavailable.
+This can happen when devices have been disconnected, such as with
+.Xr iscsi 4 .
 .It Fl n
 The file system cache is not flushed.
 This option should probably not be used.
@@ -111,6 +123,13 @@
 .Fl n
 option is not specified).
 This option should probably not be used.
+.It Fl r
+The system kills all processes, unmounts all filesystems, mounts the new
+root filesystem, and begins the usual startup sequence.
+After changing vfs.root.mountfrom with
+.Xr kenv 8 ,
+.Nm Fl r
+can be used to change the root filesystem while preserving kernel state.
 .El
 .Pp
 The
@@ -128,6 +147,13 @@
 utility is used when the system needs to be halted or restarted, giving
 users advance warning of their impending doom and cleanly terminating
 specific programs.
+.Sh EXAMPLES
+Replace current root filesystem with UFS mounted from
+.Pa /dev/ada0s1a :
+.Bd -literal -offset indent
+kenv vfs.root.mountfrom=ufs:/dev/ada0s1a
+reboot -r
+.Ed
 .Sh SEE ALSO
 .Xr getutxent 3 ,
 .Xr boot 8 ,

Modified: trunk/sbin/reboot/reboot.c
===================================================================
--- trunk/sbin/reboot/reboot.c	2018-06-07 00:23:42 UTC (rev 10471)
+++ trunk/sbin/reboot/reboot.c	2018-06-07 00:25:30 UTC (rev 10472)
@@ -60,7 +60,7 @@
 static void usage(void);
 static u_int get_pageins(void);
 
-int dohalt;
+static int dohalt;
 
 int
 main(int argc, char *argv[])
@@ -67,17 +67,17 @@
 {
 	struct utmpx utx;
 	const struct passwd *pw;
-	int ch, howto, i, fd, lflag, nflag, qflag, sverrno;
+	int ch, howto, i, fd, lflag, nflag, qflag, sverrno, Nflag;
 	u_int pageins;
-	const char *p, *user, *kernel = NULL;
+	const char *user, *kernel = NULL;
 
-	if (strstr((p = rindex(*argv, '/')) ? p + 1 : *argv, "halt")) {
+	if (strcmp(getprogname(), "halt") == 0) {
 		dohalt = 1;
 		howto = RB_HALT;
 	} else
 		howto = 0;
-	lflag = nflag = qflag = 0;
-	while ((ch = getopt(argc, argv, "dk:lnpq")) != -1)
+	lflag = nflag = qflag = Nflag = 0;
+	while ((ch = getopt(argc, argv, "dk:lNnpqr")) != -1)
 		switch(ch) {
 		case 'd':
 			howto |= RB_DUMP;
@@ -92,6 +92,10 @@
 			nflag = 1;
 			howto |= RB_NOSYNC;
 			break;
+		case 'N':
+			nflag = 1;
+			Nflag = 1;
+			break;
 		case 'p':
 			howto |= RB_POWEROFF;
 			break;
@@ -98,6 +102,9 @@
 		case 'q':
 			qflag = 1;
 			break;
+		case 'r':
+			howto |= RB_REROOT;
+			break;
 		case '?':
 		default:
 			usage();
@@ -104,9 +111,15 @@
 		}
 	argc -= optind;
 	argv += optind;
+	if (argc != 0)
+		usage();
 
 	if ((howto & (RB_DUMP | RB_HALT)) == (RB_DUMP | RB_HALT))
 		errx(1, "cannot dump (-d) when halting; must reboot instead");
+	if (Nflag && (howto & RB_NOSYNC) != 0)
+		errx(1, "-N cannot be used with -n");
+	if ((howto & RB_REROOT) != 0 && howto != RB_REROOT)
+		errx(1, "-r cannot be used with -d, -n, or -p");
 	if (geteuid()) {
 		errno = EPERM;
 		err(1, NULL);
@@ -137,6 +150,9 @@
 		if (dohalt) {
 			openlog("halt", 0, LOG_AUTH | LOG_CONS);
 			syslog(LOG_CRIT, "halted by %s", user);
+		} else if (howto & RB_REROOT) {
+			openlog("reroot", 0, LOG_AUTH | LOG_CONS);
+			syslog(LOG_CRIT, "rerooted by %s", user);
 		} else {
 			openlog("reboot", 0, LOG_AUTH | LOG_CONS);
 			syslog(LOG_CRIT, "rebooted by %s", user);
@@ -170,6 +186,16 @@
 	 */
 	(void)signal(SIGPIPE, SIG_IGN);
 
+	/*
+	 * Only init(8) can perform rerooting.
+	 */
+	if (howto & RB_REROOT) {
+		if (kill(1, SIGEMT) == -1)
+			err(1, "SIGEMT init");
+
+		return (0);
+	}
+
 	/* Just stop init -- if we fail, we'll restart it. */
 	if (kill(1, SIGTSTP) == -1)
 		err(1, "SIGTSTP init");
@@ -224,8 +250,8 @@
 {
 
 	(void)fprintf(stderr, dohalt ?
-	    "usage: halt [-lnpq] [-k kernel]\n" :
-	    "usage: reboot [-dlnpq] [-k kernel]\n");
+	    "usage: halt [-lNnpq] [-k kernel]\n" :
+	    "usage: reboot [-dlNnpqr] [-k kernel]\n");
 	exit(1);
 }
 



More information about the Midnightbsd-cvs mailing list