dracut/0093-crypt-crypt-run-generator.sh-do-not-add-already-exis.patch

247 lines
10 KiB
Diff
Raw Normal View History

From 3f7e5358e520b3d55c709a675d46c8080070276d Mon Sep 17 00:00:00 2001
From: Harald Hoyer <harald@redhat.com>
Date: Mon, 30 Jul 2012 18:35:30 +0200
Subject: [PATCH] crypt/crypt-run-generator.sh: do not add already existing
luks
---
modules.d/90crypt/crypt-run-generator.sh | 9 ++++++++-
test/TEST-10-RAID/create-root.sh | 3 ++-
test/TEST-10-RAID/test.sh | 9 +++++++--
test/TEST-12-RAID-DEG/create-root.sh | 3 ++-
test/TEST-12-RAID-DEG/test.sh | 6 ++++++
test/TEST-13-ENC-RAID-LVM/test.sh | 14 +++++++++++---
test/TEST-30-ISCSI/create-root.sh | 3 ---
test/TEST-40-NBD/create-root.sh | 16 +++++++++-------
test/TEST-40-NBD/test.sh | 8 ++++++--
9 files changed, 51 insertions(+), 20 deletions(-)
diff --git a/modules.d/90crypt/crypt-run-generator.sh b/modules.d/90crypt/crypt-run-generator.sh
index d70443e..cb3aedc 100755
--- a/modules.d/90crypt/crypt-run-generator.sh
+++ b/modules.d/90crypt/crypt-run-generator.sh
@@ -1,8 +1,15 @@
-#!/bin/bash
+#!/bin/sh
+
+. /lib/dracut-lib.sh
dev=$1
luks=$2
+while read l rest; do
+ strstr "${l##luks-}" "${luks##luks-}" && exit 0
+done < /etc/crypttab
+
+
echo "$luks $dev" >> /etc/crypttab
/lib/systemd/system-generators/systemd-cryptsetup-generator
systemctl daemon-reload
diff --git a/test/TEST-10-RAID/create-root.sh b/test/TEST-10-RAID/create-root.sh
index 3dd86cb..cd67819 100755
--- a/test/TEST-10-RAID/create-root.sh
+++ b/test/TEST-10-RAID/create-root.sh
@@ -34,5 +34,6 @@ lvm lvchange -a n /dev/dracut/root
udevadm settle
cryptsetup luksClose /dev/mapper/dracut_crypt_test
udevadm settle
-echo "dracut-root-block-created" >/dev/sda1
+eval $(udevadm info --query=env --name=/dev/md0|while read line; do [ "$line" != "${line#*ID_FS_UUID*}" ] && echo $line; done;)
+{ echo "dracut-root-block-created"; echo "ID_FS_UUID=$ID_FS_UUID"; } >/dev/sda1
poweroff -f
diff --git a/test/TEST-10-RAID/test.sh b/test/TEST-10-RAID/test.sh
index d2b1921..45bb62e 100755
--- a/test/TEST-10-RAID/test.sh
+++ b/test/TEST-10-RAID/test.sh
@@ -4,14 +4,14 @@ TEST_DESCRIPTION="root filesystem on an encrypted LVM PV on a RAID-5"
KVERSION=${KVERSION-$(uname -r)}
# Uncomment this to debug failures
-#DEBUGFAIL="rd.shell"
+DEBUGFAIL="rd.shell rd.udev.log-priority=debug loglevel=70 systemd.log_target=kmsg"
test_run() {
DISKIMAGE=$TESTDIR/TEST-10-RAID-root.img
$testdir/run-qemu \
-hda $DISKIMAGE \
-m 256M -nographic \
-net none -kernel /boot/vmlinuz-$KVERSION \
- -append "root=/dev/dracut/root rw quiet rd.retry=3 rd.info console=ttyS0,115200n81 selinux=0 rd.debug $DEBUGFAIL" \
+ -append "root=/dev/dracut/root rw rd.retry=10 console=ttyS0,115200n81 selinux=0 $DEBUGFAIL" \
-initrd $TESTDIR/initramfs.testing
grep -m 1 -q dracut-root-block-success $DISKIMAGE || return 1
}
@@ -70,6 +70,7 @@ test_setup() {
-append "root=/dev/dracut/root rw rootfstype=ext2 quiet console=ttyS0,115200n81 selinux=0" \
-initrd $TESTDIR/initramfs.makeroot || return 1
grep -m 1 -q dracut-root-block-created $DISKIMAGE || return 1
+ eval $(grep -a -m 1 ID_FS_UUID $DISKIMAGE)
(
export initdir=$TESTDIR/overlay
@@ -77,8 +78,12 @@ test_setup() {
dracut_install poweroff shutdown
inst_hook emergency 000 ./hard-off.sh
inst ./cryptroot-ask.sh /sbin/cryptroot-ask
+ mkdir -p $initdir/etc
+ echo "luks-$ID_FS_UUID /dev/md0 /etc/key" > $initdir/etc/crypttab
+ echo -n "test" > $initdir/etc/key
inst_simple ./99-idesymlinks.rules /etc/udev/rules.d/99-idesymlinks.rules
)
+
sudo $basedir/dracut.sh -l -i $TESTDIR/overlay / \
-o "plymouth network" \
-a "debug" \
diff --git a/test/TEST-12-RAID-DEG/create-root.sh b/test/TEST-12-RAID-DEG/create-root.sh
index 84f5ad2..d5a8c0b 100755
--- a/test/TEST-12-RAID-DEG/create-root.sh
+++ b/test/TEST-12-RAID-DEG/create-root.sh
@@ -41,4 +41,5 @@ udevadm settle
mdadm -W /dev/md0 || :
mdadm --detail --export /dev/md0 |grep MD_UUID > /tmp/mduuid
. /tmp/mduuid
-{ echo "dracut-root-block-created"; echo MD_UUID=$MD_UUID; } > /dev/sda1
+eval $(udevadm info --query=env --name=/dev/md0|while read line; do [ "$line" != "${line#*ID_FS_UUID*}" ] && echo $line; done;)
+{ echo "dracut-root-block-created"; echo MD_UUID=$MD_UUID; echo "ID_FS_UUID=$ID_FS_UUID";} > /dev/sda1
diff --git a/test/TEST-12-RAID-DEG/test.sh b/test/TEST-12-RAID-DEG/test.sh
index 96c84f8..558e3b0 100755
--- a/test/TEST-12-RAID-DEG/test.sh
+++ b/test/TEST-12-RAID-DEG/test.sh
@@ -103,8 +103,11 @@ test_setup() {
-kernel "/boot/vmlinuz-$kernel" \
-append "root=/dev/dracut/root rw rootfstype=ext2 quiet console=ttyS0,115200n81 selinux=0" \
-initrd $TESTDIR/initramfs.makeroot || return 1
+
grep -m 1 -q dracut-root-block-created $TESTDIR/root.ext2 || return 1
eval $(grep --binary-files=text -m 1 MD_UUID $TESTDIR/root.ext2)
+ eval $(grep -a -m 1 ID_FS_UUID $TESTDIR/root.ext2)
+
(
export initdir=$TESTDIR/overlay
. $basedir/dracut-functions.sh
@@ -114,7 +117,10 @@ test_setup() {
inst ./cryptroot-ask.sh /sbin/cryptroot-ask
mkdir -p $initdir/etc
echo "ARRAY /dev/md0 level=raid5 num-devices=3 UUID=$MD_UUID" > $initdir/etc/mdadm.conf
+ echo "luks-$ID_FS_UUID /dev/md0 /etc/key" > $initdir/etc/crypttab
+ echo -n test > $initdir/etc/key
)
+
sudo $basedir/dracut.sh -l -i $TESTDIR/overlay / \
-o "plymouth network" \
-a "debug" \
diff --git a/test/TEST-13-ENC-RAID-LVM/test.sh b/test/TEST-13-ENC-RAID-LVM/test.sh
index f0f7d34..dff3229 100755
--- a/test/TEST-13-ENC-RAID-LVM/test.sh
+++ b/test/TEST-13-ENC-RAID-LVM/test.sh
@@ -17,7 +17,7 @@ test_run() {
-hdb $TESTDIR/check-success.img \
-m 256M -nographic \
-net none -kernel /boot/vmlinuz-$KVERSION \
- -append "root=/dev/dracut/root rw quiet rd.retry=3 rd.info console=ttyS0,115200n81 selinux=0 rd.debug $LUKSARGS $DEBUGFAIL" \
+ -append "root=/dev/dracut/root rw quiet rd.retry=20 rd.info console=ttyS0,115200n81 selinux=0 rd.debug $LUKSARGS $DEBUGFAIL" \
-initrd $TESTDIR/initramfs.testing
grep -m 1 -q dracut-root-block-success $TESTDIR/check-success.img || return 1
echo "CLIENT TEST END: [OK]"
@@ -30,7 +30,7 @@ test_run() {
-hdb $TESTDIR/check-success.img \
-m 256M -nographic \
-net none -kernel /boot/vmlinuz-$KVERSION \
- -append "root=/dev/dracut/root rw quiet rd.retry=3 rd.info console=ttyS0,115200n81 selinux=0 rd.debug $DEBUGFAIL" \
+ -append "root=/dev/dracut/root rw quiet rd.retry=20 rd.info console=ttyS0,115200n81 selinux=0 rd.debug $DEBUGFAIL" \
-initrd $TESTDIR/initramfs.testing
grep -m 1 -q dracut-root-block-success $TESTDIR/check-success.img || return 1
echo "CLIENT TEST END: [OK]"
@@ -43,7 +43,7 @@ test_run() {
-hdb $TESTDIR/check-success.img \
-m 256M -nographic \
-net none -kernel /boot/vmlinuz-$KVERSION \
- -append "root=/dev/dracut/root rw quiet rd.retry=3 rd.info console=ttyS0,115200n81 selinux=0 rd.debug $DEBUGFAIL rd.luks.uuid=failme" \
+ -append "root=/dev/dracut/root rw quiet rd.retry=10 rd.info console=ttyS0,115200n81 selinux=0 rd.debug $DEBUGFAIL rd.luks.uuid=failme" \
-initrd $TESTDIR/initramfs.testing
grep -m 1 -q dracut-root-block-success $TESTDIR/check-success.img && return 1
echo "CLIENT TEST END: [OK]"
@@ -114,6 +114,14 @@ test_setup() {
inst_hook emergency 000 ./hard-off.sh
inst_simple ./99-idesymlinks.rules /etc/udev/rules.d/99-idesymlinks.rules
inst ./cryptroot-ask.sh /sbin/cryptroot-ask
+ mkdir -p $initdir/etc
+ i=2
+ for uuid in $cryptoUUIDS; do
+ eval $uuid
+ printf 'luks-%s /dev/sda%s /etc/key\n' $ID_FS_UUID $i
+ ((i+=1))
+ done > $initdir/etc/crypttab
+ echo -n test > $initdir/etc/key
)
sudo $basedir/dracut.sh -l -i $TESTDIR/overlay / \
-o "plymouth network" \
diff --git a/test/TEST-30-ISCSI/create-root.sh b/test/TEST-30-ISCSI/create-root.sh
index 6016320..8116a13 100755
--- a/test/TEST-30-ISCSI/create-root.sh
+++ b/test/TEST-30-ISCSI/create-root.sh
@@ -23,6 +23,3 @@ umount /sysroot && \
lvm lvchange -a n /dev/dracut/root && \
echo "dracut-root-block-created" >/dev/sdb
poweroff -f
-
-#lvm lvchange -a n /dev/dracut/root && \
-#cryptsetup luksClose /dev/mapper/dracut_crypt_test && \
diff --git a/test/TEST-40-NBD/create-root.sh b/test/TEST-40-NBD/create-root.sh
index 4bef5f1..5b902c3 100755
--- a/test/TEST-40-NBD/create-root.sh
+++ b/test/TEST-40-NBD/create-root.sh
@@ -18,11 +18,13 @@ mke2fs -j /dev/dracut/root && \
mkdir -p /sysroot && \
mount /dev/dracut/root /sysroot && \
cp -a -t /sysroot /source/* && \
-umount /sysroot && \
-sleep 1 && \
-lvm lvchange -a n /dev/dracut/root && \
-sleep 1 && \
-cryptsetup luksClose /dev/mapper/dracut_crypt_test && \
-sleep 1 && \
-echo "dracut-root-block-created" >/dev/sda
+umount /sysroot
+sleep 1
+lvm lvchange -a n /dev/dracut/root
+udevadm settle
+cryptsetup luksClose /dev/mapper/dracut_crypt_test
+udevadm settle
+sleep 1
+eval $(udevadm info --query=env --name=/dev/sdb|while read line; do [ "$line" != "${line#*ID_FS_UUID*}" ] && echo $line; done;)
+{ echo "dracut-root-block-created"; echo "ID_FS_UUID=$ID_FS_UUID"; } >/dev/sda
poweroff -f
diff --git a/test/TEST-40-NBD/test.sh b/test/TEST-40-NBD/test.sh
index 99d930f..9881630 100755
--- a/test/TEST-40-NBD/test.sh
+++ b/test/TEST-40-NBD/test.sh
@@ -52,7 +52,6 @@ client_test() {
echo "Unable to make client sda image" 1>&2
return 1
fi
-
$testdir/run-qemu \
-hda $TESTDIR/flag.img \
-m 256M -nographic \
@@ -234,6 +233,7 @@ make_encrypted_root() {
-append "root=/dev/dracut/root rw quiet console=ttyS0,115200n81 selinux=0" \
-initrd $TESTDIR/initramfs.makeroot || return 1
grep -m 1 -q dracut-root-block-created $TESTDIR/flag.img || return 1
+ grep -a -m 1 ID_FS_UUID $TESTDIR/flag.img > $TESTDIR/luks.uuid
}
make_client_root() {
@@ -328,7 +328,11 @@ test_setup() {
dracut_install poweroff shutdown
inst_hook emergency 000 ./hard-off.sh
inst_simple ./99-idesymlinks.rules /etc/udev/rules.d/99-idesymlinks.rules
- inst ./cryptroot-ask.sh /sbin/cryptroot-ask
+ inst ./cryptroot-ask.sh /sbin/cryptroot-ask
+ . $TESTDIR/luks.uuid
+ mkdir -p $initdir/etc
+ echo "luks-$ID_FS_UUID /dev/nbd0 /etc/key" > $initdir/etc/crypttab
+ echo -n test > $initdir/etc/key
)
sudo $basedir/dracut.sh -l -i $TESTDIR/overlay / \