Bug#375491: patch suggestion
patch
Index: autopartition-lvm
===================================================================
--- autopartition-lvm (revision 40105)
+++ autopartition-lvm (working copy)
@@ -26,10 +26,50 @@
log-output -t update-dev update-dev
fi
+
# Check if the device already contains any physical volumes
realdev=$(mapdevfs "$(cat $dev/device)")
if pv_on_device "$realdev"; then
- bail_out pv_on_device
+ # If we are beeing preseeded with partman-auto-lv/disk, then try to make sure lv's
+ # and vg's are removed from the disk in question.
+ targetvg=
+ db_get partman-auto-lvm/disk
+ diskseed=$(mapdevfs $RET)
+ if [ "$diskseed" = "$realdev" ] ;then
+ #what volume groups is on any of the the disk partitions.
+ all_volume_groups=$(vg_list)
+ #we only care about vg's on the preseeded disk
+ for vg in $all_volume_groups
+ do
+ if [ "$(vg_list_pvs "$vg" | grep -c "$realdev")" != "0" ] ; then
+ targetvg=${targetvg}" $vg"
+ fi
+ done
+ for vgroup in $targetvg
+ do
+ #make sure the volume groups on the target disk don't span any other disks.
+ if [ "$(lvm_get_info vgs pv_count "$vgroup")" != "1" ] ; then
+ log-output -t partman-auto-lvs vgs
+ bail_out pv_on_device
+ fi
+ done
+
+ #it should now be safe to remove the vg's on the target disks
+
+ #remove lv's from the target vg's.
+ for vgroup in $targetvg
+ do
+ for lv in $(vg_list_lvs $vgroup)
+ do
+ #remove the logical volumes on the volume group
+ lv_delete $vgroup $lv
+ done
+ #remove the volume group
+ vg_delete $vgroup
+ done
+ else
+ bail_out pv_on_device
+ fi
fi
choose_recipe "$free_size" lvm || exit $?
Reply to: