-/* $OpenBSD: armv7_installboot.c,v 1.10 2021/06/27 04:52:01 jsg Exp $ */
+/* $OpenBSD: armv7_installboot.c,v 1.11 2021/07/20 14:51:56 kettenis Exp $ */
/* $NetBSD: installboot.c,v 1.5 1995/11/17 23:23:50 gwr Exp $ */
/*
#include "installboot.h"
+static int create_filesystem(struct disklabel *, char);
static void write_filesystem(struct disklabel *, char);
static int findgptefisys(int, struct disklabel *);
static int findmbrfat(int, struct disklabel *);
{
}
+void
+md_prepareboot(int devfd, char *dev)
+{
+ struct disklabel dl;
+ int part;
+
+ /* Get and check disklabel. */
+ if (ioctl(devfd, DIOCGDINFO, &dl) == -1)
+ err(1, "disklabel: %s", dev);
+ if (dl.d_magic != DISKMAGIC)
+ errx(1, "bad disklabel magic=0x%08x", dl.d_magic);
+
+ /* Warn on unknown disklabel types. */
+ if (dl.d_type == 0)
+ warnx("disklabel type unknown");
+
+ part = findgptefisys(devfd, &dl);
+ if (part != -1) {
+ create_filesystem(&dl, (char)part);
+ return;
+ }
+
+ part = findmbrfat(devfd, &dl);
+ if (part != -1) {
+ create_filesystem(&dl, (char)part);
+ return;
+ }
+}
+
void
md_installboot(int devfd, char *dev)
{
}
}
+static int
+create_filesystem(struct disklabel *dl, char part)
+{
+ static char *newfsfmt ="/sbin/newfs_msdos %s >/dev/null";
+ struct msdosfs_args args;
+ char cmd[60];
+ int rslt;
+
+ /* Mount <duid>.<part> as msdos filesystem. */
+ memset(&args, 0, sizeof(args));
+ rslt = asprintf(&args.fspec,
+ "%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx.%c",
+ dl->d_uid[0], dl->d_uid[1], dl->d_uid[2], dl->d_uid[3],
+ dl->d_uid[4], dl->d_uid[5], dl->d_uid[6], dl->d_uid[7],
+ part);
+ if (rslt == -1) {
+ warn("bad special device");
+ return rslt;
+ }
+
+ rslt = snprintf(cmd, sizeof(cmd), newfsfmt, args.fspec);
+ if (rslt >= sizeof(cmd)) {
+ warnx("can't build newfs command");
+ rslt = -1;
+ return rslt;
+ }
+
+ if (verbose)
+ fprintf(stderr, "%s %s\n",
+ (nowrite ? "would newfs" : "newfsing"), args.fspec);
+ if (!nowrite) {
+ rslt = system(cmd);
+ if (rslt == -1) {
+ warn("system('%s') failed", cmd);
+ return rslt;
+ }
+ }
+
+ return 0;
+}
static void
write_filesystem(struct disklabel *dl, char part)
{
static char *fsckfmt = "/sbin/fsck_msdos %s >/dev/null";
- static char *newfsfmt ="/sbin/newfs_msdos %s >/dev/null";
struct msdosfs_args args;
char cmd[60];
char dst[PATH_MAX];
}
if (mount(MOUNT_MSDOS, dst, 0, &args) == -1) {
/* Try newfs'ing it. */
- rslt = snprintf(cmd, sizeof(cmd), newfsfmt,
- args.fspec);
- if (rslt >= sizeof(cmd)) {
- warnx("can't build newfs command");
- rslt = -1;
+ rslt = create_filesystem(dl, part);
+ if (rslt == -1)
goto rmdir;
- }
- rslt = system(cmd);
- if (rslt == -1) {
- warn("system('%s') failed", cmd);
- goto rmdir;
- }
rslt = mount(MOUNT_MSDOS, dst, 0, &args);
if (rslt == -1) {
warn("unable to mount EFI System partition");
-/* $OpenBSD: hppa_installboot.c,v 1.3 2018/09/01 16:55:29 krw Exp $ */
+/* $OpenBSD: hppa_installboot.c,v 1.4 2021/07/20 14:51:56 kettenis Exp $ */
/*
* Copyright (c) 2013 Joel Sing <jsing@openbsd.org>
{
}
+void
+md_prepareboot(int devfd, char *dev)
+{
+}
+
void
md_installboot(int devfd, char *dev)
{
-/* $OpenBSD: i386_installboot.c,v 1.39 2021/06/02 22:44:27 krw Exp $ */
+/* $OpenBSD: i386_installboot.c,v 1.40 2021/07/20 14:51:56 kettenis Exp $ */
/* $NetBSD: installboot.c,v 1.5 1995/11/17 23:23:50 gwr Exp $ */
/*
errx(1, "proto bootblocks too big");
}
+void
+md_prepareboot(int devfd, char *dev)
+{
+ struct disklabel dl;
+ int part;
+
+ /* Get and check disklabel. */
+ if (ioctl(devfd, DIOCGDINFO, &dl) == -1)
+ err(1, "disklabel: %s", dev);
+ if (dl.d_magic != DISKMAGIC)
+ errx(1, "bad disklabel magic=0x%08x", dl.d_magic);
+
+ /* Warn on unknown disklabel types. */
+ if (dl.d_type == 0)
+ warnx("disklabel type unknown");
+
+ part = findgptefisys(devfd, &dl);
+ if (part != -1) {
+ create_filesystem(&dl, (char)part);
+ return;
+ }
+}
+
void
md_installboot(int devfd, char *dev)
{
}
}
+int
+create_filesystem(struct disklabel *dl, char part)
+{
+ static char *newfsfmt ="/sbin/newfs_msdos %s >/dev/null";
+ struct msdosfs_args args;
+ char cmd[60];
+ int rslt;
+
+ /* Mount <duid>.<part> as msdos filesystem. */
+ memset(&args, 0, sizeof(args));
+ rslt = asprintf(&args.fspec,
+ "%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx.%c",
+ dl->d_uid[0], dl->d_uid[1], dl->d_uid[2], dl->d_uid[3],
+ dl->d_uid[4], dl->d_uid[5], dl->d_uid[6], dl->d_uid[7],
+ part);
+ if (rslt == -1) {
+ warn("bad special device");
+ return rslt;
+ }
+
+ rslt = snprintf(cmd, sizeof(cmd), newfsfmt, args.fspec);
+ if (rslt >= sizeof(cmd)) {
+ warnx("can't build newfs command");
+ rslt = -1;
+ return rslt;
+ }
+
+ if (verbose)
+ fprintf(stderr, "%s %s\n",
+ (nowrite ? "would newfs" : "newfsing"), args.fspec);
+ if (!nowrite) {
+ rslt = system(cmd);
+ if (rslt == -1) {
+ warn("system('%s') failed", cmd);
+ return rslt;
+ }
+ }
+
+ return 0;
+}
+
void
write_filesystem(struct disklabel *dl, char part)
{
static char *fsckfmt = "/sbin/fsck_msdos %s >/dev/null";
- static char *newfsfmt ="/sbin/newfs_msdos %s >/dev/null";
struct msdosfs_args args;
char cmd[60];
char dst[PATH_MAX];
}
if (mount(MOUNT_MSDOS, dst, 0, &args) == -1) {
/* Try newfs'ing it. */
- rslt = snprintf(cmd, sizeof(cmd), newfsfmt,
- args.fspec);
- if (rslt >= sizeof(cmd)) {
- warnx("can't build newfs command");
- rslt = -1;
+ rslt = create_filesystem(dl, part);
+ if (rslt == -1)
goto rmdir;
- }
- rslt = system(cmd);
- if (rslt == -1) {
- warn("system('%s') failed", cmd);
- goto rmdir;
- }
rslt = mount(MOUNT_MSDOS, dst, 0, &args);
if (rslt == -1) {
warn("unable to mount EFI System partition");
-/* $OpenBSD: i386_installboot.h,v 1.6 2020/06/27 15:35:29 deraadt Exp $ */
+/* $OpenBSD: i386_installboot.h,v 1.7 2021/07/20 14:51:56 kettenis Exp $ */
/*
* Copyright (c) 2011 Joel Sing <jsing@openbsd.org>
* Copyright (c) 2003 Tom Cosgrove <tom.cosgrove@arches-consulting.com>
void sym_set_value(struct sym_data *, char *, u_int32_t);
void write_bootblocks(int, char *, struct disklabel *);
int findgptefisys(int, struct disklabel *);
+int create_filesystem(struct disklabel *, char);
void write_filesystem(struct disklabel *, char);
-.\" $OpenBSD: installboot.8,v 1.4 2014/01/18 18:14:21 jmc Exp $
+.\" $OpenBSD: installboot.8,v 1.5 2021/07/20 14:51:56 kettenis Exp $
.\"
.\" Copyright (c) 2013, 2014 Joel Sing
.\"
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
-.Dd $Mdocdate: January 18 2014 $
+.Dd $Mdocdate: July 20 2021 $
.Dt INSTALLBOOT 8
.Os
.Sh NAME
.Nd install bootstrap on a disk
.Sh SYNOPSIS
.Nm installboot
-.Op Fl nv
+.Op Fl npv
.Op Fl r Ar root
.Ar disk
.Op Ar stage1 Op Ar stage2
.Bl -tag -width Ds
.It Fl n
Perform a dry run - do not actually write any bootstrap to the disk.
+.It Fl p
+Prepare filesystem.
+This will create a new filesystem on the partition reserved for the
+boot loader on architectures that require one.
.It Fl r Ar root
Specify the mount point of the
.Ar root
-/* $OpenBSD: installboot.c,v 1.13 2019/10/29 17:41:45 deraadt Exp $ */
+/* $OpenBSD: installboot.c,v 1.14 2021/07/20 14:51:56 kettenis Exp $ */
/*
* Copyright (c) 2012, 2013 Joel Sing <jsing@openbsd.org>
#include "installboot.h"
int nowrite;
+int prepare;
int stages;
int verbose;
{
extern char *__progname;
- fprintf(stderr, "usage: %s [-nv] [-r root] disk [stage1%s]\n",
+ fprintf(stderr, "usage: %s [-npv] [-r root] disk [stage1%s]\n",
__progname, (stages >= 2) ? " [stage2]" : "");
exit(1);
md_init();
- while ((opt = getopt(argc, argv, "nr:v")) != -1) {
+ while ((opt = getopt(argc, argv, "npr:v")) != -1) {
switch (opt) {
case 'n':
nowrite = 1;
break;
+ case 'p':
+ prepare = 1;
+ break;
case 'r':
root = strdup(optarg);
if (root == NULL)
md_loadboot();
+ if (prepare) {
+ md_prepareboot(devfd, realdev);
+ return 0;
+ }
+
#ifdef SOFTRAID
sr_installboot(devfd, dev);
#else
-/* $OpenBSD: installboot.h,v 1.12 2020/06/08 19:17:12 kn Exp $ */
+/* $OpenBSD: installboot.h,v 1.13 2021/07/20 14:51:56 kettenis Exp $ */
/*
* Copyright (c) 2012, 2013 Joel Sing <jsing@openbsd.org>
*
void md_init(void);
void md_loadboot(void);
+void md_prepareboot(int, char *);
void md_installboot(int, char *);
#ifdef SOFTRAID
-/* $OpenBSD: landisk_installboot.c,v 1.9 2018/09/01 16:55:29 krw Exp $ */
+/* $OpenBSD: landisk_installboot.c,v 1.10 2021/07/20 14:51:56 kettenis Exp $ */
/*
* Copyright (c) 2013 Joel Sing <jsing@openbsd.org>
{
}
+void
+md_prepareboot(int devfd, char *dev)
+{
+}
+
void
md_installboot(int devfd, char *dev)
{
-/* $OpenBSD: loongson_installboot.c,v 1.3 2020/07/19 15:23:08 visa Exp $ */
+/* $OpenBSD: loongson_installboot.c,v 1.4 2021/07/20 14:51:56 kettenis Exp $ */
/* $NetBSD: installboot.c,v 1.5 1995/11/17 23:23:50 gwr Exp $ */
/*
{
}
+void
+md_prepareboot(int devfd, char *dev)
+{
+}
+
void
md_installboot(int devfd, char *dev)
{
-/* $OpenBSD: macppc_installboot.c,v 1.3 2020/07/22 05:06:38 deraadt Exp $ */
+/* $OpenBSD: macppc_installboot.c,v 1.4 2021/07/20 14:51:56 kettenis Exp $ */
/*
* Copyright (c) 2011 Joel Sing <jsing@openbsd.org>
#include "installboot.h"
+static int create_filesystem(struct disklabel *, char);
static void write_filesystem(struct disklabel *, char);
static int findmbrfat(int, struct disklabel *);
{
}
+void
+md_prepareboot(int devfd, char *dev)
+{
+ struct disklabel dl;
+ int part;
+
+ /* Get and check disklabel. */
+ if (ioctl(devfd, DIOCGDINFO, &dl) == -1)
+ err(1, "disklabel: %s", dev);
+ if (dl.d_magic != DISKMAGIC)
+ errx(1, "bad disklabel magic=0x%08x", dl.d_magic);
+
+ /* Warn on unknown disklabel types. */
+ if (dl.d_type == 0)
+ warnx("disklabel type unknown");
+
+ part = findmbrfat(devfd, &dl);
+ if (part != -1) {
+ create_filesystem(&dl, (char)part);
+ return;
+ }
+}
+
void
md_installboot(int devfd, char *dev)
{
}
}
+static int
+create_filesystem(struct disklabel *dl, char part)
+{
+ static char *newfsfmt ="/sbin/newfs_msdos %s >/dev/null";
+ struct msdosfs_args args;
+ char cmd[60];
+ int rslt;
+
+ /* Mount <duid>.<part> as msdos filesystem. */
+ memset(&args, 0, sizeof(args));
+ rslt = asprintf(&args.fspec,
+ "%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx.%c",
+ dl->d_uid[0], dl->d_uid[1], dl->d_uid[2], dl->d_uid[3],
+ dl->d_uid[4], dl->d_uid[5], dl->d_uid[6], dl->d_uid[7],
+ part);
+ if (rslt == -1) {
+ warn("bad special device");
+ return rslt;
+ }
+
+ rslt = snprintf(cmd, sizeof(cmd), newfsfmt, args.fspec);
+ if (rslt >= sizeof(cmd)) {
+ warnx("can't build newfs command");
+ rslt = -1;
+ return rslt;
+ }
+
+ if (verbose)
+ fprintf(stderr, "%s %s\n",
+ (nowrite ? "would newfs" : "newfsing"), args.fspec);
+ if (!nowrite) {
+ rslt = system(cmd);
+ if (rslt == -1) {
+ warn("system('%s') failed", cmd);
+ return rslt;
+ }
+ }
+
+ return 0;
+}
static void
write_filesystem(struct disklabel *dl, char part)
{
static char *fsckfmt = "/sbin/fsck_msdos %s >/dev/null";
- static char *newfsfmt ="/sbin/newfs_msdos %s >/dev/null";
struct msdosfs_args args;
char cmd[60];
char dst[PATH_MAX];
}
if (mount(MOUNT_MSDOS, dst, 0, &args) == -1) {
/* Try newfs'ing it. */
- rslt = snprintf(cmd, sizeof(cmd), newfsfmt,
- args.fspec);
- if (rslt >= sizeof(cmd)) {
- warnx("can't build newfs command");
- rslt = -1;
- goto rmdir;
- }
- rslt = system(cmd);
- if (rslt == -1) {
- warn("system('%s') failed", cmd);
+ rslt = create_filesystem(dl, part);
+ if (rslt == -1)
goto rmdir;
- }
rslt = mount(MOUNT_MSDOS, dst, 0, &args);
if (rslt == -1) {
warn("unable to mount MSDOS partition");
-/* $OpenBSD: octeon_installboot.c,v 1.3 2020/07/22 05:06:38 deraadt Exp $ */
+/* $OpenBSD: octeon_installboot.c,v 1.4 2021/07/20 14:51:56 kettenis Exp $ */
/*
* Copyright (c) 2011 Joel Sing <jsing@openbsd.org>
#include "installboot.h"
+static int create_filesystem(struct disklabel *, char);
static void write_filesystem(struct disklabel *, char);
static int findmbrfat(int, struct disklabel *);
{
}
+void
+md_prepareboot(int devfd, char *dev)
+{
+ struct disklabel dl;
+ int part;
+
+ /* Get and check disklabel. */
+ if (ioctl(devfd, DIOCGDINFO, &dl) == -1)
+ err(1, "disklabel: %s", dev);
+ if (dl.d_magic != DISKMAGIC)
+ errx(1, "bad disklabel magic=0x%08x", dl.d_magic);
+
+ /* Warn on unknown disklabel types. */
+ if (dl.d_type == 0)
+ warnx("disklabel type unknown");
+
+ part = findmbrfat(devfd, &dl);
+ if (part != -1) {
+ create_filesystem(&dl, (char)part);
+ return;
+ }
+}
+
void
md_installboot(int devfd, char *dev)
{
}
}
+static int
+create_filesystem(struct disklabel *dl, char part)
+{
+ static char *newfsfmt ="/sbin/newfs_msdos %s >/dev/null";
+ struct msdosfs_args args;
+ char cmd[60];
+ int rslt;
+
+ /* Mount <duid>.<part> as msdos filesystem. */
+ memset(&args, 0, sizeof(args));
+ rslt = asprintf(&args.fspec,
+ "%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx.%c",
+ dl->d_uid[0], dl->d_uid[1], dl->d_uid[2], dl->d_uid[3],
+ dl->d_uid[4], dl->d_uid[5], dl->d_uid[6], dl->d_uid[7],
+ part);
+ if (rslt == -1) {
+ warn("bad special device");
+ return rslt;
+ }
+
+ rslt = snprintf(cmd, sizeof(cmd), newfsfmt, args.fspec);
+ if (rslt >= sizeof(cmd)) {
+ warnx("can't build newfs command");
+ rslt = -1;
+ return rslt;
+ }
+
+ if (verbose)
+ fprintf(stderr, "%s %s\n",
+ (nowrite ? "would newfs" : "newfsing"), args.fspec);
+ if (!nowrite) {
+ rslt = system(cmd);
+ if (rslt == -1) {
+ warn("system('%s') failed", cmd);
+ return rslt;
+ }
+ }
+
+ return 0;
+}
static void
write_filesystem(struct disklabel *dl, char part)
{
static char *fsckfmt = "/sbin/fsck_msdos %s >/dev/null";
- static char *newfsfmt ="/sbin/newfs_msdos %s >/dev/null";
struct msdosfs_args args;
char cmd[60];
char dst[PATH_MAX];
}
if (mount(MOUNT_MSDOS, dst, 0, &args) == -1) {
/* Try newfs'ing it. */
- rslt = snprintf(cmd, sizeof(cmd), newfsfmt,
- args.fspec);
- if (rslt >= sizeof(cmd)) {
- warnx("can't build newfs command");
- rslt = -1;
- goto rmdir;
- }
- rslt = system(cmd);
- if (rslt == -1) {
- warn("system('%s') failed", cmd);
+ rslt = create_filesystem(dl, part);
+ if (rslt == -1)
goto rmdir;
- }
rslt = mount(MOUNT_MSDOS, dst, 0, &args);
if (rslt == -1) {
warn("unable to mount MSDOS partition");
-/* $OpenBSD: powerpc64_installboot.c,v 1.2 2020/07/18 15:28:38 deraadt Exp $ */
+/* $OpenBSD: powerpc64_installboot.c,v 1.3 2021/07/20 14:51:56 kettenis Exp $ */
/*
* Copyright (c) 2011 Joel Sing <jsing@openbsd.org>
#include "installboot.h"
+static int create_filesystem(struct disklabel *, char);
static void write_filesystem(struct disklabel *, char);
static int findmbrfat(int, struct disklabel *);
{
}
+void
+md_prepareboot(int devfd, char *dev)
+{
+ struct disklabel dl;
+ int part;
+
+ /* Get and check disklabel. */
+ if (ioctl(devfd, DIOCGDINFO, &dl) == -1)
+ err(1, "disklabel: %s", dev);
+ if (dl.d_magic != DISKMAGIC)
+ errx(1, "bad disklabel magic=0x%08x", dl.d_magic);
+
+ /* Warn on unknown disklabel types. */
+ if (dl.d_type == 0)
+ warnx("disklabel type unknown");
+
+ part = findmbrfat(devfd, &dl);
+ if (part != -1) {
+ create_filesystem(&dl, (char)part);
+ return;
+ }
+}
+
void
md_installboot(int devfd, char *dev)
{
}
}
+static int
+create_filesystem(struct disklabel *dl, char part)
+{
+ static char *newfsfmt ="/sbin/newfs_msdos %s >/dev/null";
+ struct msdosfs_args args;
+ char cmd[60];
+ int rslt;
+
+ /* Mount <duid>.<part> as msdos filesystem. */
+ memset(&args, 0, sizeof(args));
+ rslt = asprintf(&args.fspec,
+ "%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx.%c",
+ dl->d_uid[0], dl->d_uid[1], dl->d_uid[2], dl->d_uid[3],
+ dl->d_uid[4], dl->d_uid[5], dl->d_uid[6], dl->d_uid[7],
+ part);
+ if (rslt == -1) {
+ warn("bad special device");
+ return rslt;
+ }
+
+ rslt = snprintf(cmd, sizeof(cmd), newfsfmt, args.fspec);
+ if (rslt >= sizeof(cmd)) {
+ warnx("can't build newfs command");
+ rslt = -1;
+ return rslt;
+ }
+
+ if (verbose)
+ fprintf(stderr, "%s %s\n",
+ (nowrite ? "would newfs" : "newfsing"), args.fspec);
+ if (!nowrite) {
+ rslt = system(cmd);
+ if (rslt == -1) {
+ warn("system('%s') failed", cmd);
+ return rslt;
+ }
+ }
+
+ return 0;
+}
static void
write_filesystem(struct disklabel *dl, char part)
{
static char *fsckfmt = "/sbin/fsck_msdos %s >/dev/null";
- static char *newfsfmt ="/sbin/newfs_msdos %s >/dev/null";
struct msdosfs_args args;
char cmd[60];
char dir[PATH_MAX];
}
if (mount(MOUNT_MSDOS, dir, 0, &args) == -1) {
/* Try newfs'ing it. */
- rslt = snprintf(cmd, sizeof(cmd), newfsfmt,
- args.fspec);
- if (rslt >= sizeof(cmd)) {
- warnx("can't build newfs command");
- rslt = -1;
+ rslt = create_filesystem(dl, part);
+ if (rslt == -1)
goto rmdir;
- }
- rslt = system(cmd);
- if (rslt == -1) {
- warn("system('%s') failed", cmd);
- goto rmdir;
- }
rslt = mount(MOUNT_MSDOS, dir, 0, &args);
if (rslt == -1) {
warn("unable to mount MSDOS partition");
-/* $OpenBSD: sparc64_installboot.c,v 1.8 2019/06/28 13:32:48 deraadt Exp $ */
+/* $OpenBSD: sparc64_installboot.c,v 1.9 2021/07/20 14:51:56 kettenis Exp $ */
/*
* Copyright (c) 2012, 2013 Joel Sing <jsing@openbsd.org>
close(fd);
}
+void
+md_prepareboot(int devfd, char *dev)
+{
+}
+
void
md_installboot(int devfd, char *dev)
{
-/* $OpenBSD: stubs.c,v 1.4 2015/10/15 04:41:10 deraadt Exp $ */
+/* $OpenBSD: stubs.c,v 1.5 2021/07/20 14:51:56 kettenis Exp $ */
/*
* Copyright (c) 2014 Joel Sing <jsing@openbsd.org>
{
}
+void
+md_prepareboot(int devfd, char *dev)
+{
+}
+
void
md_installboot(int devfd, char *dev)
{