home: hub: mkinitfs

Download patch

ref: be20737c8c6ca8b4ba94302f6b6c9725bc98565d
parent: 92801060dccf632c827867eb361396646e04ae99
author: Mark Riedesel <mark@klowner.com>
date: Sat Sep 17 05:46:03 CDT 2016

add zpool import capability

--- /dev/null
+++ b/features.d/zfs.files
@@ -1,0 +1,2 @@
+/usr/sbin/zfs
+/usr/sbin/zpool
--- /dev/null
+++ b/features.d/zfs.modules
@@ -1,0 +1,7 @@
+extra/avl
+extra/nvpair
+extra/spl
+extra/unicode
+extra/zcommon
+extra/zfs
+extra/zpios
--- a/initramfs-init.in
+++ b/initramfs-init.in
@@ -363,6 +363,11 @@
 	setup_nbd || echo "Failed to setup nbd device."
 fi
 
+if [ "$KOPT_rootfstype" = "zfs" ]; then
+	# zpool reports /dev/zfs missing if it can't read /etc/mtab
+	ln -s /proc/mounts /etc/mtab
+fi
+
 # check if root=... was set
 if [ -n "$KOPT_root" ]; then
 	if [ "$SINGLEMODE" = "yes" ]; then
--- a/nlplug-findfs.c
+++ b/nlplug-findfs.c
@@ -51,11 +51,12 @@
 
 #define LVM_PATH	"/sbin/lvm"
 #define MDADM_PATH	"/sbin/mdadm"
+#define ZPOOL_PATH	"/usr/sbin/zpool"
 
 static int dodebug;
 static char *default_envp[2];
 char *argv0;
-static int use_mdadm, use_lvm;
+static int use_mdadm, use_lvm, use_zpool;
 
 #if defined(DEBUG)
 #include <stdarg.h>
@@ -496,6 +497,15 @@
 		spawn_command(&spawnmgr, lvm2_argv, 0);
 }
 
+static void start_zpool(char *uuid) {
+	char *zpool_argv[] = {
+		ZPOOL_PATH, "import", uuid,
+		NULL
+	};
+	if (use_zpool && uuid)
+		spawn_command(&spawnmgr, zpool_argv, 0);
+}
+
 static int read_pass(char *pass, size_t pass_size)
 {
 	struct termios old_flags, new_flags;
@@ -913,6 +923,7 @@
 		blkid_get_cache(&conf->blkid_cache, NULL);
 
 	type = blkid_get_tag_value(conf->blkid_cache, "TYPE", ev->devnode);
+	uuid = blkid_get_tag_value(conf->blkid_cache, "UUID", ev->devnode);
 
 	if (searchdev != NULL) {
 		if (strncmp("LABEL=", searchdev, 6) == 0) {
@@ -920,7 +931,6 @@
 			if (label && strcmp(label, searchdev+6) == 0)
 				rc = FOUND_DEVICE;
 		} else if (strncmp("UUID=", searchdev, 5) == 0) {
-			uuid = blkid_get_tag_value(conf->blkid_cache, "UUID", ev->devnode);
 			if (uuid && strcmp(uuid, searchdev+5) == 0)
 				rc = FOUND_DEVICE;
 		}
@@ -934,6 +944,8 @@
 			start_mdadm(ev->devnode);
 		} else if (strcmp("LVM2_member", type) == 0) {
 			start_lvm2(ev->devnode);
+		} else if (strcmp("zfs_member", type) == 0) {
+			start_zpool(uuid);
 		} else if (scanbootmedia) {
 			rc = scandev(conf, ev->devnode, type);
 		}
@@ -1133,6 +1145,7 @@
 	conf.uevent_timeout = DEFAULT_EVENT_TIMEOUT;
 	use_lvm = access(LVM_PATH, X_OK) == 0;
 	use_mdadm = access(MDADM_PATH, X_OK) == 0;
+	use_zpool = access(ZPOOL_PATH, X_OK) == 0;
 
 	argv0 = strrchr(argv[0], '/');
 	if (argv0++ == NULL)