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

Bug#484421: Should support preseeding of LVM-over-RAID setups



On Wed, Jun 04, 2008 at 01:48:16AM +0200, Jérémy Bobbio wrote:
> Attached is a patch adding support for preseeding LVM-over-RAID setups.

Here it is.

Cheers,
-- 
Jérémy Bobbio                        .''`. 
lunar@debian.org                    : :Ⓐ  :  # apt-get install anarchism
                                    `. `'` 
                                      `-   
commit a0bac278b265a7755323c70c2db234935357406b
Author: Jérémy Bobbio <lunar@debian.org>
Date:   Tue Jun 3 14:35:00 2008 +0000

    Move dev_to_partman() to lib/auto-shared.sh
    
    dev_to_partman() was defined and used in both partman-auto and
    partman-auto-raid.  It is now defined in lib/auto-shared.sh.

diff --git a/packages/partman/partman-auto-raid/debian/changelog b/packages/partman/partman-auto-raid/debian/changelog
index 95bc242..d57a5b4 100644
--- a/packages/partman/partman-auto-raid/debian/changelog
+++ b/packages/partman/partman-auto-raid/debian/changelog
@@ -1,3 +1,11 @@
+partman-auto-raid (12) UNRELEASED; urgency=low
+
+  [ Jérémy Bobbio ]
+  * Use dev_to_partman() from lib/auto-shared.sh.
+    Requires partman-auto (>= 79)
+
+ -- Jérémy Bobbio <lunar@debian.org>  Tue, 03 Jun 2008 11:31:01 +0000
+
 partman-auto-raid (11) unstable; urgency=low
 
   [ Updated translations ]
diff --git a/packages/partman/partman-auto-raid/debian/control b/packages/partman/partman-auto-raid/debian/control
index 90d5f46..355c605 100644
--- a/packages/partman/partman-auto-raid/debian/control
+++ b/packages/partman/partman-auto-raid/debian/control
@@ -9,5 +9,5 @@ Vcs-Svn: svn://svn.debian.org/d-i/trunk/packages/partman/partman-auto-raid
 Package: partman-auto-raid
 XC-Package-Type: udeb
 Architecture: all
-Depends: ${misc:Depends}, partman-base (>= 114), partman-basicfilesystems, partman-ext3, partman-auto (>= 58), partman-md
+Depends: ${misc:Depends}, partman-base (>= 114), partman-basicfilesystems, partman-ext3, partman-auto (>= 79), partman-md
 Description: Allow preseeded RAID installs
diff --git a/packages/partman/partman-auto-raid/display.d/initial_auto_raid b/packages/partman/partman-auto-raid/display.d/initial_auto_raid
index d545c6b..64fbbb1 100755
--- a/packages/partman/partman-auto-raid/display.d/initial_auto_raid
+++ b/packages/partman/partman-auto-raid/display.d/initial_auto_raid
@@ -5,24 +5,7 @@
 
 . /lib/partman/lib/base.sh
 . /lib/partman/lib/commit.sh
-
-dev_to_partman () {
-	local dev_name="$1"
-
-	local mapped_dev_name="$(mapdevfs $dev_name)"
-	if [ -n "$mapped_dev_name" ]; then
-		dev_name="$mapped_dev_name"
-	fi
-
-	for dev in $DEVICES/*; do
-		# mapdevfs both to allow for different ways to refer to the
-		# same device using devfs, and to allow user input in
-		# non-devfs form
-		if [ "$(mapdevfs $(cat $dev/device))" = "$dev_name" ]; then
-			echo $dev
-		fi
-	done
-}
+. /lib/partman/lib/auto-shared.sh
 
 # See if we are supposed to run and only run once
 db_get partman-auto/method
diff --git a/packages/partman/partman-auto/debian/changelog b/packages/partman/partman-auto/debian/changelog
index d6d23a4..6809d3a 100644
--- a/packages/partman/partman-auto/debian/changelog
+++ b/packages/partman/partman-auto/debian/changelog
@@ -1,3 +1,10 @@
+partman-auto (79) UNRELEASED; urgency=low
+
+  [ Jérémy Bobbio ]
+  * Move dev_to_partman() to lib/auto-shared.sh.
+
+ -- Jérémy Bobbio <lunar@debian.org>  Tue, 03 Jun 2008 14:30:14 +0000
+
 partman-auto (78) unstable; urgency=low
 
   [ Updated translations ]
diff --git a/packages/partman/partman-auto/display.d/initial_auto b/packages/partman/partman-auto/display.d/initial_auto
index ff486db..c89dc20 100755
--- a/packages/partman/partman-auto/display.d/initial_auto
+++ b/packages/partman/partman-auto/display.d/initial_auto
@@ -9,26 +9,6 @@ fi
 
 . /lib/partman/lib/auto-shared.sh
 
-dev_to_partman () {
-	local dev_name="$1"
-
-	local mapped_dev_name="$(mapdevfs $dev_name)"
-	if [ -n "$mapped_dev_name" ]; then
-		dev_name="$mapped_dev_name"
-	fi
-
-	for dev in $DEVICES/*; do
-		[ -d "$dev" ] || continue
-
-		# mapdevfs both to allow for different ways to refer to the
-		# same device using devfs, and to allow user input in
-		# non-devfs form
-		if [ "$(mapdevfs $(cat $dev/device))" = "$dev_name" ]; then
-			echo $dev
-		fi
-	done
-}
-
 # Skip if no disks detected and don't run on S/390
 if [ -z "$(get_auto_disks)" ] || \
    [ "$(udpkg --print-architecture)" = s390 ]; then
diff --git a/packages/partman/partman-auto/lib/auto-shared.sh b/packages/partman/partman-auto/lib/auto-shared.sh
index 1429183..ec42e52 100644
--- a/packages/partman/partman-auto/lib/auto-shared.sh
+++ b/packages/partman/partman-auto/lib/auto-shared.sh
@@ -213,3 +213,21 @@ select_auto_disk() {
 
 # TODO: Add a select_auto_disks() function
 # Note: This needs a debconf_multiselect equiv.
+
+dev_to_partman () {
+	local dev_name="$1"
+
+	local mapped_dev_name="$(mapdevfs $dev_name)"
+	if [ -n "$mapped_dev_name" ]; then
+		dev_name="$mapped_dev_name"
+	fi
+
+	for dev in $DEVICES/*; do
+		# mapdevfs both to allow for different ways to refer to the
+		# same device using devfs, and to allow user input in
+		# non-devfs form
+		if [ "$(mapdevfs $(cat $dev/device))" = "$dev_name" ]; then
+			echo $dev
+		fi
+	done
+}

commit 4a888c570e79e94f0fa9856c2f0bce8137f05ef8
Author: Jérémy Bobbio <lunar@debian.org>
Date:   Tue Jun 3 12:04:33 2008 +0000

    Add the ability to preseed LVM over RAID
    
    It is now possible to preseed LVM over RAID by preseeding:
      - partman-auto/method=raid
      - partman-auto-disk        (as suitable for partman-auto-raid)
      - partman-auto-raid/recipe (as suitable for partman-auto-raid)
      - partman-auto/expert_recipe with *both* partitions used by the software
        RAID devices and the logical volumes, respectively tagged with
        "$lvmignore{ }" and "$defaultignore{ } $lvmok{ }".
    
    This last part is a bit hackish, but does the trick.

diff --git a/packages/partman/partman-auto-raid/README b/packages/partman/partman-auto-raid/README
index 8b7df9e..cb94317 100644
--- a/packages/partman/partman-auto-raid/README
+++ b/packages/partman/partman-auto-raid/README
@@ -23,3 +23,64 @@ ignored).
 
 -- Simon Huggins <huggie@earth.li>
 sponsored by Black Cat Networks http://www.blackcatnetworks.co.uk/
+
+It is also possible to preseed LVM over RAID.  The following example will
+create a RAID 1 setup on two hard drives with:
+
+  /dev/md0 as /boot (ext3)
+  /dev/md1 as a LVM physical volume
+  /dev/mapper/<hostname>-root as / (ext3)
+  /dev/mapper/<hostname>-swap_1 as swap
+  /dev/mapper/<hostname>-home as /home (ext3)
+
+--- 8< ---
+d-i partman-auto/method string raid
+
+d-i partman-auto/disk string /dev/sda /dev/sdb
+
+d-i partman-auto-raid/recipe string			\
+	1 2 0 ext3 /boot				\
+		/dev/sda1#/dev/sdb1			\
+	.						\
+	1 2 0 lvm -					\
+		/dev/sda5#/dev/sdb5			\
+	.
+
+# Please note that RAID partitions are tagged as "lvmignore"
+# and LVM logical volumes as "defaultignore" and "lvmok".
+d-i partman-auto/expert_recipe string			\
+	multiraid ::					\
+		100 512 256 raid			\
+			$lvmignore{ }			\
+			$primary{ }			\
+			method{ raid }			\
+		.					\
+		900 5000 4000 raid			\
+			$lvmignore{ }			\
+			method{ raid }			\
+		.					\
+		700 5000 4000 ext3			\
+			$defaultignore{ }		\
+			$lvmok{ }			\
+			method{ format }		\
+			format{ }			\
+			use_filesystem{ }		\
+			filesystem{ ext3 }		\
+			mountpoint{ / }			\
+		.					\
+		64 512 300% linux-swap			\
+			$defaultignore{ }		\
+			$lvmok{ }			\
+			method{ swap }			\
+			format{ }			\
+		.					\
+		100 1000 1000000000 ext3		\
+			$defaultignore{ }		\
+			$lvmok{ }			\
+			method{ format }		\
+			format{ }			\
+			use_filesystem{ }		\
+			filesystem{ ext3 }		\
+			mountpoint{ /home }		\
+		.
+--- >8 ---
diff --git a/packages/partman/partman-auto-raid/debian/changelog b/packages/partman/partman-auto-raid/debian/changelog
index d57a5b4..4a5fbf5 100644
--- a/packages/partman/partman-auto-raid/debian/changelog
+++ b/packages/partman/partman-auto-raid/debian/changelog
@@ -3,6 +3,7 @@ partman-auto-raid (12) UNRELEASED; urgency=low
   [ Jérémy Bobbio ]
   * Use dev_to_partman() from lib/auto-shared.sh.
     Requires partman-auto (>= 79)
+  * Add the ability to preseed LVM over RAID.  See README for details.
 
  -- Jérémy Bobbio <lunar@debian.org>  Tue, 03 Jun 2008 11:31:01 +0000
 
diff --git a/packages/partman/partman-auto-raid/display.d/_numbers b/packages/partman/partman-auto-raid/display.d/_numbers
index 90a149b..fc7dae8 100644
--- a/packages/partman/partman-auto-raid/display.d/_numbers
+++ b/packages/partman/partman-auto-raid/display.d/_numbers
@@ -1,2 +1,3 @@
 50 initial_auto_raid
 55 initial_auto_raid_fs
+56 initial_auto_raid_lvm
diff --git a/packages/partman/partman-auto-raid/display.d/initial_auto_raid_fs b/packages/partman/partman-auto-raid/display.d/initial_auto_raid_fs
index 630078d..339b6af 100755
--- a/packages/partman/partman-auto-raid/display.d/initial_auto_raid_fs
+++ b/packages/partman/partman-auto-raid/display.d/initial_auto_raid_fs
@@ -29,16 +29,24 @@ fix_raid_fs() {
 	fi
 	cd $id
 
-	if [ "$fstype" = swap ]; then
+	case "$fstype" in
+	    swap)
 		rm -f filesystem mountpoint use_filesystem options
 		echo swap >method
-	else
+		;;
+	    lvm)
+		# Register this RAID as a PV for initial_auto_raid_lvm
+		echo lvm >method
+		echo "/dev/md$raidnum" >>/var/lib/partman/initial_auto_raid_pvs
+		;;
+	    *)
 		echo "$fstype" >filesystem
 		echo "$mountpoint" >mountpoint
 		echo format >method
 		touch use_filesystem
 		mkdir options
-	fi
+		;;
+	esac
 	touch format
 	touch formatable
 
@@ -50,6 +58,7 @@ if [ ! -f /var/lib/partman/do_initial_auto_raid_fs ]; then
 	exit 0
 fi
 rm /var/lib/partman/do_initial_auto_raid_fs
+rm -f /var/lib/partman/initial_auto_raid_pvs
 
 # Check we have the stashed value of the first RAID dev we created
 db_get partman-auto-raid/raidnum
diff --git a/packages/partman/partman-auto-raid/display.d/initial_auto_raid_lvm b/packages/partman/partman-auto-raid/display.d/initial_auto_raid_lvm
new file mode 100755
index 0000000..159bc6d
--- /dev/null
+++ b/packages/partman/partman-auto-raid/display.d/initial_auto_raid_lvm
@@ -0,0 +1,56 @@
+#!/bin/sh
+
+set -x
+
+# Apply LVM partitioning on top of a RAID preseed
+
+if ! [ -f /var/lib/partman/initial_auto_raid_pvs ] ||
+   ! [ -e /lib/partman/lib/auto-lvm.sh ]; then
+	exit 0
+fi
+
+. /lib/partman/lib/auto-lvm.sh
+
+# pv_devices is used by auto_lvm_perform()
+pv_devices="$(cat /var/lib/partman/initial_auto_raid_pvs)"
+rm -f /var/lib/partman/initial_auto_raid_pvs
+
+db_get partman-auto/expert_recipe_file
+recipe="$RET"
+
+nr_devices=0
+size=0
+for pv_device in $pv_devices; do
+	dev="$(dev_to_partman $pv_device)"
+	[ -f $dev/size ] || exit 1
+	size=$(($size + $(cat $dev/size)))
+	nr_devices=$(($nr_devices + 1))
+done
+
+if [ $nr_devices -eq 1 ]; then
+	dev="$(dev_to_partman $pv_devices)"
+	target="$(humandev $(cat $dev/device)) - $(cat $dev/model)"
+else
+	for pv_device in $pv_devices; do
+		dev="$(dev_to_partman $pv_device)"
+		target="${target:+$target }$(cat $dev/device)"
+	done
+	target="Multiple disks ($target)"
+fi
+target="$target: $(longint2human $size)"
+free_size=$(expr 0000000"$size" : '0*\(..*\)......$') # convert to megabytes
+
+choose_recipe lvm "$target" "$free_size" || return $?
+
+# Do nothing if there is no "lvmok" partitions.
+if ! echo "$scheme" | grep -q lvmok; then
+	exit 0
+fi
+
+expand_scheme
+
+# Be sure the modules are loaded
+modprobe dm-mod >/dev/null 2>&1 || true
+modprobe lvm-mod >/dev/null 2>&1 || true
+
+auto_lvm_perform

Attachment: signature.asc
Description: Digital signature


Reply to: