Handle at least absolute paths and the automatic
`/etc/cryptsetup-keys.d/<volume>.key` search path.
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")