forked from ungleich-public/cdist
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##*/}"
|
||||
|
||||
cat << DONE
|
||||
# stop lvm's if any
|
||||
if find /sys/class/block/$disk_name*/holders/ -mindepth 1 | grep -q holders/dm; then
|
||||
if command -v vgchange >/dev/null; then
|
||||
vgchange -a n
|
||||
else
|
||||
echo "WARNING: vgchange command not found" >&2
|
||||
|
||||
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
|
||||
fi
|
||||
done
|
||||
done
|
||||
}
|
||||
|
||||
if command -v pvremove >/dev/null; then
|
||||
pvremove --force --force --yes "$disk" || true
|
||||
# disable any enabled volume group
|
||||
if command -v vgchange >/dev/null; then
|
||||
vgchange -a n
|
||||
else
|
||||
echo "WARNING: pvremove command not found" >&2
|
||||
echo "WARNING: vgchange 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
|
||||
|
|
Loading…
Reference in a new issue