NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
16.85k stars 13.22k forks source link

Encrypted ZFS partition: very slow to boot #293294

Open tobiasBora opened 5 months ago

tobiasBora commented 5 months ago

Describe the bug

I have a ZFS encrypted dataset with an encrypted swap partition (encrypted via luks following this tutorial). When my system boots, after typing the passphrase, I see a message:

waiting for device /dev/disk/by-uuid/fe31…

where fe31… is the uuid of the decrypted swap. After 40 seconds (not sure why, but it runs now two times for the same drive) the message stops and the system boots, but this is really annoying to wait so long.

  swapDevices =
    [ {
        device = "/dev/disk/by-uuid/fe31620b-3a1e-480f-a496-bafbcf05f799";
        encrypted = {
          enable = true;
          keyFile = "/mnt-root/root/swap.key";
          label = "decrypted_swap";
          # The encrypted luks partition id is given by lsblk -o name,uuid
          blkDev = "/dev/disk/by-uuid/b29b8b20-5d18-45e1-9057-035abf76dcbf";
        };
      }
    ];

Steps To Reproduce

Steps to reproduce the behavior:

  1. Create an encrypted swap like in https://unix.stackexchange.com/a/529536, as zfs does not support swap. In my case the system runs in an encrypted ZFS pool that I created following the wiki https://wiki.nixos.org/wiki/ZFSç
  2. reboot, type your password, and wait

Expected behavior

I would expect not to wait so long.

Additional context

Might be related to https://github.com/NixOS/nixpkgs/issues/50346

Notify maintainers

@Madouura @alyssais you have modified https://github.com/NixOS/nixpkgs/blob/master/nixos/modules/system/boot/stage-1-init.sh recently

@abbradar you typed stuff related to waiting devices

Metadata

Running 23.11, 79baff8812a0d68e24a836df0a364c678089e2c7


Add a :+1: reaction to issues you find important.

tobiasBora commented 5 months ago

Note that I don’t know if it is possible to cover all use-cases… but at least maybe a way to enable/disable this phase, and/or to customize the waiting time could be nice?

emmanuelrosa commented 5 months ago

Perhaps you're affected by the swapon discard policy.

If:

then swapon will trim/discard the swap partition. I don't know of a way to turn that off; My swap partition is in a LUKS container, and I also have a boot delay, as you described.

See man swapon