[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#375491: yet another lvm_removal_on_demand patch suggestion



here is attached my 3rd attempth for lvm removal on installations.
It's basicaly Frans Pops suggestions. with a new template

if lvm is detected on the disk,
ask user if it's ok to delete them.
if yes ; delete
if no ; same error as before.
If this is acceptable ill see about adding something to the error description.

this works interactivly, and can preseed it as normal i expect.
It still errors out if the VG's on the selected disk span multiple disks.
I also tried to reuse some of the variables an not create a dozen when it was not needed.

hope someone can review and judge this

Ronny

Index: debian/partman-auto-lvm.templates
===================================================================
--- debian/partman-auto-lvm.templates	(revision 40192)
+++ debian/partman-auto-lvm.templates	(working copy)
@@ -37,6 +37,15 @@
  You can choose to ignore this warning, but that may result in a failure to
  reboot the system after the installation is completed.
 
+Template: partman-auto-lvm/purge_lvm_from_device
+Type: boolean
+Default: false
+_Description: Remove all Logical Volume Configuration?
+ Before creating any Logical Volume Groups, we need to remove all exsisting
+ Logical Volumes and Volume Groups from the disk we are partitioning. 
+ .
+ WARNING     This will erase all data on LVM Partitions
+
 Template: partman-auto-lvm/pv_on_device
 Type: error
 _Description: Existing physical volume on the selected device
Index: autopartition-lvm
===================================================================
--- autopartition-lvm	(revision 40192)
+++ autopartition-lvm	(working copy)
@@ -26,10 +26,52 @@
 	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
+	# Ask for mermission to erase LVM volumes 
+	db_set partman-auto-lvm/purge_lvm_from_device "false"
+        db_input critical partman-auto-lvm/purge_lvm_from_device
+        db_go
+        db_get partman-auto-lvm/purge_lvm_from_device
+	if [ "$RET" = "true" ] ;then 
+	
+		targetvg=
+		#what volume groups is on any of the the disk partitions.
+		all_volume_groups=$(vg_list)
+		#we only care about vg's on the selected disk
+		for vg in $all_volume_groups
+		do	
+			if [ "$(vg_list_pvs "$vg" | grep -c "$realdev")" != "0" ] ; then
+				targetvg=${targetvg}" $vg"
+			fi
+		done
+		for vg 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 "$vg")" != "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 vg in $targetvg
+		do
+			for lv in $(vg_list_lvs $vg)
+			do
+				#remove the logical volumes on the volume group
+	   			lv_delete $vg $lv
+			done
+			#remove the volume group
+			vg_delete $vg
+		done
+	else
+		bail_out pv_on_device
+	fi
 fi
 
 choose_recipe "$free_size" lvm || exit $?

Reply to: