first stop lvm, then mdadm

Signed-off-by: Steven Armstrong <steven@icarus.ethz.ch>
This commit is contained in:
Steven Armstrong 2013-12-17 14:56:20 +01:00
parent f9cac131c9
commit be8df7999b

View file

@ -22,6 +22,15 @@ 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
if command -v vgchange >/dev/null; then
vgchange -a n
else
echo "WARNING: vgchange command not found" >&2
fi
fi
# stop mdadm raids if any # stop mdadm raids if any
if [ -r /proc/mdstat ]; then if [ -r /proc/mdstat ]; then
md_name="\$(awk "/$disk_name/ {print \$1}" /proc/mdstat)" md_name="\$(awk "/$disk_name/ {print \$1}" /proc/mdstat)"
@ -35,28 +44,19 @@ if [ -r /proc/mdstat ]; then
fi fi
fi fi
# stop lvm's if any if command -v pvremove >/dev/null; then
if find /sys/class/block/$disk_name*/holders/ -mindepth 1 | grep -q holders/dm; then pvremove --force --force --yes "$disk" || true
if command -v vgchange >/dev/null; then else
vgchange -a n echo "WARNING: pvremove command not found" >&2
else
echo "WARNING: vgchange command not found" >&2
fi
fi
# clean disks from any legacy signatures
if command -v wipefs >/dev/null; then
wipefs -a "$disk" || true
fi fi
if command -v mdadm >/dev/null; then if command -v mdadm >/dev/null; then
mdadm --zero-superblock --force "$disk" || true mdadm --zero-superblock --force "$disk" || true
else else
echo "WARNING: mdadm command not found" >&2 echo "WARNING: mdadm command not found" >&2
fi fi
if command -v pvremove >/dev/null; then # clean disks from any legacy signatures
pvremove --force --force --yes "$disk" || true if command -v wipefs >/dev/null; then
else wipefs -a "$disk" || true
echo "WARNING: pvremove command not found" >&2
fi fi
# erase partition table # erase partition table