Add more robust removal of LVM on target

Should prevent strange failures to recreate LVM if a previous one
existed and no block zeroing is done.
This commit is contained in:
Joshua Boniface 2021-12-13 13:39:48 -05:00
parent 100bd8c403
commit 78af7006ed
1 changed files with 26 additions and 2 deletions

View File

@ -552,8 +552,32 @@ else
echo "found small disk (${blockdev_size_gbytes} < 100GB), using small partition sizes."
fi
echo -n "Disabing existing volume groups... "
vgchange -an >&2 || true
echo -n "Unmounting potential partitions on target device... "
for mount in $( mount | grep "${target_disk}" | awk '{ print $3 }' | sort -r ); do
umount -f ${mount} >&2
done
echo "done."
echo -n "Unmounting potential LVM logical volumes on target device... "
for vg in $( pvscan | grep "${target_disk}" | awk '{ print $4 }' ); do
for mount in $( mount | grep "/${vg}" | awk '{ print $3 }' | sort -r ); do
umount -f ${mount} >&2
done
done
echo "done."
echo -n "Disabing potential LVM volume groups on target device... "
for vg in $( pvscan | grep "${target_disk}" | awk '{ print $4 }' ); do
vgchange -an ${vg} >&2 || true
sleep 1
vgchange -an ${vg} >&2
done
echo "done."
echo -n "Removing existing LVM physical volumes... "
for pv in $( pvcscan | grep "${target_disk}" | awk '{ print $2 }' ); do
yes | pvremove ${pv}
done
echo "done."
blockcheck() {