Now with manpage diff, fixed usage and less magic numbers (thanks to
florian@ again for the last two).

Paul

On Mon, Nov 06, 2017 at 03:58:50PM +0100, Paul de Weerd wrote:
| installboot(8) will error out when not given a device to install to:
| 
| [weerd@pom] $ doas installboot
| usage: installboot [-nv] [-r root] disk [stage1 [stage2]]
| 
| Here's a diff that will make it default to the device carrying the
| root filesystem.  Result this:
| 
| [weerd@pom] $ doas obj/installboot -v
| Using / as root
| installing bootstrap on /dev/rsd10c
| using first-stage /usr/mdec/biosboot, second-stage /usr/mdec/boot
| sd10: softraid volume with 1 disk(s)
| sd10: installing boot loader on softraid volume
| /usr/mdec/boot is 5 blocks x 16384 bytes
| sd0a: installing boot blocks on /dev/rsd0c, part offset 144
| master boot record (MBR) at sector 0
|         partition 3: type 0xA6 offset 64 size 1953520001
| /usr/mdec/biosboot will be written at sector 64
| 
| Thanks to fobser@ for the cluebat, preventing me from diving too deep
| into pcreapi(3)...
| 
| Comments?
| 
| Paul 'WEiRD' de Weerd

Index: installboot.8
===================================================================
RCS file: /cvs/src/usr.sbin/installboot/installboot.8,v
retrieving revision 1.4
diff -u -p -r1.4 installboot.8
--- installboot.8       18 Jan 2014 18:14:21 -0000      1.4
+++ installboot.8       6 Nov 2017 15:12:54 -0000
@@ -24,8 +24,7 @@
 .Nm installboot
 .Op Fl nv
 .Op Fl r Ar root
-.Ar disk
-.Op Ar stage1 Op Ar stage2
+.Op Ar disk Op Ar stage1 Op Ar stage2
 .Sh DESCRIPTION
 .Nm
 installs bootstrap on the specified disk.
@@ -52,6 +51,7 @@ Specify the
 to install the bootstrap on.
 This may be specified using a full pathname, an abbreviated disk form,
 or a disklabel UID.
+It defaults to the device with the root filesystem.
 .It Ar stage1
 Specify the file to use for the primary bootstrap.
 If not specified, the default for this architecture will be used.
Index: installboot.c
===================================================================
RCS file: /cvs/src/usr.sbin/installboot/installboot.c,v
retrieving revision 1.11
diff -u -p -r1.11 installboot.c
--- installboot.c       29 Nov 2015 00:14:07 -0000      1.11
+++ installboot.c       6 Nov 2017 15:14:21 -0000
@@ -23,6 +23,8 @@
 #include <string.h>
 #include <unistd.h>
 #include <util.h>
+#include <sys/param.h>
+#include <sys/mount.h>
 
 #include "installboot.h"
 
@@ -39,7 +41,7 @@ usage(void)
 {
        extern char *__progname;
 
-       fprintf(stderr, "usage: %s [-nv] [-r root] disk [stage1%s]\n",
+       fprintf(stderr, "usage: %s [-nv] [-r root] [disk [stage1%s]]\n",
            __progname, (stages >= 2) ? " [stage2]" : "");
 
        exit(1);
@@ -50,6 +52,7 @@ main(int argc, char **argv)
 {
        char *dev, *realdev;
        int devfd, opt;
+       struct statfs buf;
 
        md_init();
 
@@ -74,10 +77,18 @@ main(int argc, char **argv)
        argc -= optind;
        argv += optind;
 
-       if (argc < 1 || argc > stages + 1)
+       if (argc > stages + 1)
                usage();
 
-       dev = argv[0];
+       /* default to the device carrying the root filesystem */
+       if (argc == 0) {
+               statfs("/", &buf);
+               dev = &buf.f_mntfromname[sizeof("/dev/") - 1];
+               dev[strlen(dev) - 1] = '\0';
+       } else {
+               dev = argv[0];
+       }
+
        if (argc > 1)
                stage1 = argv[1];
        if (argc > 2)

-- 
>++++++++[<++++++++++>-]<+++++++.>+++[<------>-]<.>+++[<+
+++++++++++>-]<.>++[<------------>-]<+.--------------.[-]
                 http://www.weirdnet.nl/                 

Reply via email to