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

Bug#375491: yet another lvm_removal_on_demand patch suggestion



David Härdeman wrote:
I've attached a patch which details what this could look like...

And here's an updated patch. This one is tested and works with one exception: if you do an automated partman-auto-lvm install two times in a row, the parted server seems to become confused and the manual partitioning screen is messed up thereafter.

This still needs fixing but I'm unsure of what goes wrong and why (note that the idea of a "disappearing" disk, which is what a VG/LV removal looks like to parted, has not been tried yet in partman-* as far as I know).

I've CC:ed Colin Watson who perhaps knows a bit more than me about parted_server?

Latest patch attached...(the section under the "Make sure that parted has no stale LVM info" is what needs to be checked)...

Regards,
David
Index: partman-auto/debian/partman-auto.templates
===================================================================
--- partman-auto/debian/partman-auto.templates	(revision 40312)
+++ partman-auto/debian/partman-auto.templates	(working copy)
@@ -27,6 +27,21 @@
  use the guided partitioning tool, you will still have a chance later to
  review and customise the results.
 
+Template: partman-auto/purge_lvm_from_device
+Type: boolean
+Default: false
+_Description: Remove all Logical Volume Configuration?
+ Before creating any partitions, we need to remove all existing
+ Logical Volumes and Volume Groups from the disk.
+ .
+ WARNING     This will erase all data on LVM Partitions
+
+Template: partman-auto/pv_on_device
+Type: error
+_Description: Existing physical volume on the selected device
+ The device you selected already contains one or more physical volumes. It
+ is not possible to automatically partition this device using LVM.
+
 Template: partman-auto/disk
 Type: string
 # Only used for preseeding.
Index: partman-auto/auto-shared.sh
===================================================================
--- partman-auto/auto-shared.sh	(revision 40234)
+++ partman-auto/auto-shared.sh	(working copy)
@@ -1,9 +1,92 @@
 ## this file contains a bunch of shared code between partman-auto
 ## and partman-auto-lvm.
 
+# Wipes any traces of LVM from a disk
+# Normally you wouldn't want to use this function, 
+# but wipe_disk() which will also call this function.
+lvm_wipe_disk() {
+	local dev realdev vg pvs pv lv tmpdev
+	dev="$1"
+
+	if [ ! -e /lib/partman/lvm_tools.sh ]; then
+		return 0
+	fi
+
+	. /lib/partman/lvm_tools.sh
+
+	# Check if the device already contains any physical volumes
+	realdev=$(mapdevfs "$(cat $dev/device)")
+	if ! pv_on_device "$realdev"; then
+		return 0
+	fi
+
+	# Ask for permission to erase LVM volumes 
+	db_input critical partman-auto/purge_lvm_from_device
+	db_go || return 1
+	db_get partman-auto/purge_lvm_from_device
+	if [ "$RET" != "true" ]; then
+		db_input critical partman-auto/pv_on_device || true
+		db_go || true
+		return 1
+	fi
+
+	# Check all VG's
+	for vg in $(vg_list); do
+		pvs=$(vg_list_pvs $vg)
+		
+		# Only deal with VG's on the selected disk
+		if ! $(echo "$pvs" | grep -q "$realdev"); then
+			continue
+		fi
+
+		# Make sure the VG don't span any other disks
+		if $(echo -n "$pvs" | grep -q -v "$realdev"); then
+			log-output -t partman-auto-lvs vgs
+			db_input critical partman-auto/pv_on_device || true
+			db_go || true
+			return 1
+		fi
+
+		# Remove LV's from the VG
+		for lv in $(vg_list_lvs $vg); do
+			lv_delete $vg $lv
+		done
+
+		# Remove the VG and its PV's 
+		vg_delete $vg
+		for pv in $pvs; do
+			pv_delete $pv
+		done
+	done
+
+	# Make sure that parted has no stale LVM info
+	for tmpdev in $DEVICES/*; do
+		realdev=$(cat $tmpdev/device)
+
+		if ! $(echo "$realdev" | grep -q "/dev/mapper/"); then
+			continue
+		fi
+
+		if [ -b "$realdev" ]; then
+			continue
+		fi
+
+		cd $tmpdev
+		open_dialog CLOSE "$realdev"
+		read_line response
+		close_dialog
+
+		rm -rf $tmpdev
+	done
+
+	return 0
+}
+
 wipe_disk() {
 	cd $dev
 
+	lvm_wipe_disk "$dev" || return 1
+
 	open_dialog LABEL_TYPES
 	types=$(read_list)
 	close_dialog
Index: partman-auto-lvm/debian/partman-auto-lvm.templates
===================================================================
--- partman-auto-lvm/debian/partman-auto-lvm.templates	(revision 40234)
+++ partman-auto-lvm/debian/partman-auto-lvm.templates	(working copy)
@@ -37,12 +37,6 @@
  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/pv_on_device
-Type: error
-_Description: Existing physical volume on the selected device
- The device you selected already contains one or more physical volumes. It
- is not possible to automatically partition this device using LVM.
-
 Template: partman-auto-lvm/vg_exists
 Type: error
 _Description: Volume group name already in use
Index: partman-auto-lvm/autopartition-lvm
===================================================================
--- partman-auto-lvm/autopartition-lvm	(revision 40234)
+++ partman-auto-lvm/autopartition-lvm	(working copy)
@@ -26,12 +26,6 @@
 	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
-fi
-
 choose_recipe "$free_size" lvm || exit $?
 
 wipe_disk || exit $?

Reply to: