nix-community/impermanence

Mounting paths needed for boot can fail

m-bdf opened this issue · 5 comments

m-bdf commented

Booting a system with environment.persistence."/persistent".directories = [ "/var/lib/nixos" ] (from the README) fails if /persistent/var/lib/nixos does not exist yet:

waiting for device /mnt-root/persistent/var/lib/nixos to appear.......................
Timed out waiting for device /mnt-root/persistent/var/lib/nixos, trying to mount anyway.
mounting /mnt-root/persistent/var/lib/nixos on /var/lib/nixos...
mount: mounting /mnt-root/persistent/var/lib/nixos on /mnt-root/var/lib/nixos failed: No such file or directory

An error occurred in stage 1 of the boot process, which must mount the
root filesystem on `/mnt-root` and then start stage 2. Press one
of the following keys:

  r) to reboot immediately
  *) to ignore the error and continue

The init script of boot stage 1 tries to mount non-existent /persistent/var/lib/nixos on /var/lib/nixos, because this path is needed for boot. However, the activation script responsible for creating missing directories is only run after stage 1, so mounting fails.

This issue should occur for any path needed for boot, whose persistent storage does not exist at boot.

m-bdf commented

Note that for some reason this is not an issue with boot.initrd.systemd.enable = true;

Maybe you need the option neededForBoot.

m-bdf commented

I agree it looks like this should fix it, but unfortunately it doesn't, my /persistent filesystem is already marked neededForBoot.
If it works with systemd-based initrd, maybe it's a bug in NixOS's traditional scripted initrd?

For anyone who struggles with this, try:

boot.initrd.systemd.enable = true;
boot.loader.efi.canTouchEfiVariables = true;

Please try #172 and see if it fixes this issue for you.