]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
mkosi-initrd: honor x-initrd.attach options in crypttab
authorAntonio Alvarez Feijoo <antonio.feijoo@suse.com>
Tue, 22 Oct 2024 14:49:39 +0000 (16:49 +0200)
committerJörg Behrmann <behrmann@physik.fu-berlin.de>
Mon, 28 Oct 2024 08:26:21 +0000 (09:26 +0100)
mkosi/initrd.py

index 80c21ed38e93fc0e218866033f2a09875e6cfa93..a06511c96251dbfc6553087f9af36bf3aa06f365 100644 (file)
@@ -169,6 +169,23 @@ def main() -> None:
 
         cmdline += ["--sandbox-tree", sandbox_tree]
 
+        # Generate crypttab with all the x-initrd.attach entries
+        if Path("/etc/crypttab").exists():
+            crypttab = [
+                line
+                for line in Path("/etc/crypttab").read_text().splitlines()
+                if (
+                    len(entry := line.split()) >= 4
+                    and not entry[0].startswith("#")
+                    and "x-initrd.attach" in entry[3]
+                )
+            ]
+            if crypttab:
+                with (Path(staging_dir) / "crypttab").open("w") as f:
+                    f.write("# Automatically generated by mkosi-initrd\n")
+                    f.write("\n".join(crypttab))
+                cmdline += ["--extra-tree", f"{staging_dir}/crypttab:/etc/crypttab"]
+
         # Prefer dnf as dnf5 has not yet officially replaced it and there's a much bigger chance that there
         # will be a populated dnf cache directory.
         run(