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##*/}" 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() {
if command -v vgchange >/dev/null; then echo "[DEBUG] \$@" >&2
vgchange -a n }
else
echo "WARNING: vgchange command not found" >&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 fi
fi done
done
}
if command -v pvremove >/dev/null; then # disable any enabled volume group
pvremove --force --force --yes "$disk" || true if command -v vgchange >/dev/null; then
vgchange -a n
else else
echo "WARNING: pvremove command not found" >&2 echo "WARNING: vgchange command not found" >&2
fi fi
# stop mdadm raids if any # disable any running mdadm arrays related to $disk
if [ -r /proc/mdstat ]; then for md_name in \$(find_md_device_names "$disk_name" | sort | uniq); do
md_name="\$(awk '/$disk_name/ {print \$1}' /proc/mdstat)" echo "md_name: \$md_name"
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