Skip to content

Commit e55f9a8

Browse files
authored
Merge pull request #757 from nix-community/disk-deactiviate
disk-deactivate: only run zfs command if they are present
2 parents 37c83c0 + 8f0f75f commit e55f9a8

2 files changed

Lines changed: 7 additions & 3 deletions

File tree

disk-deactivate/disk-deactivate.jq

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# since lsblk lacks zfs support, we have to do it this way
22
def remove:
33
if .fstype == "zfs_member" then
4-
"zpool destroy -f \(.label)"
4+
"if type zpool >/dev/null; then zpool destroy -f \(.label); zpool labelclear -f \(.label); fi"
55
elif .fstype == "LVM2_member" then
66
[
77
"vg=$(pvs \(.path) --noheadings --options vg_name | grep -o '[a-zA-Z0-9-]*')",
@@ -14,8 +14,8 @@ def remove:
1414
# maybe its zfs
1515
[
1616
# the next line has some horrible escaping
17-
"zpool=$(zdb -l \(.path) | sed -nr $'s/ +name: \\'(.*)\\'/\\\\1/p')",
18-
"if [[ -n \"${zpool}\" ]]; then zpool destroy -f \"$zpool\"; fi",
17+
"zpool=$(if type zdb >/dev/null; then zdb -l \(.path) | sed -nr $'s/ +name: \\'(.*)\\'/\\\\1/p'; fi)",
18+
"if [[ -n \"${zpool}\" ]]; then zpool destroy -f \"$zpool\"; zpool labelclear -f \"$zpool\"; fi",
1919
"unset zpool"
2020
]
2121
else

lib/types/zpool.nix

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,10 @@ in
148148
in
149149
''
150150
readarray -t zfs_devices < <(cat "$disko_devices_dir"/zfs_${config.name})
151+
if [ ''${#zfs_devices[@]} -eq 0 ]; then
152+
echo "no devices found for zpool ${config.name}. Did you misspell the pool name?" >&2
153+
exit 1
154+
fi
151155
# Try importing the pool without mounting anything if it exists.
152156
# This allows us to set mounpoints.
153157
if zpool import -N -f '${config.name}' || zpool list '${config.name}'; then

0 commit comments

Comments
 (0)