import argparse
import contextlib
import dataclasses
+import logging
import os
import platform
import shutil
# 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"]
+ try:
+ 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"]
+ except PermissionError:
+ logging.warning("Permission denied to access /etc/crypttab, the initrd may be unbootable")
return cmdline