mirror of
https://github.com/nix-community/disko
synced 2024-11-10 06:14:14 +00:00
Merge pull request #757 from nix-community/disk-deactiviate
disk-deactivate: only run zfs command if they are present
This commit is contained in:
commit
e55f9a8678
2 changed files with 7 additions and 3 deletions
|
@ -1,7 +1,7 @@
|
||||||
# since lsblk lacks zfs support, we have to do it this way
|
# since lsblk lacks zfs support, we have to do it this way
|
||||||
def remove:
|
def remove:
|
||||||
if .fstype == "zfs_member" then
|
if .fstype == "zfs_member" then
|
||||||
"zpool destroy -f \(.label)"
|
"if type zpool >/dev/null; then zpool destroy -f \(.label); zpool labelclear -f \(.label); fi"
|
||||||
elif .fstype == "LVM2_member" then
|
elif .fstype == "LVM2_member" then
|
||||||
[
|
[
|
||||||
"vg=$(pvs \(.path) --noheadings --options vg_name | grep -o '[a-zA-Z0-9-]*')",
|
"vg=$(pvs \(.path) --noheadings --options vg_name | grep -o '[a-zA-Z0-9-]*')",
|
||||||
|
@ -14,8 +14,8 @@ def remove:
|
||||||
# maybe its zfs
|
# maybe its zfs
|
||||||
[
|
[
|
||||||
# the next line has some horrible escaping
|
# the next line has some horrible escaping
|
||||||
"zpool=$(zdb -l \(.path) | sed -nr $'s/ +name: \\'(.*)\\'/\\\\1/p')",
|
"zpool=$(if type zdb >/dev/null; then zdb -l \(.path) | sed -nr $'s/ +name: \\'(.*)\\'/\\\\1/p'; fi)",
|
||||||
"if [[ -n \"${zpool}\" ]]; then zpool destroy -f \"$zpool\"; fi",
|
"if [[ -n \"${zpool}\" ]]; then zpool destroy -f \"$zpool\"; zpool labelclear -f \"$zpool\"; fi",
|
||||||
"unset zpool"
|
"unset zpool"
|
||||||
]
|
]
|
||||||
else
|
else
|
||||||
|
|
|
@ -148,6 +148,10 @@ in
|
||||||
in
|
in
|
||||||
''
|
''
|
||||||
readarray -t zfs_devices < <(cat "$disko_devices_dir"/zfs_${config.name})
|
readarray -t zfs_devices < <(cat "$disko_devices_dir"/zfs_${config.name})
|
||||||
|
if [ ''${#zfs_devices[@]} -eq 0 ]; then
|
||||||
|
echo "no devices found for zpool ${config.name}. Did you misspell the pool name?" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
# Try importing the pool without mounting anything if it exists.
|
# Try importing the pool without mounting anything if it exists.
|
||||||
# This allows us to set mounpoints.
|
# This allows us to set mounpoints.
|
||||||
if zpool import -N -f '${config.name}' || zpool list '${config.name}'; then
|
if zpool import -N -f '${config.name}' || zpool list '${config.name}'; then
|
||||||
|
|
Loading…
Reference in a new issue