-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathzfs-parse-cmdline
More file actions
61 lines (54 loc) · 1.91 KB
/
zfs-parse-cmdline
File metadata and controls
61 lines (54 loc) · 1.91 KB
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
#!/usr/bin/awk -f
# Accepts a newline-separated list of kernel cmdline words. Suggested usage:
# > cat /proc/cmdline | xargs printf "%s\n" | zfs-parse-cmdline
#
# Interprets special forms of `root=` kernel cmdline parameter:
# - `root=zfs`: import all pools (`ZFS_ROOT_MODE=all`)
# - `root=zfs:<POOL>`: import <POOL> and use bootfs property (`ZFS_ROOT_MODE=pool`)
# - `root=zfs:<POOL>/<DATASET>`: import <POOL> and use <DATASET> (`ZFS_ROOT_MODE=dataset`)
#
# Alternatively, `zfsroot=` parameter may be used with the equivalent semantics.
# This is supported to avoid inhibiting systemd-gpt-auto-generator (which might
# be useful e.g. to auto-configure LUKS decryption).
# Returns a set of KEY=val assignments
# - ZFS_ROOT_MODE: "dataset", "pool", "all", "none"
# - all: import all pools, use the first one with a bootfs property
# - pool: import a specific pool, use bootfs to determine the dataset
# - dataset: import a specific pool, use a specific dataset
# - none: not using zfs for root
# - ZFS_ROOT_POOL: contains the root pool name (used with mode "dataset" and "pool")
# - ZFS_ROOT_DATASET: contains the root dataset name (used with mode "dataset")
$0 ~ /^root=/ {
root = substr($0, 6)
}
$0 ~ /^zfsroot=/ {
root = substr($0, 9)
}
END {
if (root == "zfs") {
# import all pools
zfs_root_mode = "all"
} else if (match(root, /^zfs[:=][^\/]+$/)) {
root = substr(root, 5)
# import a specific pool
zfs_root_mode = "pool"
zfs_root_pool = root
} else if (match(root, /^zfs[:=][^\/]+(\/[^\/]+)+$/)) {
root = substr(root, 5)
# use a particular dataset
zfs_root_mode = "dataset"
zfs_root_dataset = root
split(root, items, "/")
zfs_root_pool = items[1]
} else {
zfs_root_mode = "none"
}
printf "ZFS_ROOT_MODE=%s\n", zfs_root_mode
if (zfs_root_pool) {
printf "ZFS_ROOT_POOL=%s\n", zfs_root_pool
}
if (zfs_root_dataset) {
printf "ZFS_ROOT_DATASET=%s\n", zfs_root_dataset
}
}
# vim: ft=awk ts=8 noet: