with complete_step(f"Installing {str(context.config.distribution).capitalize()}"):
context.config.distribution.install(context)
- if (context.root / "etc").exists() and not (context.root / "etc/machine-id").exists():
+ if context.config.machine_id:
+ with umask(~0o755):
+ (context.root / "etc").mkdir(exist_ok=True)
+ with umask(~0o444):
+ (context.root / "etc/machine-id").write_text(context.config.machine_id.hex)
+ elif (context.root / "etc").exists() and not (context.root / "etc/machine-id").exists():
# Uninitialized means we want it to get initialized on first boot.
with umask(~0o444):
(context.root / "etc/machine-id").write_text("uninitialized\n")
hostname: Optional[str]
root_password: Optional[tuple[str, bool]]
root_shell: Optional[str]
+ machine_id: Optional[uuid.UUID]
autologin: bool
make_initrd: bool
parse=config_parse_string,
help="Set the shell for root",
),
+ ConfigSetting(
+ dest="machine_id",
+ metavar="MACHINE_ID",
+ section="Content",
+ parse=config_parse_uuid,
+ paths=("mkosi.machine-id",),
+ path_read_text=True,
+ help="Set the machine ID to use",
+ ),
ConfigSetting(
dest="autologin",
short="-a",
Hostname: {none_to_default(config.hostname)}
Root Password: {("(set)" if config.root_password else "(default)")}
Root Shell: {none_to_default(config.root_shell)}
+ Machine ID: {none_to_none(config.machine_id)}
Autologin: {yes_no(config.autologin)}
Make Initrd: {yes_no(config.make_initrd)}
def uuid_transformer(uuidstr: str, fieldtype: type[uuid.UUID]) -> uuid.UUID:
return uuid.UUID(uuidstr)
+ def optional_uuid_transformer(uuidstr: Optional[str], fieldtype: type[Optional[uuid.UUID]]) -> Optional[uuid.UUID]:
+ return uuid.UUID(uuidstr) if uuidstr is not None else None
+
def root_password_transformer(
rootpw: Optional[list[Union[str, bool]]], fieldtype: type[Optional[tuple[str, bool]]]
) -> Optional[tuple[str, bool]]:
Optional[Path]: optional_path_transformer,
list[Path]: path_list_transformer,
uuid.UUID: uuid_transformer,
+ Optional[uuid.UUID]: optional_uuid_transformer,
Optional[tuple[str, bool]]: root_password_transformer,
list[ConfigTree]: config_tree_transformer,
Architecture: enum_transformer,
a host system with the same SELinux policy as the image you're
building.
+`MachineId=`, `--machine-id=`
+
+: Takes a UUID or the special value `random`. Sets the machine ID of the
+ image to the specified UUID. If set to `random`, a random UUID will be
+ written to `/etc/machine-id`. If not specified explicitly and the file
+ `mkosi.machine-id` exists in the local directory, the UUID to use it
+ read from it. Otherwise, `uninitialized` will be written to `/etc/machine-id`.
+
### [Validation] Section
`SecureBoot=`, `--secure-boot`
"Locale": "en_C.UTF-8",
"LocaleMessages": "",
"Machine": "machine",
+ "MachineId": "b58253b0-cc92-4a34-8782-bcd99b20d07f",
"MakeInitrd": false,
"ManifestFormat": [
"json",
locale="en_C.UTF-8",
locale_messages="",
machine="machine",
+ machine_id=uuid.UUID("b58253b0cc924a348782bcd99b20d07f"),
make_initrd=False,
manifest_format=[ManifestFormat.json, ManifestFormat.changelog],
minimum_version=GenericVersion("123"),