make nuking mdadm/lvm actually work
Signed-off-by: Steven Armstrong <steven@icarus.ethz.ch>
This commit is contained in:
parent
49dfcf4885
commit
2bd48f1c8d
1 changed files with 35 additions and 29 deletions
|
@ -22,38 +22,44 @@ disk="/$__object_id"
|
||||||
disk_name="${disk##*/}"
|
disk_name="${disk##*/}"
|
||||||
|
|
||||||
cat << DONE
|
cat << DONE
|
||||||
# stop lvm's if any
|
|
||||||
if find /sys/class/block/$disk_name*/holders/ -mindepth 1 | grep -q holders/dm; then
|
debug() {
|
||||||
|
echo "[DEBUG] \$@" >&2
|
||||||
|
}
|
||||||
|
|
||||||
|
find_md_device_names() {
|
||||||
|
local disk_name="\$1"
|
||||||
|
for slave in \$(find /sys/devices/virtual/block/*/slaves/ -name "\${disk_name}*"); do
|
||||||
|
debug "slave: \$slave"
|
||||||
|
for holder in \$slave/holders/*; do
|
||||||
|
debug "holder: \$holder"
|
||||||
|
if [ -d "\$holder/md" ]; then
|
||||||
|
debug "mdadm found at \$holder"
|
||||||
|
holder_name="\${holder##*/}"
|
||||||
|
echo "\$holder_name"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
# disable any enabled volume group
|
||||||
if command -v vgchange >/dev/null; then
|
if command -v vgchange >/dev/null; then
|
||||||
vgchange -a n
|
vgchange -a n
|
||||||
else
|
else
|
||||||
echo "WARNING: vgchange command not found" >&2
|
echo "WARNING: vgchange command not found" >&2
|
||||||
fi
|
fi
|
||||||
fi
|
|
||||||
|
|
||||||
if command -v pvremove >/dev/null; then
|
# disable any running mdadm arrays related to $disk
|
||||||
pvremove --force --force --yes "$disk" || true
|
for md_name in \$(find_md_device_names "$disk_name" | sort | uniq); do
|
||||||
else
|
echo "md_name: \$md_name"
|
||||||
echo "WARNING: pvremove command not found" >&2
|
|
||||||
fi
|
|
||||||
|
|
||||||
# stop mdadm raids if any
|
|
||||||
if [ -r /proc/mdstat ]; then
|
|
||||||
md_name="\$(awk '/$disk_name/ {print \$1}' /proc/mdstat)"
|
|
||||||
if [ -n "\$md_name" ]; then
|
|
||||||
if command -v mdadm >/dev/null; then
|
if command -v mdadm >/dev/null; then
|
||||||
mdadm --stop "/dev/\$md_name"
|
mdadm --stop "/dev/\$md_name"
|
||||||
else
|
else
|
||||||
echo "WARNING: mdadm command not found" >&2
|
echo "WARNING: mdadm command not found" >&2
|
||||||
echo "WARNING: could not stop active mdadm raid for disk $disk" >&2
|
echo "WARNING: could not stop active mdadm raid for disk $disk" >&2
|
||||||
fi
|
fi
|
||||||
fi
|
done
|
||||||
fi
|
|
||||||
if command -v mdadm >/dev/null; then
|
|
||||||
mdadm --zero-superblock --force "$disk" || true
|
|
||||||
else
|
|
||||||
echo "WARNING: mdadm command not found" >&2
|
|
||||||
fi
|
|
||||||
# clean disks from any legacy signatures
|
# clean disks from any legacy signatures
|
||||||
if command -v wipefs >/dev/null; then
|
if command -v wipefs >/dev/null; then
|
||||||
wipefs -a "$disk" || true
|
wipefs -a "$disk" || true
|
||||||
|
|
Loading…
Reference in a new issue