nix-community / impermanence

Modules to help you handle persistent state on systems with ephemeral root storage [maintainer=@talyz]
MIT License
1.03k stars 77 forks source link

Persistence files mount units error when `boot.initrd.systemd.enable = true;` #119

Closed oneingan closed 1 year ago

oneingan commented 1 year ago

If boot.initrd.systemd.enable = true; in 22.11 then systemd unit mounts fail with:

Mar 21 20:59:46 x2100 systemd[1]: Starting Bind mount or link '/persist/etc/machine-id' to '/etc/machine-id'...
Mar 21 20:59:46 x2100 2bgs67hdclia3k8vdyqpcnsiyd7wh042-impermanence-mount-file[1303]: A file already exists at /etc/machine-id!
Mar 21 20:59:46 x2100 systemd[1]: persist--persist-etc-machine-id-.service: Main process exited, code=exited, status=1/FAILURE
Mar 21 20:59:46 x2100 systemd[1]: persist--persist-etc-machine-id-.service: Failed with result 'exit-code'.
Mar 21 20:59:46 x2100 systemd[1]: Failed to start Bind mount or link '/persist/etc/machine-id' to '/etc/machine-id'.

I guess because local-fs.target is included in initrd, creating the files previous to stage2 boot. The existent files are empty.

Directories mount units are working ok.

I tried to exclude persist-- failed units using boot.initrd.systemd.suppressedUnits but without luck.

oneingan commented 1 year ago

Ok, after some investigation I've discovered main reason because boot.initrd.systemd is not working. My zfs was not restoring to blank after reboot. This is because configuration:

boot.initrd.postDeviceCommands = lib.mkAfter ''
   zfs rollback -r rpool/local/root@blank
''

was being ignored. As i have not found a initrd.systemd equivalent I migrated to root on tpmfs and everything is working well again.

lovesegfault commented 1 year ago

I think you'd just create a oneshot service that the initrd systemd would execute, but tmpfs also works!

xxxcrow commented 1 year ago

For anyone looking for a solution There's one for zfs and for btrfs Thank to the awesome people who found the exact solution 🫡 https://discourse.nixos.org/t/impermanence-vs-systemd-initrd-w-tpm-unlocking/25167/2