specified. This is primarily for use by the installer and defaults to /.
-# $OpenBSD: Makefile,v 1.9 2014/01/18 02:45:38 jsing Exp $
+# $OpenBSD: Makefile,v 1.10 2014/01/18 02:47:27 jsing Exp $
PROG= installboot
-SRCS= installboot.c
+SRCS= installboot.c util.c
MAN= installboot.8
CPPFLAGS= -I${.CURDIR}
-.\" $OpenBSD: installboot.8,v 1.1 2014/01/05 16:02:40 jsing Exp $
+.\" $OpenBSD: installboot.8,v 1.2 2014/01/18 02:47:27 jsing 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 5 2014 $
+.Dd $Mdocdate: January 18 2014 $
.Dt INSTALLBOOT 8
.Os
.Sh NAME
.Sh SYNOPSIS
.Nm installboot
.Op Fl nv
+.Op Fl r Ar root
.Ar disk
.Op Ar stage1 Op Ar stage2
.Sh DESCRIPTION
Perform a dry run - do not actually write any bootstrap to the disk.
.It Fl v
Increase verbosity during operation.
+.It Fl r Ar root
+Specify the mount point of the
+.Ar root
+filesystem to operate on, defaulting to
+.Ar / .
.It Ar disk
Specify the
.Ar disk
-/* $OpenBSD: installboot.c,v 1.1 2013/12/27 13:52:40 jsing Exp $ */
+/* $OpenBSD: installboot.c,v 1.2 2014/01/18 02:47:27 jsing Exp $ */
/*
* Copyright (c) 2012, 2013 Joel Sing <jsing@openbsd.org>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
#include <unistd.h>
#include <util.h>
int stages;
int verbose;
+char *root = "/";
char *stage1;
char *stage2;
{
extern char *__progname;
- fprintf(stderr, "usage: %s [-nv] disk [stage1%s]\n",
+ fprintf(stderr, "usage: %s [-nv] [-r root] disk [stage1%s]\n",
__progname, (stages >= 2) ? " [stage2]" : "");
exit(1);
md_init();
- while ((opt = getopt(argc, argv, "nv")) != -1) {
+ while ((opt = getopt(argc, argv, "nr:v")) != -1) {
switch (opt) {
case 'n':
nowrite = 1;
break;
+ case 'r':
+ root = strdup(optarg);
+ if (root == NULL)
+ err(1, "strdup");
+ break;
case 'v':
verbose = 1;
break;
if (argc > 2)
stage2 = argv[2];
+ /* Prefix stages with root. */
+ if (verbose)
+ fprintf(stderr, "Using %s as root\n", root);
+ if (stage1 != NULL)
+ stage1 = fileprefix(root, stage1);
+ if (stage2 != NULL)
+ stage2 = fileprefix(root, stage2);
+
if ((devfd = opendev(dev, (nowrite ? O_RDONLY : O_RDWR), OPENDEV_PART,
&realdev)) < 0)
err(1, "open: %s", realdev);
-/* $OpenBSD: installboot.h,v 1.2 2013/12/28 11:26:57 jsing Exp $ */
+/* $OpenBSD: installboot.h,v 1.3 2014/01/18 02:47:27 jsing Exp $ */
/*
* Copyright (c) 2012, 2013 Joel Sing <jsing@openbsd.org>
*
extern int stages;
extern int verbose;
+extern char *root;
extern char *stage1;
extern char *stage2;
void bootstrap(int, char *, char *);
#endif
+char *fileprefix(const char *, const char *);
+
void md_init(void);
void md_loadboot(void);
void md_installboot(int, char *);
--- /dev/null
+/* $OpenBSD: util.c,v 1.1 2014/01/18 02:47:27 jsing Exp $ */
+
+/*
+ * Copyright (c) 2014 Joel Sing <jsing@openbsd.org>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <sys/param.h>
+#include <err.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "installboot.h"
+
+char *
+fileprefix(const char *base, const char *path)
+{
+ char *r, *s;
+ int n;
+
+ if ((s = malloc(PATH_MAX)) == NULL)
+ err(1, "malloc");
+ n = snprintf(s, PATH_MAX, "%s/%s", base, path);
+ if (n < 1 || n >= PATH_MAX)
+ err(1, "snprintf");
+ if ((r = realpath(s, NULL)) == NULL)
+ err(1, "realpath");
+ free(s);
+
+ return r;
+}