I had this failure when testing https://github.com/systemd/mkosi/pull/1442. But
it would happen whenever the installed system has no /etc/shadow and we want to
set the password, so it's worth fixing regardless.
return ":".join(["root", password] + line.split(":")[2:])
return line
- patch_file(state.root / "etc/shadow", set_root_pw)
+ shadow = state.root / "etc/shadow"
+ try:
+ patch_file(shadow, set_root_pw)
+ except FileNotFoundError:
+ shadow.write_text(f"root:{password}:0:0:99999:7:::")
def configure_autologin(state: MkosiState) -> None: