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

[RFC] Some love for partman-md v4



On Thu, Jun 05, 2008 at 07:09:36PM +0200, Frans Pop wrote:
> On Wednesday 04 June 2008, Jérémy Bobbio wrote:
> >    Two questions popped up in my mind after this change:
> >      * Would it be desirable to activate Volume Groups by default, like
> >        it would now be done for RAID devices?
> 
> Since it basically only requires loading dm-mod and running 'vgscan -a y' 
> I don't see any real objection.

Well… We might want to think of the impacts on preseeding, guided
partitioning, modification of a partition table on which one of the
partition is used for LVM…

Given the current schedule, I wonder if we have enough time and power to
do proper testing.

> >      * How are we going to cope with really twisted setups if we ever
> >        fix #451535?
> 
> Maybe just detect them and bail out. There's only so much you can support 
> out of the box. Also, once you've detected for example an encrypted 
> device, there's not that much use in checking what's inside it.

Use case: I am reinstalling a system which has a separate encrypted,
/home partition.

I think it would be better if I could tell the installer how to use this
existing partition, even if its encrypted.  But well, the question was
just meant to bring awareness of a possible issue in the future.

> > Comments welcome, as usual. :)

All of the issues you have pointed have been addressed.  Thanks! :)

> > +++ b/packages/partman/partman-md/lib/md-remove.sh
> 
> In general I wonder if this should not be delayed to post-Lenny.
> It may be better for now to just warn that RAID devices have been
> detected and that those should be removed manually before restarting 
> guided partitioning.

This would make entirely automatic installations through preseeding fail
if partman-md is loaded and previously existing software RAID devices
are detected.  Sounds not really desirable to me… :(

> One thing I don't like is that we don't first present an overview of _all_ 
> affected RAID devices.
> Also, the template you are reusing is less suitable as it is designed as a 
> confirmation of a specifically selected action, not for something that 
> could be the unintended consequense of guided partitioning.

I felt while writing the code that reusing mdcfg's template might not be
the best thing.  I always feel clumsy when I need to write new ones, so
I took the easy path.

This new version of the patch introduces a new template, inspired by
partman-lvm/device_remove_lvm which displays all affected software RAID
devices and partitions at ounce.

The logic of device_remove_md() has been reworked accordingly.

> > @@ -0,0 +1,60 @@
> > +# Wipes any traces of an active MD on the given device
> > +device_remove_md() {
> > +	local dev md_dev md_devs used_parts type device_dir
> > +	dev="$1"
> > +	cd $dev
> > +
> > +	realdev=$(mapdevfs "$(cat $dev/device)")
> > +	md_devs=$(sed -n -e \
> > +		"s,^\(md[0-9]*\) : active raid[0-9]*
> > .*${realdev#/dev/}[^[]*\[[0-9]\].*,/dev/\1,p" \
> > +		/proc/mdstat) 
> 
> I'd think that _all_ RAID devices should be removed, including inactive 
> ones. If only to clear the superblocks.

To make it clear, are you saying "all RAID devices which use at least a
partition on the target device"?

Otherwise, I think we need to keep RAID devices only using other
devices.  Use case: system on first disk, without RAID; /srv on other
disks, using RAID 5.

> > +	# Make sure that parted has no stale info on the MD
> > +	restart=""
> > +	for md_dev in $md_devs; do
> > +		device_dir="$DEVICES/$(echo $md_dev | sed -e 's,/,=,g')"
> > +		if ! [ -d "$device_dir" ]; then
> > +			continue
> > +		fi
> > +		rm -rf $device_dir
> > +		restart=1
> > +	done
> 
> Is this necessary? Isn't this done automatically during the restart?
> If we rely on that, a comment that explains it is probably useful.

Indeed.  We can just restart if at least one device has been removed.

Fourth version of the patch is attached.  I hope it'll be the last. :)

Cheers,
-- 
Jérémy Bobbio                        .''`. 
lunar@debian.org                    : :Ⓐ  :  # apt-get install anarchism
                                    `. `'` 
                                      `-   
commit 2b92a1fd4b598c1936fa90cbf237ecc53f11316d
Author: Jérémy Bobbio <lunar@debian.org>
Date:   Thu May 29 16:12:16 2008 +0000

    Clean up the initialization of MD devices
    
    The initialization of MD devices in partman previously diverged from what
    others partman components are doing, resulting in quite few bugs and
    really bad interactions with crypto setup.
    
     * Scanning for existing MD devices
    
       During partman initialization, the init.d/md-devices script now load
       kernel modules and scan for MD devices the first time it is started.
    
       This script has been moved to be called before init.d/parted to have
       existing RAID partitions listed on the first partitioner run.
    
       Thus, existing MD devices will now be activated at the begining of
       the partionner.  (Closes: #391474)
    
       The same code snippet in mdcfg is now only called if /proc/mdstat did
       exist before.  The attempt to load the ancient "md" module has also
       been removed.
    
       init.d/md has been moved before init.d/lvm in order to correctly detect
       the presence of LVM Physical Volumes on RAID partitions.
    
     * Keep configurations of RAID partitions accross partman restarts
    
       MD devices were previously skipped in init.d/parted, resulting in the
       loss of the previous configuration.  We now only skip deactivated RAID
       devices, in a similar way than sataraid and multipath devices are
       skipped.
    
       Most of the job of init.d/md and init.d/md-devices have been cleaned up
       and merged into init.d/md to cope with the previous change. The
       initialization scheme is now closer to what is done for LVM.
    
       (Closes: #391479, #391483, #393728, #398668, #475479)
    
     * Stop loading raid* kernel modules manually
    
       Manually loading raid* kernel modules is not needed with the current
       Linux kernels.  They will be automatically loaded when detecting or
       creating a new MD device.

diff --git a/packages/mdcfg/debian/changelog b/packages/mdcfg/debian/changelog
index 2543ba2..2ef6ab4 100644
--- a/packages/mdcfg/debian/changelog
+++ b/packages/mdcfg/debian/changelog
@@ -1,3 +1,12 @@
+mdcfg (1.27) UNRELEASED; urgency=low
+
+  [ Jérémy Bobbio ]
+  * mdcfg now load kernel modules and scan MD devices only if /proc/mdstat did
+    not exist before.
+  * Remove the attempt to load the ancient module "md".
+
+ -- Jérémy Bobbio <lunar@debian.org>  Thu, 29 May 2008 17:46:31 +0000
+
 mdcfg (1.26) unstable; urgency=low
 
   [ Updated translations ]
diff --git a/packages/mdcfg/mdcfg.sh b/packages/mdcfg/mdcfg.sh
index 37a1f09..46c3ab3 100755
--- a/packages/mdcfg/mdcfg.sh
+++ b/packages/mdcfg/mdcfg.sh
@@ -502,31 +502,30 @@ md_mainmenu() {
 
 ### Main of script ###
 
-# Try to load the necesarry modules.
-# Supported schemes: RAID 0, RAID 1, RAID 5
-depmod -a >/dev/null 2>&1
-modprobe md >/dev/null 2>&1 || modprobe md-mod >/dev/null 2>&1
-modprobe raid0 >/dev/null 2>&1
-modprobe raid1 >/dev/null 2>&1
-# kernels >=2.6.18 have raid456
-modprobe raid456 >/dev/null 2>&1 || modprobe raid5 >/dev/null 2>&1
-
-# Try to detect MD devices, and start them
-# mdadm will fail if /dev/md does not already exist
-mkdir -p /dev/md
-
-log-output -t mdcfg --pass-stdout \
-	mdadm --examine --scan --config=partitions >/tmp/mdadm.conf
-
-log-output -t mdcfg \
-	mdadm --assemble --scan --run --config=/tmp/mdadm.conf --auto=yes
-
-# Make sure that we have md-support
-if [ ! -e /proc/mdstat ]; then
-	db_set mdcfg/nomd false
-	db_input high mdcfg/nomd
-	db_go
-	exit 0
+# Load the modules and scan for MD devices if needed
+if ! [ -e /proc/mdstat ]; then
+	# Try to load the necesarry modules.
+	depmod -a >/dev/null 2>&1
+	modprobe md-mod >/dev/null 2>&1
+
+	# Make sure that we have md-support
+	if [ ! -e /proc/mdstat ]; then
+		db_set mdcfg/nomd false
+		db_input high mdcfg/nomd
+		db_go
+		exit 0
+	fi
+
+	# Try to detect MD devices, and start them
+	# mdadm will fail if /dev/md does not already exist
+	mkdir -p /dev/md
+
+	log-output -t mdcfg --pass-stdout \
+		mdadm --examine --scan --config=partitions >/tmp/mdadm.conf
+
+	log-output -t mdcfg \
+		mdadm --assemble --scan --run \
+		--config=/tmp/mdadm.conf --auto=yes
 fi
 
 # Force mdadm to be installed on the target system
diff --git a/packages/partman/partman-base/debian/changelog b/packages/partman/partman-base/debian/changelog
index e81d2bf..fcd0b65 100644
--- a/packages/partman/partman-base/debian/changelog
+++ b/packages/partman/partman-base/debian/changelog
@@ -1,10 +1,15 @@
 partman-base (121) UNRELEASED; urgency=low
 
+  [ Frans Pop ]
   * Add divider below "Use as" in ithe partition options dialog. If the
     partition is used for encryption, "Encryption method" will also be
     above the divider. As changing these option changes defaults and what
     other options are available, this provides a useful visual separation.
 
+  [ Jérémy Bobbio ]
+  * Instead of skipping all MD devices during partman initialization, we
+    now only skip the ones that are deactivated.  (Closes: #475479)
+
  -- Frans Pop <fjp@debian.org>  Fri, 30 May 2008 17:56:28 +0200
 
 partman-base (120) unstable; urgency=high
diff --git a/packages/partman/partman-base/init.d/parted b/packages/partman/partman-base/init.d/parted
index 346170a..c544562 100755
--- a/packages/partman/partman-base/init.d/parted
+++ b/packages/partman/partman-base/init.d/parted
@@ -6,6 +6,15 @@ set -e
 
 ORIG_IFS="$IFS"
 
+is_inactive_md() {
+	local number
+	number=$(echo "$1" | sed -n -e 's,/dev/md/\?,,p')
+	if [ "$number" ] && ! grep -q "^md$number : active" /proc/mdstat; then
+		return 0
+	fi
+	return 1
+}
+
 part_of_sataraid () {
 	local raiddev
 	for raiddev in $(dmraid -r -c); do
@@ -52,8 +61,7 @@ if [ ! -f /var/run/parted_server.pid ]; then
 
 	IFS="$NL"
 	for partdev in $(parted_devices |
-		grep -v '^/dev/md' |
-		sed 's,^/dev/\(ide\|scsi\|[hs]d\),!/dev/\1,' |
+		sed 's,^/dev/\(ide\|scsi\|[hs]d\|md/\?[0-9]\+\),!/dev/\1,' |
 		sort |
 		sed 's,^!,,' ); do
 
@@ -65,6 +73,13 @@ if [ ! -f /var/run/parted_server.pid ]; then
 		size=$2
 		model=$3
 
+		# Skip MD devices which are not active
+		if [ -e /proc/mdstat ]; then
+			if is_inactive_md $device; then
+				continue
+			fi
+		fi
+
 		# Skip devices that are part of a dmraid device
 		if type dmraid >/dev/null 2>&1; then
 			if part_of_sataraid $device; then
diff --git a/packages/partman/partman-md/debian/changelog b/packages/partman/partman-md/debian/changelog
index e93fc37..3dfc95c 100644
--- a/packages/partman/partman-md/debian/changelog
+++ b/packages/partman/partman-md/debian/changelog
@@ -1,3 +1,15 @@
+partman-md (42) UNRELEASED; urgency=low
+
+  [ Jérémy Bobbio ]
+  * Clean up the initialization of MD devices.  Together with the changes
+    introduced in partman-base (>= 121), setup of RAID devices won't be lost
+    across partman restarts anymore.
+    (Closes: #391479, #391483, #393728, #398668)
+  * Load the necessary modules and scan RAID arrays during partman
+    initialization.  (Closes: #391474)
+
+ -- Jérémy Bobbio <lunar@debian.org>  Thu, 29 May 2008 16:02:39 +0000
+
 partman-md (41) unstable; urgency=low
 
   [ Frans Pop ]
diff --git a/packages/partman/partman-md/debian/control b/packages/partman/partman-md/debian/control
index 08c74b5..f4f96d9 100644
--- a/packages/partman/partman-md/debian/control
+++ b/packages/partman/partman-md/debian/control
@@ -9,5 +9,5 @@ Vcs-Svn: svn://svn.debian.org/d-i/trunk/packages/partman/partman-md
 Package: partman-md
 XC-Package-Type: udeb
 Architecture: all
-Depends: ${misc:Depends}, mdadm-udeb, mdcfg-utils, partman-base (>= 114)
+Depends: ${misc:Depends}, mdadm-udeb, mdcfg-utils, partman-base (>= 121)
 Description: Add to partman support for MD
diff --git a/packages/partman/partman-md/init.d/_numbers b/packages/partman/partman-md/init.d/_numbers
index 75ae141..139cb78 100644
--- a/packages/partman/partman-md/init.d/_numbers
+++ b/packages/partman/partman-md/init.d/_numbers
@@ -1,2 +1,2 @@
-31 md-devices
-51 md
+25 md-devices
+49 md
diff --git a/packages/partman/partman-md/init.d/md b/packages/partman/partman-md/init.d/md
index e5024f2..fb8ddac 100755
--- a/packages/partman/partman-md/init.d/md
+++ b/packages/partman/partman-md/init.d/md
@@ -2,16 +2,25 @@
 
 . /lib/partman/lib/base.sh
 
-# Load modules
-#depmod -a 1>/dev/null 2>&1
-#modprobe md 1>/dev/null 2>&1 || modprobe md-mod 1>/dev/null 2>&1
-#
-## Load supported personalities
-#modprobe raid1 1>/dev/null 2>&1
-#
-## Detect and start MD devices
-#/sbin/mdadm --examine --scan --config=partitions >/tmp/mdadm.conf
-#/sbin/mdadm --assemble --scan --run --config=/tmp/mdadm.conf --auto=yes
+# Check if we have RAID
+if [ ! -f /proc/mdstat ]; then
+	exit 0
+fi
+
+# Obtain the size of an MD device
+get_size () {
+	while [ -z "$(echo "$line" | grep "^md$NUMBER :")" ]; do
+		read line
+		[ $? -eq 1 ] && break  # EOF
+	done
+	read line
+	size=$(echo "$line" | sed -e 's/ blocks.*//')
+	# If the sed failed, the line didn't contain the size; just
+	# return 0 in that case.
+	if [ "$size" = "$line" ]; then
+		size=0
+	fi
+}
 
 # Mark all RAID partitions as being MD
 for dev in $DEVICES/*; do
@@ -28,6 +37,7 @@ for dev in $DEVICES/*; do
 	done
 	close_dialog
 
+	# Check if device/partitions are used for software RAID
 	for id in $partitions; do
 		md=no
 		open_dialog GET_FLAGS $id
@@ -43,38 +53,57 @@ for dev in $DEVICES/*; do
 		fi
 	done
 
-	# Next, check if the device is a part of an MD setup
-#	if [ -f device ]; then
-#		DEVICE=`sed -e "s/\/dev\///" device`
-#		grep -q "${DEVICE}" /proc/mdstat
-#		if [ $? -eq 0 ]; then
-#			open_dialog NEW_LABEL loop
-#			close_dialog
-#		fi
-#	fi
-done
+	# Check if the device is a software RAID device
+	if [ -f device ]; then
+		NUMBER=$(sed -e 's,/dev/md/\?,,' device)
+		if ! grep -q "^md$NUMBER :" /proc/mdstat; then
+			continue
+		fi
 
-# Create the raid devices
-# NOTE: /dev/md/X does not necessarily exist; /dev/mdX can exist alone
-#       (see #470374 for reference)
-#for i in $(grep md /proc/mdstat | \
-#	    sed -e 's/^\(md.*\) : active \([[:alnum:]]*\).*/\1/'); do
-#	NUMBER=$(echo $i | sed -e "s/^md//")
-#	DEVICE="$DEVICES/=dev=md$NUMBER"
-#	mkdir -p $DEVICE
-#	cd $DEVICE
-#	echo "/dev/md$NUMBER" > $DEVICE/device
-#	echo Unknown > $DEVICE/model
-#	echo "0" > $DEVICE/size
-#	open_dialog OPEN "/dev/md$NUMBER"
-#	read_line response
-#	close_dialog
-#	if [ "$response" = failed ]; then
-#		rm -rf $DEVICE
-#	fi
-#
-#	open_dialog NEW_LABEL loop
-#	close_dialog
-#done
+		# Set an appropriate value for device model
+		db_metaget partman-md/text/device description
+		echo "${RET}" > model
+
+		# fix size
+		get_size < /proc/mdstat
+		sector_size=$(grep " sectors" /proc/mdstat | sed -e 's/[^0-9]\+//g')
+		if [ -z "$sector_size" ]; then
+			sector_size=1024
+		fi
+		size=$(($size * $sector_size))
+		echo "$size" > size
+
+		# create a label
+		open_dialog NEW_LABEL loop
+		close_dialog
+		# find the free space
+		open_dialog PARTITIONS
+		free_space=''
+		while { read_line num id size type fs path name; [ "$id" ]; }; do
+			if [ "$fs" = free ]; then
+				free_space=$id
+				free_size=$size
+			fi
+		done
+		close_dialog
+		# create partition in the free space
+		if [ "$free_space" ]; then
+			open_dialog NEW_PARTITION primary ext2 $free_space full $free_size
+			read_line num id size type fs path name
+			close_dialog
+			if [ "$id" ]; then
+				open_dialog GET_FILE_SYSTEM $id
+				read_line filesystem
+				close_dialog
+				if [ "$filesystem" != none ]; then
+					open_dialog CHANGE_FILE_SYSTEM $id $filesystem
+					close_dialog
+				fi
+			fi
+		fi
+		open_dialog DISK_UNCHANGED
+		close_dialog
+	fi
+done
 
 exit 0
diff --git a/packages/partman/partman-md/init.d/md-devices b/packages/partman/partman-md/init.d/md-devices
index df9c785..3d2ff2e 100755
--- a/packages/partman/partman-md/init.d/md-devices
+++ b/packages/partman/partman-md/init.d/md-devices
@@ -2,94 +2,23 @@
 
 . /lib/partman/lib/base.sh
 
-# Check if we have RAID
-if [ ! -f /proc/mdstat ]; then
+# Load modules and scan arrays if it was not done before
+if [ -e /proc/mdstat ]; then
 	exit 0
 fi
 
-# Obtain the size of an MD device
-get_size () {
-	while [ -z "$(echo "$line" | grep "^md$NUMBER :")" ]; do
-		read line
-		[ $? -eq 1 ] && break  # EOF
-	done
-	read line
-	size=$(echo "$line" | sed -e 's/ blocks.*//')
-	# If the sed failed, the line didn't contain the size; just
-	# return 0 in that case.
-	if [ "$size" = "$line" ]; then
-		size=0
-	fi
-}
+# Try to load the necessary modules.
+depmod -a >/dev/null 2>&1
+modprobe md-mod >/dev/null 2>&1
 
-# Create the raid devices
-for i in $(grep ^md /proc/mdstat | grep -v inactive | \
-	   sed -e 's/^\(md.*\) : active \([[:alnum:]]*\).*/\1/'); do
-	NUMBER="${i#md}"
-	if [ -e "/dev/md/${NUMBER}" ]; then
-		DEVICE="$DEVICES/=dev=md=${NUMBER}"
-		DEVNODE="/dev/md/${NUMBER}"
-	else
-		DEVICE="$DEVICES/=dev=md${NUMBER}"
-		DEVNODE="/dev/md${NUMBER}"
-	fi
-	mkdir -p ${DEVICE}
-	cd ${DEVICE}
-	echo "$DEVNODE" > ${DEVICE}/device
+# Try to detect MD devices, and start them
+# mdadm will fail if /dev/md does not already exist
+mkdir -p /dev/md
 
-	db_metaget partman-md/text/device description
-	echo "${RET}" > ${DEVICE}/model
+log-output -t md-devices --pass-stdout \
+	mdadm --examine --scan --config=partitions >/tmp/mdadm.conf
 
-	get_size < /proc/mdstat
-	sector_size=$(grep " sectors" /proc/mdstat | sed -e 's/[^0-9]\+//g')
-	if [ -z "$sector_size" ]; then
-		sector_size=1024
-	fi
-	size=$(($size * $sector_size))
-	echo "$size" > ${DEVICE}/size
-
-	open_dialog OPENED "$DEVNODE"
-	read_line response
-	close_dialog
-	if [ "$response" = no ]; then
-		open_dialog OPEN "$DEVNODE"
-		read_line response
-		close_dialog
-		if [ "$response" = failed ]; then
-			rm -rf ${DEVICE}
-		fi
-	fi
-
-	open_dialog NEW_LABEL loop
-	close_dialog
-
-	open_dialog PARTITIONS
-	free_space=''
-	while { read_line num id size type fs path name; [ "$id" ]; }; do
-		if [ "$fs" = free ]; then
-			free_space=$id
-			free_size=$size
-		fi
-	done
-	close_dialog
-
-	if [ "$free_space" ]; then
-		open_dialog NEW_PARTITION primary ext2 $free_space full $free_size
-		read_line num id size type fs path name
-		close_dialog
-		if [ "$id" ]; then
-			open_dialog GET_FILE_SYSTEM $id
-			read_line filesystem
-			close_dialog
-			if [ "$filesystem" != none ]; then
-				open_dialog CHANGE_FILE_SYSTEM $id $filesystem
-				close_dialog
-			fi
-		fi
-	fi
-
-	open_dialog DISK_UNCHANGED
-	close_dialog
-done
+log-output -t md-devices \
+	mdadm --assemble --scan --run --config=/tmp/mdadm.conf --auto=yes
 
 exit 0

commit 07d21fa9e6e380c9147102bb269740c574f0fd87
Author: Jérémy Bobbio <lunar@debian.org>
Date:   Tue Jun 3 15:51:06 2008 +0000

    Remove MD devices when creating a new disk label
    
    In create_new_label(), we now remove MD devices like it was already done
    for LVM.  As partman-md now scans for existing MD devices during
    partman initialization, it is required in order to make automatic
    partitioning working on disks which was previously used for an MD device.
    
    A small library, lib/md-remove.sh has been added to partman-md in order to
    do so.

diff --git a/packages/partman/partman-md/debian/changelog b/packages/partman/partman-md/debian/changelog
index 3dfc95c..6c2e652 100644
--- a/packages/partman/partman-md/debian/changelog
+++ b/packages/partman/partman-md/debian/changelog
@@ -7,6 +7,9 @@ partman-md (42) UNRELEASED; urgency=low
     (Closes: #391479, #391483, #393728, #398668)
   * Load the necessary modules and scan RAID arrays during partman
     initialization.  (Closes: #391474)
+  * Add device_remove_md() in lib/md-remove.sh: it is necessary to allow
+    proper removal of MD devices when we create a new label on a disk
+    (for example, during automatic partitioning).
 
  -- Jérémy Bobbio <lunar@debian.org>  Thu, 29 May 2008 16:02:39 +0000
 
diff --git a/packages/partman/partman-md/debian/partman-md.templates b/packages/partman/partman-md/debian/partman-md.templates
index 8430d5b..f65e3ea 100644
--- a/packages/partman/partman-md/debian/partman-md.templates
+++ b/packages/partman/partman-md/debian/partman-md.templates
@@ -52,3 +52,18 @@ Template: partman/method_short/raid
 Type: text
 # :sl3:
 _Description: raid
+
+Template: partman-md/device_remove_md
+Type: boolean
+Default: false
+# :sl3:
+_Description: Remove existing software RAID partitions?
+ The selected device contains partitions used for software RAID devices.
+ The following devices and partitions are about to be removed:
+ .
+ Software RAID devices about to be removed: ${REMOVED_DEVICES}
+ .
+ Partitions used by these RAID devices: ${REMOVED_PARTITIONS}
+ .
+ Note that this will also permanently erase any data currently on the
+ software RAID devices.
diff --git a/packages/partman/partman-md/debian/rules b/packages/partman/partman-md/debian/rules
index 60ead47..7f682c4 100755
--- a/packages/partman/partman-md/debian/rules
+++ b/packages/partman/partman-md/debian/rules
@@ -24,7 +24,7 @@ install: build
 	debian/install-rc choose_partition
 	debian/install-rc init.d
 	debian/install-rc update.d
-	#dh_install parted_names lib/partman
+	dh_install lib lib/partman
 
 binary-indep: build install
 	dh_testdir
diff --git a/packages/partman/partman-md/lib/md-remove.sh b/packages/partman/partman-md/lib/md-remove.sh
new file mode 100644
index 0000000..d4fa425
--- /dev/null
+++ b/packages/partman/partman-md/lib/md-remove.sh
@@ -0,0 +1,61 @@
+# Wipes any traces of an active MD on the given device
+device_remove_md() {
+	local dev md_dev md_devs part used_parts type removed_devices
+	dev="$1"
+	cd $dev
+
+	realdev=$(mapdevfs "$(cat $dev/device)")
+	md_devs=$(sed -n -e \
+		"s,^\(md[0-9]*\) : \(active raid[0-9]*\|inactive\) .*${realdev#/dev/}[^[]*\[[0-9]\].*,/dev/\1,p" \
+		/proc/mdstat)
+
+	if [ -z "$md_devs" ]; then
+		return 0
+	fi
+
+	used_parts=""
+	removed_devices=""
+	for md_dev in $md_devs; do
+		used_parts="${used_parts:+$used_parts }$(
+			mdadm -Q --detail $md_dev |
+			grep -E "^[[:space:]]*[0-9].*(active|spare)" |
+			sed -e 's/.* //')"
+		type="$(mdadm -Q --detail $md_dev |
+			sed -n -e 's/^.*Raid Level : \(.*\)/\1/p')"
+		removed_devices="${removed_devices:+$removed_devices, }${md_dev#/dev/} ($type)"
+	done
+
+	db_subst partman-md/device_remove_md REMOVED_DEVICES "$removed_devices"
+	db_subst partman-md/device_remove_md REMOVED_PARTITIONS \
+		"$(echo $used_parts | sed -e 's/ /, /')"
+	db_input critical partman-md/device_remove_md
+	db_go || return 1
+	db_get partman-md/device_remove_md
+
+	if [ "$RET" = true ]; then
+		db_reset partman-md/device_remove_md
+	else
+		db_reset partman-md/device_remove_md
+		return 1
+	fi
+	if [ -e /lib/partman/lib/lvm-remove.sh ]; then
+		. /lib/partman/lib/lvm-remove.sh
+		for md_dev in $md_devs; do
+			device_remove_lvm "$md_dev" || return 1
+		done
+	fi
+	for md_dev in $md_devs; do
+		logger -t md-remove "Removing $md_dev ($used_parts)"
+		log-output -t md-remove mdadm --stop $md_dev || return 1
+	done
+	for part in $used_parts; do
+		log-output -t md-remove mdadm \
+			--zero-superblock --force $part || return 1
+	done
+
+	# Restart partman to get rid of stale informations
+	stop_parted_server
+	restart_partman || return 1
+
+	return 0
+}
diff --git a/packages/partman/partman-partitioning/debian/changelog b/packages/partman/partman-partitioning/debian/changelog
index 7da50d7..de60ead 100644
--- a/packages/partman/partman-partitioning/debian/changelog
+++ b/packages/partman/partman-partitioning/debian/changelog
@@ -14,6 +14,11 @@ partman-partitioning (60) UNRELEASED; urgency=low
   * Disable "resize" and "delete" for partitions on "loop" partition tables.
     This will prevent unusable behaviour on RAID, crypto and LVM partitions.
     (Closes: #318228, #417973)
+  * In create_new_label(), we now remove MD devices similar to what's already
+    done for LVM.  As partman-md now scans for existing MD devices during
+    partman initialization, it is required in order to make guided
+    partitioning work on a disk that was previously used for an MD device.
+    Requires partman-md (>= 42).
 
  -- Colin Watson <cjwatson@debian.org>  Tue, 27 May 2008 10:17:15 +0100
 
diff --git a/packages/partman/partman-partitioning/lib/disk-label.sh b/packages/partman/partman-partitioning/lib/disk-label.sh
index d2696be..e9b3a94 100644
--- a/packages/partman/partman-partitioning/lib/disk-label.sh
+++ b/packages/partman/partman-partitioning/lib/disk-label.sh
@@ -170,6 +170,10 @@ create_new_label() {
 		. /lib/partman/lib/lvm-remove.sh
 		device_remove_lvm "$dev" || return 1
 	fi
+	if [ -e /lib/partman/lib/md-remove.sh ]; then
+		. /lib/partman/lib/md-remove.sh
+		device_remove_md "$dev" || return 1
+	fi
 
 	cd $dev
 

Attachment: signature.asc
Description: Digital signature


Reply to: