summaryrefslogtreecommitdiff
path: root/sys/kern/subr_disk.c
diff options
context:
space:
mode:
authorJoel Sing <jsing@cvs.openbsd.org>2011-04-26 17:20:21 +0000
committerJoel Sing <jsing@cvs.openbsd.org>2011-04-26 17:20:21 +0000
commit2d7740a3b1a96dd7d345686c8e2c1e1277f4f5d1 (patch)
treec8cb10d00c33cbd86d5a30c1662ddeaac302500e /sys/kern/subr_disk.c
parentd5480d483307adc3cd1653bebab9d8fbc25e0547 (diff)
Allow the root device to be identified via its disklabel UID.
ok deraadt@ marco@ krw@
Diffstat (limited to 'sys/kern/subr_disk.c')
-rw-r--r--sys/kern/subr_disk.c28
1 files changed, 27 insertions, 1 deletions
diff --git a/sys/kern/subr_disk.c b/sys/kern/subr_disk.c
index a488b3c7842..cecfd12f48a 100644
--- a/sys/kern/subr_disk.c
+++ b/sys/kern/subr_disk.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: subr_disk.c,v 1.119 2011/04/16 03:21:16 krw Exp $ */
+/* $OpenBSD: subr_disk.c,v 1.120 2011/04/26 17:20:20 jsing Exp $ */
/* $NetBSD: subr_disk.c,v 1.17 1996/03/16 23:17:08 christos Exp $ */
/*
@@ -78,6 +78,8 @@ int disk_change; /* set if a disk has been attached/detached
* is reset by hw_sysctl()
*/
+u_char rootduid[8]; /* DUID of root disk. */
+
/* softraid callback, do not use! */
void (*softraid_disk_attach)(struct disk *, int);
@@ -1082,6 +1084,8 @@ setroot(struct device *bootdv, int part, int exitflags)
struct device *rootdv, *dv;
dev_t nrootdev, nswapdev = NODEV, temp = NODEV;
struct ifnet *ifp = NULL;
+ struct disk *dk = NULL;
+ u_char duid[8];
char buf[128];
#if defined(NFSCLIENT)
extern char *nfsbootdevname;
@@ -1187,6 +1191,22 @@ gotswap:
* `swap generic'
*/
rootdv = bootdv;
+ bzero(&duid, sizeof(duid));
+ if (bcmp(rootduid, &duid, sizeof(rootduid)) != 0) {
+ TAILQ_FOREACH(dk, &disklist, dk_link)
+ if (dk->dk_label && bcmp(dk->dk_label->d_uid,
+ &rootduid, sizeof(rootduid)) == 0)
+ break;
+ if (dk == NULL)
+ panic("root device (%02hhx%02hhx%02hhx%02hhx"
+ "%02hhx%02hhx%02hhx%02hhx) not found",
+ rootduid[0], rootduid[1], rootduid[2],
+ rootduid[3], rootduid[4], rootduid[5],
+ rootduid[6], rootduid[7]);
+ bcopy(rootduid, duid, sizeof(duid));
+ rootdv = dk->dk_device;
+ }
+
majdev = findblkmajor(rootdv);
if (majdev >= 0) {
/*
@@ -1244,6 +1264,12 @@ gotswap:
printf("root on %s%c", rootdv->dv_xname, 'a' + part);
+ if (dk != NULL && bcmp(rootduid, &duid, sizeof(rootduid)) == 0)
+ printf(" (%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx.%c)",
+ rootduid[0], rootduid[1], rootduid[2], rootduid[3],
+ rootduid[4], rootduid[5], rootduid[6], rootduid[7],
+ 'a' + part);
+
/*
* Make the swap partition on the root drive the primary swap.
*/