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.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 14:52:23 -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"
 
@@ -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[5];
+               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