summaryrefslogtreecommitdiff
path: root/test/TEST-24-CRYPTSETUP
diff options
context:
space:
mode:
authorFrantisek Sumsal <frantisek@sumsal.cz>2022-05-26 13:19:11 +0200
committerFrantisek Sumsal <frantisek@sumsal.cz>2022-05-26 15:04:56 +0200
commitb22d90e59438481b421b1eb2449e6efdfb7f2118 (patch)
treed17998c5db42406d7e61f9ccaf2ff32ce57e08aa /test/TEST-24-CRYPTSETUP
parent1fb7f8e15e19fbe61230b70203b0c35fca54f0a0 (diff)
downloadsystemd-b22d90e59438481b421b1eb2449e6efdfb7f2118.tar.gz
test: generate a custom initrd for TEST-24 if $INITRD is unset
Co-Authored-By: Yu Watanabe <watanabe.yu+github@gmail.com>
Diffstat (limited to 'test/TEST-24-CRYPTSETUP')
-rwxr-xr-xtest/TEST-24-CRYPTSETUP/test.sh24
1 files changed, 24 insertions, 0 deletions
diff --git a/test/TEST-24-CRYPTSETUP/test.sh b/test/TEST-24-CRYPTSETUP/test.sh
index 83f4d65b1d..bdf630d912 100755
--- a/test/TEST-24-CRYPTSETUP/test.sh
+++ b/test/TEST-24-CRYPTSETUP/test.sh
@@ -66,6 +66,30 @@ EOF
# Forward journal messages to the console, so we have something
# to investigate even if we fail to mount the encrypted /var
echo ForwardToConsole=yes >> "$initdir/etc/systemd/journald.conf"
+
+ # If $INITRD wasn't provided explicitly, generate a custom one with dm-crypt
+ # support
+ if [[ -z "$INITRD" ]]; then
+ INITRD="${TESTDIR:?}/initrd.img"
+ dinfo "Generating a custom initrd with dm-crypt support in '${INITRD:?}'"
+
+ if command -v dracut >/dev/null; then
+ dracut --force --verbose --add crypt "$INITRD"
+ elif command -v mkinitcpio >/dev/null; then
+ mkinitcpio --addhooks sd-encrypt --generate "$INITRD"
+ elif command -v mkinitramfs >/dev/null; then
+ # The cryptroot hook is provided by the cryptsetup-initramfs package
+ if ! dpkg-query -s cryptsetup-initramfs; then
+ derror "Missing 'cryptsetup-initramfs' package for dm-crypt support in initrd"
+ return 1
+ fi
+
+ mkinitramfs -o "$INITRD"
+ else
+ dfatal "Unrecognized initrd generator, can't continue"
+ return 1
+ fi
+ fi
}
cleanup_root_var() {