From c770c5a23ae92b3b4de79c9c7b87716f7881c07b Mon Sep 17 00:00:00 2001 From: kn Date: Fri, 19 Aug 2022 08:27:48 +0000 Subject: [PATCH] Split -p into own synopsis Platform-dependent preparation of the filesystem required by the boot loader only ever creates a new fileystem without instaling using any bootstrap files. To reflect reality, turn # installboot -nvp vnd0 Using / as root would install bootstrap on /dev/rvnd0c using first-stage /usr/mdec/biosboot, second-stage /usr/mdec/boot would newfs 545c9bdf92aa18f9.i into # ./obj/installboot -nvp vnd0 would newfs 4db2c0e89e0d3268.i and error out if -p is combined with -r or stages: $ man -hl./installboot.8 installboot [-nv] [-r root] disk [stage1 [stage2]] installboot [-nv] -p disk Feedback OK millert --- usr.sbin/installboot/installboot.8 | 12 ++++++---- usr.sbin/installboot/installboot.c | 37 +++++++++++++++--------------- 2 files changed, 27 insertions(+), 22 deletions(-) diff --git a/usr.sbin/installboot/installboot.8 b/usr.sbin/installboot/installboot.8 index 3429ffcfbf9..a9a7f44a9cb 100644 --- a/usr.sbin/installboot/installboot.8 +++ b/usr.sbin/installboot/installboot.8 @@ -1,4 +1,4 @@ -.\" $OpenBSD: installboot.8,v 1.5 2021/07/20 14:51:56 kettenis Exp $ +.\" $OpenBSD: installboot.8,v 1.6 2022/08/19 08:27:48 kn Exp $ .\" .\" Copyright (c) 2013, 2014 Joel Sing .\" @@ -14,7 +14,7 @@ .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" -.Dd $Mdocdate: July 20 2021 $ +.Dd $Mdocdate: August 19 2022 $ .Dt INSTALLBOOT 8 .Os .Sh NAME @@ -22,10 +22,14 @@ .Nd install bootstrap on a disk .Sh SYNOPSIS .Nm installboot -.Op Fl npv +.Op Fl nv .Op Fl r Ar root .Ar disk .Op Ar stage1 Op Ar stage2 +.Nm +.Op Fl nv +.Fl p +.Ar disk .Sh DESCRIPTION .Nm installs bootstrap on the specified disk. @@ -38,7 +42,7 @@ the beginning of the disk. The options are as follows: .Bl -tag -width Ds .It Fl n -Perform a dry run - do not actually write any bootstrap to the disk. +Perform a dry run - do not actually write to the disk. .It Fl p Prepare filesystem. This will create a new filesystem on the partition reserved for the diff --git a/usr.sbin/installboot/installboot.c b/usr.sbin/installboot/installboot.c index 6f79d397886..824a5ad9179 100644 --- a/usr.sbin/installboot/installboot.c +++ b/usr.sbin/installboot/installboot.c @@ -1,4 +1,4 @@ -/* $OpenBSD: installboot.c,v 1.14 2021/07/20 14:51:56 kettenis Exp $ */ +/* $OpenBSD: installboot.c,v 1.15 2022/08/19 08:27:48 kn Exp $ */ /* * Copyright (c) 2012, 2013 Joel Sing @@ -31,17 +31,16 @@ int prepare; int stages; int verbose; -char *root = "/"; +char *root; char *stage1; char *stage2; static __dead void usage(void) { - extern char *__progname; - - fprintf(stderr, "usage: %s [-npv] [-r root] disk [stage1%s]\n", - __progname, (stages >= 2) ? " [stage2]" : ""); + fprintf(stderr, "usage:\t%1$s [-nv] [-r root] disk [stage1%2$s]\n" + "\t%1$s [-nv] -p disk\n", + getprogname(), (stages >= 2) ? " [stage2]" : ""); exit(1); } @@ -63,9 +62,7 @@ main(int argc, char **argv) prepare = 1; break; case 'r': - root = strdup(optarg); - if (root == NULL) - err(1, "strdup"); + root = optarg; break; case 'v': verbose = 1; @@ -80,6 +77,8 @@ main(int argc, char **argv) if (argc < 1 || argc > stages + 1) usage(); + if (prepare && (root != NULL || argc > 1)) + usage(); dev = argv[0]; if (argc > 1) @@ -87,7 +86,18 @@ main(int argc, char **argv) if (argc > 2) stage2 = argv[2]; + if ((devfd = opendev(dev, (nowrite ? O_RDONLY : O_RDWR), OPENDEV_PART, + &realdev)) == -1) + err(1, "open: %s", realdev); + + if (prepare) { + md_prepareboot(devfd, realdev); + return 0; + } + /* Prefix stages with root, unless they were user supplied. */ + if (root == NULL) + root = "/"; if (verbose) fprintf(stderr, "Using %s as root\n", root); if (argc <= 1 && stage1 != NULL) { @@ -101,10 +111,6 @@ main(int argc, char **argv) exit(1); } - if ((devfd = opendev(dev, (nowrite ? O_RDONLY : O_RDWR), OPENDEV_PART, - &realdev)) == -1) - err(1, "open: %s", realdev); - if (verbose) { fprintf(stderr, "%s bootstrap on %s\n", (nowrite ? "would install" : "installing"), realdev); @@ -119,11 +125,6 @@ main(int argc, char **argv) md_loadboot(); - if (prepare) { - md_prepareboot(devfd, realdev); - return 0; - } - #ifdef SOFTRAID sr_installboot(devfd, dev); #else -- 2.20.1