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 2023-09-01 15:41:57 -04:00
parent b023596ef6
commit ccf3c63606
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() {