diff --git a/mkosi/__init__.py b/mkosi/__init__.py index f9f9ad56e3..3334712d1f 100644 --- a/mkosi/__init__.py +++ b/mkosi/__init__.py @@ -72,6 +72,7 @@ MkosiException, MkosiPrinter, OutputFormat, + Partition, PartitionTable, SourceFileTransfer, die, @@ -892,7 +893,7 @@ def luks_format_root( return assert args.passphrase is not None - with complete_step("Setting up LUKS on root partition…"): + with complete_step(f"Setting up LUKS on {part.name}…"): luks_format(part.blockdev(loopdev), args.passphrase) @@ -908,7 +909,7 @@ def luks_format_home(args: CommandLineArguments, loopdev: Path, do_run_build_scr return assert args.passphrase is not None - with complete_step("Setting up LUKS on home partition…"): + with complete_step(f"Setting up LUKS on {part.name}…"): luks_format(part.blockdev(loopdev), args.passphrase) @@ -924,7 +925,7 @@ def luks_format_srv(args: CommandLineArguments, loopdev: Path, do_run_build_scri return assert args.passphrase is not None - with complete_step("Setting up LUKS on server data partition…"): + with complete_step(f"Setting up LUKS on {part.name}…"): luks_format(part.blockdev(loopdev), args.passphrase) @@ -940,7 +941,7 @@ def luks_format_var(args: CommandLineArguments, loopdev: Path, do_run_build_scri return assert args.passphrase is not None - with complete_step("Setting up LUKS on variable data partition…"): + with complete_step(f"Setting up LUKS on {part.name}…"): luks_format(part.blockdev(loopdev), args.passphrase) @@ -956,16 +957,16 @@ def luks_format_tmp(args: CommandLineArguments, loopdev: Path, do_run_build_scri return assert args.passphrase is not None - with complete_step("Setting up LUKS on temporary data partition…"): + with complete_step(f"Setting up LUKS on {part.name}…"): luks_format(part.blockdev(loopdev), args.passphrase) @contextlib.contextmanager -def luks_open(dev: Path, passphrase: Dict[str, str], partition: str) -> Generator[Path, None, None]: +def luks_open(part: Partition, loopdev: Path, passphrase: Dict[str, str]) -> Generator[Path, None, None]: name = str(uuid.uuid4()) - # FIXME: partition is only used in messages, rename it? + dev = part.blockdev(loopdev) - with complete_step(f"Setting up LUKS on {partition}…"): + with complete_step(f"Setting up LUKS on {part.name}…"): if passphrase["type"] == "stdin": passphrase_content = (passphrase["content"] + "\n").encode("utf-8") run(["cryptsetup", "open", "--type", "luks", dev, name], input=passphrase_content) @@ -978,7 +979,7 @@ def luks_open(dev: Path, passphrase: Dict[str, str], partition: str) -> Generato try: yield path finally: - with complete_step(f"Closing LUKS {partition}"): + with complete_step(f"Closing LUKS on {part.name}"): run(["cryptsetup", "close", path]) @@ -996,7 +997,7 @@ def luks_setup_root( return contextlib.nullcontext() assert args.passphrase is not None - return luks_open(part.blockdev(loopdev), args.passphrase, "root partition") + return luks_open(part, loopdev, args.passphrase) def luks_setup_home( @@ -1011,7 +1012,7 @@ def luks_setup_home( return contextlib.nullcontext() assert args.passphrase is not None - return luks_open(part.blockdev(loopdev), args.passphrase, "home partition") + return luks_open(part, loopdev, args.passphrase) def luks_setup_srv( @@ -1026,7 +1027,7 @@ def luks_setup_srv( return contextlib.nullcontext() assert args.passphrase is not None - return luks_open(part.blockdev(loopdev), args.passphrase, "server data partition") + return luks_open(part, loopdev, args.passphrase) def luks_setup_var( @@ -1041,7 +1042,7 @@ def luks_setup_var( return contextlib.nullcontext() assert args.passphrase is not None - return luks_open(part.blockdev(loopdev), args.passphrase, "variable data partition") + return luks_open(part, loopdev, args.passphrase) def luks_setup_tmp( @@ -1056,7 +1057,7 @@ def luks_setup_tmp( return contextlib.nullcontext() assert args.passphrase is not None - return luks_open(part.blockdev(loopdev), args.passphrase, "temporary data partition") + return luks_open(part, loopdev, args.passphrase) class LuksSetupOutput(NamedTuple): diff --git a/mkosi/backend.py b/mkosi/backend.py index 5f8fa4923d..87cb758d25 100644 --- a/mkosi/backend.py +++ b/mkosi/backend.py @@ -210,6 +210,7 @@ class ManifestFormat(Parseable, enum.Enum): class Partition: size: int number: int + name: str def blockdev(self, loopdev: Path) -> Path: return Path(f"{loopdev}p{self.number}") @@ -325,7 +326,7 @@ def add(self, self.partitions += [', '.join(filter(None, new))] self.last_partition_sector = self.last_partition_offset() // self.sector_size + n_sectors - part = Partition(size, len(self.partitions)) + part = Partition(size, len(self.partitions), name) if label is not None: self._labelled[label] = part