Bug#391664: Patch to remove loops from p-a-c (bug #391664)
I've attached a patch which replaces the loops with more direct access
methods. I've done one install run with it and it seems to work as
expected.
The patch is fairly large though, not sure whether it would be a good
idea to apply it before Etch?
--
David Härdeman
Index: autopartition-crypto
===================================================================
--- autopartition-crypto (revision 42301)
+++ autopartition-crypto (working copy)
@@ -6,71 +6,79 @@
dev="$1"
method="crypto"
-auto_lvm_prepare $dev $method || exit 1
+get_partitions() {
+ local dev found
+ dev="$1"
+ found=""
-found="no"
-for dev in $DEVICES/*; do
- [ -d "$dev" ] || continue
- cd $dev
- partitions=
+ if [ ! -d "$dev" ]; then
+ return 1
+ fi
+
+ cd "$dev"
open_dialog PARTITIONS
while { read_line num id size type fs path name; [ "$id" ]; }; do
if [ "$fs" != free ]; then
- partitions="$partitions $id"
+ echo "$id"
+ found="yes"
fi
done
- close_dialog
+ close_dialog
- for id in $partitions; do
- [ -f $id/method ] || continue
- method=$(cat $id/method)
- [ $method = crypto ] || continue
+ if [ $found = yes ]; then
+ return 0
+ else
+ return 1
+ fi
+}
- echo "dm-crypt" > $id/crypto_type
- crypto_prepare_method "$dev/$id" "dm-crypt" || exit 1
- found="yes"
- break
- done
- [ $found = yes ] && break
+# Step 1 - Setup two partitions: one for /boot and one for everything else
+auto_lvm_prepare "$dev" $method || exit 1
+
+# Step 2 - Find the id of the non-boot partition and prepare it
+crypto_partition=""
+partitions=$(get_partitions "$dev") || exit 1
+cd "$dev"
+for id in $partitions; do
+ [ -f "$id/method" ] || continue
+ [ "$(cat "$id/method")" = crypto ] || continue
+
+ echo "dm-crypt" > $id/crypto_type
+ crypto_prepare_method "$dev/$id" "dm-crypt" || exit 1
+ crypto_partition="$dev/$id"
+ break
done
+[ -n "$crypto_partition" ] || exit 1
+# Step 3 - Commit the crypto changes and set it up
crypto_check_setup || exit 1
crypto_setup no || exit 1
+[ -e "$crypto_partition/crypt_active" ] || exit 1
-# This is a kludge to workaround parted's refusal to allow dm devices
-# to be used for LVM
-for dev in $DEVICES/*; do
- [ -d "$dev" ] || continue
- [ -f "$dev/crypt_realdev" ] || continue
- [ -f "$dev/device" ] || continue
+# Step 4 - workaround parted's refusal to allow dm devices for LVM
+pv_devices="$(cat "$crypto_partition/crypt_active")"
+target="$DEVICES/$(echo "$pv_devices" | tr / =)"
+[ -d "$target" ] || exit 1
+[ -f "$target/crypt_realdev" ] || exit 1
+partitions=$(get_partitions "$target") || exit 1
+cd "$target"
- # Found it
- pv_devices=$(cat $dev/device)
-
- # We should have only one partition, but lets be thorough
- cd $dev
- partitions=
- open_dialog PARTITIONS
- while { read_line num id size type fs path name; [ "$id" ]; }; do
- [ "$fs" != free ] || continue
- partitions="$partitions $id"
+# We should have only one partition, but lets be thorough
+for id in $partitions; do
+ for file in acting_filesystem filesystem format formatable use_filesystem; do
+ rm -f "$id/$file"
done
- close_dialog
-
- for id in $partitions; do
- for file in acting_filesystem filesystem format formatable use_filesystem; do
- rm -f $id/$file
- done
- echo -n "lvm" > $id/method
- done
+ echo -n "lvm" > "$id/method"
done
+# Step 5 - Setup LVM volumes on the crypto volume
auto_lvm_perform || exit 1
-# partman likes to believe that the virtual devices have a changed
-# partition table
-for dev in $DEVICES/*; do
- cd $dev
+# Step 6 - Remove changed partition table warnings
+for device in $DEVICES/*; do
+ cd "$device"
open_dialog DISK_UNCHANGED
close_dialog
done
+
+exit 0
Reply to: