Skip to content

Commit

Permalink
Have systemd-repart generate fstab and crypttab if requested
Browse files Browse the repository at this point in the history
If systemd-repart is new enough, let's specify --generate-fstab= and
--generate-crypttab= so that these files are automatically generated
and included in the disk image if the corresponding new settings are
used in any partition definition files.

We also make sure systemd-repart always uses the same seed by
generating the random seed ourselves instead of leaving it up to
systemd-repart.

See systemd/systemd#30636.
  • Loading branch information
DaanDeMeyer authored and keszybz committed Feb 18, 2024
1 parent 3cce9bf commit 7afa0e0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
13 changes: 10 additions & 3 deletions mkosi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2641,6 +2641,7 @@ def make_image(
msg: str,
skip: Sequence[str] = [],
split: bool = False,
tabs: bool = False,
root: Optional[Path] = None,
definitions: Sequence[Path] = [],
) -> list[Partition]:
Expand All @@ -2652,7 +2653,7 @@ def make_image(
"--json=pretty",
"--no-pager",
f"--offline={yes_no(context.config.repart_offline)}",
"--seed", str(context.config.seed) if context.config.seed else "random",
"--seed", str(context.config.seed),
context.staging / context.config.output_with_format,
]
options: list[PathString] = ["--bind", context.staging, context.staging]
Expand All @@ -2679,6 +2680,11 @@ def make_image(
cmdline += ["--split=yes"]
if context.config.sector_size:
cmdline += ["--sector-size", str(context.config.sector_size)]
if tabs and systemd_tool_version(context.config, "systemd-repart") >= 256:
cmdline += [
"--generate-fstab=/etc/fstab",
"--generate-crypttab=/etc/crypttab",
]

for d in definitions:
cmdline += ["--definitions", d]
Expand Down Expand Up @@ -2711,6 +2717,7 @@ def make_disk(
msg: str,
skip: Sequence[str] = [],
split: bool = False,
tabs: bool = False,
) -> list[Partition]:
if context.config.output_format != OutputFormat.disk:
return []
Expand Down Expand Up @@ -2777,7 +2784,7 @@ def make_disk(

definitions = [defaults]

return make_image(context, msg=msg, skip=skip, split=split, root=context.root, definitions=definitions)
return make_image(context, msg=msg, skip=skip, split=split, tabs=tabs, root=context.root, definitions=definitions)


def make_esp(context: Context, uki: Path) -> list[Partition]:
Expand Down Expand Up @@ -3041,7 +3048,7 @@ def build_image(context: Context) -> None:
run_finalize_scripts(context)

normalize_mtime(context.root, context.config.source_date_epoch)
partitions = make_disk(context, skip=("esp", "xbootldr"), msg="Generating disk image")
partitions = make_disk(context, skip=("esp", "xbootldr"), tabs=True, msg="Generating disk image")
install_uki(context, partitions)
prepare_grub_efi(context)
prepare_grub_bios(context, partitions)
Expand Down
9 changes: 5 additions & 4 deletions mkosi/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -1209,7 +1209,7 @@ class Config:
repart_offline: bool
overlay: bool
use_subvolumes: ConfigFeature
seed: Optional[uuid.UUID]
seed: uuid.UUID

packages: list[str]
build_packages: list[str]
Expand Down Expand Up @@ -1850,6 +1850,7 @@ def parse_ini(path: Path, only_sections: Collection[str] = ()) -> Iterator[tuple
metavar="UUID",
section="Output",
parse=config_parse_seed,
default=uuid.uuid4(),
help="Set the seed for systemd-repart",
),

Expand Down Expand Up @@ -3639,8 +3640,8 @@ def optional_path_transformer(path: Optional[str], fieldtype: type[Optional[Path
def path_list_transformer(pathlist: list[str], fieldtype: type[list[Path]]) -> list[Path]:
return [Path(p) for p in pathlist]

def optional_uuid_transformer(optuuid: Optional[str], fieldtype: type[Optional[uuid.UUID]]) -> Optional[uuid.UUID]:
return uuid.UUID(optuuid) if optuuid is not None else None
def uuid_transformer(uuidstr: str, fieldtype: type[uuid.UUID]) -> uuid.UUID:
return uuid.UUID(uuidstr)

def root_password_transformer(
rootpw: Optional[list[Union[str, bool]]], fieldtype: type[Optional[tuple[str, bool]]]
Expand Down Expand Up @@ -3704,7 +3705,7 @@ def generic_version_transformer(
Path: path_transformer,
Optional[Path]: optional_path_transformer,
list[Path]: path_list_transformer,
Optional[uuid.UUID]: optional_uuid_transformer,
uuid.UUID: uuid_transformer,
Optional[tuple[str, bool]]: root_password_transformer,
list[ConfigTree]: config_tree_transformer,
tuple[str, ...]: str_tuple_transformer,
Expand Down

0 comments on commit 7afa0e0

Please sign in to comment.