Bug#462396: Multiple disks support for partman-auto-lvm
Le dimanche 03 août 2008 09:06, Jérémy Bobbio a écrit :
> > It puts in global scope some attributes about the last free partition
> > found on the disk. So what about get_last_free_partition_infos() ?
>
> A lot more meaningful, indeed. :)
Here is an updated patch for the refactoring part, which also corrects a
stupid error (I forgot the parenthesis after auto_lvm_create_envelope()).
Cheers,
Grégory
Index: partman-auto-raid/display.d/initial_auto_raid
===================================================================
--- partman-auto-raid/display.d/initial_auto_raid (révision 54731)
+++ partman-auto-raid/display.d/initial_auto_raid (copie de travail)
@@ -5,25 +5,8 @@
. /lib/partman/lib/base.sh
. /lib/partman/lib/commit.sh
+. /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
- # 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
-}
-
# See if we are supposed to run and only run once
db_get partman-auto/method
if [ "$RET" != raid ] || \
Index: partman-auto-lvm/lib/auto-lvm.sh
===================================================================
--- partman-auto-lvm/lib/auto-lvm.sh (révision 54731)
+++ partman-auto-lvm/lib/auto-lvm.sh (copie de travail)
@@ -10,6 +10,55 @@
exit 1
}
+# Creates, if needed, the envelope to hold LVM VGs.
+#
+# We need to create the envelope only if one is not defined. This is the case
+# when :
+# - the default device is not part of a PV declaration in the scheme (a PV
+# is declared when there's a method{ lvm } or method{ crypto } attribute) ;
+# *AND*
+# - the recipe contains a PV declaration *without* device.
+#
+# For this case the physical device used will be the default one.
+#
+# First arg : the scheme to add the envelope to
+# Second arg : the physical device (ie /dev/hda)
+# Third arg : the method to use (lvm or crypto)
+# Returns : the scheme with the envelope if needed
+#
+auto_lvm_create_envelope() {
+ local scheme physdev method
+ scheme="$1"
+ physdev=$2
+ method=$3
+
+ if ! echo "$scheme" | grep -E "method\{ (lvm|crypto) \}" | grep -q "device{ $physdev[[:digit:]]* }" && \
+ ! echo "$scheme" | grep -E "method\{ (lvm|crypto) \}" | grep -q -v "device{"; then
+ scheme="$scheme${NL}100 1000 1000000000 ext3 \$primary{ } method{ $method }"
+ fi
+
+ echo "$scheme"
+}
+
+# This function depends on the existence of $scheme and $devfspv_devices in scope
+#
+# It will create the partitions needed by a recipe / scheme to hold all PVs
+#
+# First arg : the path to the partman directory for the device
+#
+auto_lvm_create_partitions() {
+ local dev free_size
+ dev=$1
+
+ get_disk_infos $dev;
+ free_size=$(expr 0000000"$free_size" : '0*\(..*\)......$') # convert to megabytes
+
+ expand_scheme
+
+ create_primary_partitions
+ create_partitions
+}
+
auto_lvm_prepare() {
local dev method size free_size normalscheme target
dev=$1
Index: partman-auto/display.d/initial_auto
===================================================================
--- partman-auto/display.d/initial_auto (révision 54731)
+++ partman-auto/display.d/initial_auto (copie de travail)
@@ -9,26 +9,6 @@
. /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
Index: partman-auto/lib/auto-shared.sh
===================================================================
--- partman-auto/lib/auto-shared.sh (révision 54731)
+++ partman-auto/lib/auto-shared.sh (copie de travail)
@@ -8,6 +8,13 @@
. /lib/partman/lib/disk-label.sh
create_new_label "$dev" no || return 1
+ get_last_free_partition_infos $dev
+}
+
+get_last_free_partition_infos() {
+ local dev
+ dev=$1
+
cd $dev
free_space=''
@@ -213,3 +220,25 @@
# TODO: Add a select_auto_disks() function
# Note: This needs a debconf_multiselect equiv.
+
+# Maps a devfs name to a partman directory
+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
+}
+
Reply to: