aboutsummaryrefslogtreecommitdiffstats
path: root/main/mkinitfs/0001-add-zpool-import-capability.patch
blob: af280cd83222a0693e5e71ac8a50de3f0370dfaf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
From be20737c8c6ca8b4ba94302f6b6c9725bc98565d Mon Sep 17 00:00:00 2001
From: Mark Riedesel <mark@klowner.com>
Date: Sat, 17 Sep 2016 10:46:03 -0500
Subject: [PATCH] add zpool import capability

---
 features.d/zfs.files   |  2 ++
 features.d/zfs.modules |  7 +++++++
 initramfs-init.in      |  5 +++++
 nlplug-findfs.c        | 17 +++++++++++++++--
 4 files changed, 29 insertions(+), 2 deletions(-)
 create mode 100644 features.d/zfs.files
 create mode 100644 features.d/zfs.modules

diff --git a/features.d/zfs.files b/features.d/zfs.files
new file mode 100644
index 0000000..c821e15
--- /dev/null
+++ b/features.d/zfs.files
@@ -0,0 +1,2 @@
+/usr/sbin/zfs
+/usr/sbin/zpool
diff --git a/features.d/zfs.modules b/features.d/zfs.modules
new file mode 100644
index 0000000..be5225a
--- /dev/null
+++ b/features.d/zfs.modules
@@ -0,0 +1,7 @@
+extra/avl
+extra/nvpair
+extra/spl
+extra/unicode
+extra/zcommon
+extra/zfs
+extra/zpios
diff --git a/initramfs-init.in b/initramfs-init.in
index 64b1b5b..24a25c9 100755
--- a/initramfs-init.in
+++ b/initramfs-init.in
@@ -363,6 +363,11 @@ if [ -n "$KOPT_nbd" ]; then
 	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
diff --git a/nlplug-findfs.c b/nlplug-findfs.c
index 7907389..7104d40 100644
--- 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 @@ static void start_lvm2(char *devnode)
 		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 @@ static int searchdev(struct uevent *ev, const char *searchdev, int scanbootmedia
 		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 @@ static int searchdev(struct uevent *ev, const char *searchdev, int scanbootmedia
 			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 @@ static int searchdev(struct uevent *ev, const char *searchdev, int scanbootmedia
 			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 @@ int main(int argc, char *argv[])
 	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)
-- 
2.11.0