Unable hibernate with encrypted swap

systemctl hibernate -i
Failed to hibernate system via logind: Not enough swap space for hibernation
 - system: `"x86_64-linux"`
 - host os: `Linux 6.0.9, NixOS, 22.11 (Raccoon), 22.11.20221121.af50806`

Related config :

  swapDevices = [{
    device = "/dev/disk/by-uuid/e58a561c-60a8-4fa4-92e6-f3dba68c3360";
    options = [ "defaults" "nofail" ];
    discardPolicy = "once";
    encrypted = {
      label = "swap";
      blkDev = "/dev/disk/by-partuuid/5f92a962-fe03-4dbd-8276-99b76bdadb36";
      enable = true;
      keyFile = "/mnt-root/.swapkey";
    };
  }];
  boot = {
    kernelParams =
      [ "amd_iommu=off" "iommu=soft" "quiet" "udev.log_level=3" "loglevel=3" "resume=PARTUUID=5f92a962-fe03-4dbd-8276-99b76bdadb36" ];

resumeDevice = "/dev/disk/by-partuuid/5f92a962-fe03-4dbd-8276-99b76bdadb36";

related disks :

sda                 8:0    0 447,1G  0 disk
└─sda1              8:1    0 447,1G  0 part
  └─nix_vg-nix_lv 254:0    0 890,3G  0 lvm
    └─nix_root    254:1    0 890,2G  0 crypt /nix/store
                                             /
sdb                 8:16   0 447,1G  0 disk
├─sdb1              8:17   0     2G  0 part  /boot
└─sdb2              8:18   0 445,1G  0 part
  └─nix_vg-nix_lv 254:0    0 890,3G  0 lvm
    └─nix_root    254:1    0 890,2G  0 crypt /nix/store
                                             /
sdd                 8:48   0 111,8G  0 disk
├─sdd1              8:49   0    32G  0 part
│ └─swap          254:2    0    32G  0 crypt [SWAP]
└─sdd2              8:50   0  79,8G  0 part  /mnt/vms
 free -h
              total        used        free      
Mem:           11Gi       4,1Gi       5,6Gi
Swap:          31Gi          0B        31Gi

full conf

Can you take a look at dmesg output after trying to hibernate?

I had a similar error but for a different problem, I had my swap file on a btrfs filesystem with COW enabled on it, and dmesg reported the error clearly.

dmesg returns nothing about it, but i may have found the culprit.

cat /sys/power/resume shows 8:17, while should be 254:2 .

When I change it I can run systemctl hibernate, but the computer effectively comes back from not from swap, but as if i’m performing a cold boot.

.
.
.
btw i’m a big fan of your articles.

1 Like

First, i was using the LUKS device PARTUUID instead of the swap UUID on the kernel resume= parameter, Second, i had to add the swap luks partition to boot.initrd.luks.devices. Hibernation is working now but i gave up using a keyfile and am using a passphrase. wich i have to type two times despite being the same for my root luks container and my swap luks container, but that’s another issue.

1 Like
Hosted by Flying Circus.