make nuking mdadm/lvm actually work

Signed-off-by: Steven Armstrong <steven@icarus.ethz.ch>
This commit is contained in:
Steven Armstrong 2014-01-20 13:45:23 +01:00
parent 49dfcf4885
commit 2bd48f1c8d

View file

@ -22,38 +22,44 @@ disk="/$__object_id"
disk_name="${disk##*/}"
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
vgchange -a n
else
echo "WARNING: vgchange command not found" >&2
fi
fi
if command -v pvremove >/dev/null; then
pvremove --force --force --yes "$disk" || true
else
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
# disable any running mdadm arrays related to $disk
for md_name in \$(find_md_device_names "$disk_name" | sort | uniq); do
echo "md_name: \$md_name"
if command -v mdadm >/dev/null; then
mdadm --stop "/dev/\$md_name"
else
echo "WARNING: mdadm command not found" >&2
echo "WARNING: could not stop active mdadm raid for disk $disk" >&2
fi
fi
fi
if command -v mdadm >/dev/null; then
mdadm --zero-superblock --force "$disk" || true
else
echo "WARNING: mdadm command not found" >&2
fi
done
# clean disks from any legacy signatures
if command -v wipefs >/dev/null; then
wipefs -a "$disk" || true