]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test: generate a custom initrd for TEST-24 if $INITRD is unset
authorFrantisek Sumsal <frantisek@sumsal.cz>
Thu, 26 May 2022 11:19:11 +0000 (13:19 +0200)
committerFrantisek Sumsal <frantisek@sumsal.cz>
Thu, 26 May 2022 13:04:56 +0000 (15:04 +0200)
Co-Authored-By: Yu Watanabe <watanabe.yu+github@gmail.com>
test/TEST-24-CRYPTSETUP/test.sh
test/test-functions

index 83f4d65b1daf521fc1afb3cddbb07716a293d76c..bdf630d9120a58a936ec705a4a34f4a0cd282a60 100755 (executable)
@@ -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() {
index 06a06e706ad5a3199832f5acbb668983f6e591d7..daed481a29243f32a1a4c454452d35a913fedcbe 100644 (file)
@@ -337,6 +337,11 @@ qemu_min_version() {
 # Return 0 if qemu did run (then you must check the result state/logs for actual
 # success), or 1 if qemu is not available.
 run_qemu() {
+    # If the test provided its own initrd, use it (e.g. TEST-24)
+    if [[ -z "$INITRD" && -f "${TESTDIR:?}/initrd.img" ]]; then
+        INITRD="$TESTDIR/initrd.img"
+    fi
+
     if [ -f /etc/machine-id ]; then
         read -r MACHINE_ID </etc/machine-id
         [ -z "$INITRD" ] && [ -e "$EFI_MOUNT/$MACHINE_ID/$KERNEL_VER/initrd" ] \