]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
mkosi-initrd: add key files for crypttab entries
authorAntonio Alvarez Feijoo <antonio.feijoo@suse.com>
Thu, 27 Mar 2025 09:52:33 +0000 (10:52 +0100)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Thu, 27 Mar 2025 10:50:20 +0000 (11:50 +0100)
Handle at least absolute paths and the automatic
`/etc/cryptsetup-keys.d/<volume>.key` search path.

mkosi/initrd.py

index a03882777a453da8fc353878e52b40e42ad66325..f0f2aaad1f0c93677c2993f63b01ca2ad5e5fe77 100644 (file)
@@ -165,6 +165,16 @@ def process_crypttab(staging_dir: Path) -> list[str]:
                     f.write("# Automatically generated by mkosi-initrd\n")
                     f.write("\n".join(crypttab))
                 cmdline += ["--extra-tree", f"{staging_dir / 'crypttab'}:/etc/crypttab"]
+
+                # Add key files
+                for line in crypttab:
+                    entry = line.split()
+                    if (
+                        entry[2] in ["-", "none"]
+                        and Path(keyfile := f"/etc/cryptsetup-keys.d/{entry[0]}.key").exists()
+                    ) or Path(keyfile := entry[2]).exists():
+                        cmdline += ["--extra-tree", f"{keyfile}:{keyfile}"]
+
         except PermissionError:
             logging.warning("Permission denied to access /etc/crypttab, the initrd may be unbootable")