0738a69
From 5bfebf0f04c8e88a0447d5f75c7ec13951fa610d Mon Sep 17 00:00:00 2001
0738a69
From: Harald Hoyer <harald@redhat.com>
0738a69
Date: Tue, 7 Apr 2020 22:26:25 +0200
0738a69
Subject: [PATCH] 90crypt/module-setup.sh: try to catch kernel config changes
0738a69
0738a69
If a crypto kernel module changes from compiled in to module, the
0738a69
encrypted disk might fail to open, because the kernel module was
0738a69
not included in the initramfs.
0738a69
0738a69
This patch tries heuristically to catch such modules.
0738a69
0738a69
Fixes https://github.com/dracutdevs/dracut/issues/706
0738a69
---
0738a69
 modules.d/90crypt/module-setup.sh | 25 +++++++++++++++++++++++++
0738a69
 1 file changed, 25 insertions(+)
0738a69
0738a69
diff --git a/modules.d/90crypt/module-setup.sh b/modules.d/90crypt/module-setup.sh
0738a69
index a9dda734..3bce2411 100755
0738a69
--- a/modules.d/90crypt/module-setup.sh
0738a69
+++ b/modules.d/90crypt/module-setup.sh
0738a69
@@ -26,6 +26,31 @@ depends() {
0738a69
 installkernel() {
0738a69
     hostonly="" instmods drbg
0738a69
     instmods dm_crypt
0738a69
+
0738a69
+    # in case some of the crypto modules moved from compiled in
0738a69
+    # to module based, try to install those modules
0738a69
+    # best guess
0738a69
+    [[ $hostonly ]] || [[ $mount_needs ]] && {
0738a69
+        # dmsetup returns s.th. like
0738a69
+        # cryptvol: 0 2064384 crypt aes-xts-plain64 :64:logon:cryptsetup:....
0738a69
+        dmsetup table | while read name _ _ is_crypt cipher _; do
0738a69
+            [[ $is_crypt != "crypt" ]] && continue
0738a69
+            # get the device name
0738a69
+            name=/dev/$(dmsetup info -c --noheadings -o blkdevname ${name%:})
0738a69
+            # check if the device exists as a key in our host_fs_types
0738a69
+            if [[ ${host_fs_types[$name]+_} ]]; then
0738a69
+                # split the cipher aes-xts-plain64 in pieces
0738a69
+                _OLD_IFS=$IFS
0738a69
+                IFS='-:'
0738a69
+                set -- $cipher
0738a69
+                IFS=$_OLD_IFS
0738a69
+                # try to load the cipher part with "crypto-" prepended
0738a69
+                # in non-hostonly mode
0738a69
+                hostonly= instmods $(for k in "$@"; do echo "crypto-$k";done)
0738a69
+            fi
0738a69
+        done
0738a69
+    }
0738a69
+    return 0
0738a69
 }
0738a69
 
0738a69
 # called by dracut
0738a69