ZFS and hibernate/suspend to disk

Hello,
I want my laptop to hibernate (suspend to disk). At the moment the whole system is using ZFS, and i dont get the option to suspend in KDE/plasma. What should i do to make the laptop hibernate. Also i am willing to move the root partition to non-ZFS filesystem if that is needed.

Thanks

You have to use a non-zfs partition for your swap. Then you can hibernate to that but keep your zfs root.

I do have swap defined which is encrypted using LUKS. The nvme0n1p7 partition holds the encrypted swap,

# lsblk -f
NAME          FSTYPE      FSVER LABEL           UUID                                 FSAVAIL FSUSE% MOUNTPOINTS
nvme0n1                                                                                             
├─nvme0n1p1   vfat        FAT32                 7284-11DE                             839.9M    18% /boot
├─nvme0n1p2                                                                                         
├─nvme0n1p3   ntfs                              617062D81F0FED88                                    
├─nvme0n1p4   ntfs              System Reserved 1672A6FB72A6DEAD                                    
├─nvme0n1p5   crypto_LUKS 2                     040aefdc-0919-495d-a923-8eefcf7843a3                
│ └─key                                                                                             
├─nvme0n1p6                                                                                         
├─nvme0n1p7   crypto_LUKS 2                     5df7fec0-8e2c-4ed1-97af-7e26aa64bf14                
│ └─cryptswap swap        1     swap            5af86a2f-58d2-45a3-a3fe-d1fc77d3e49b                [SWAP]
└─nvme0n1p8   crypto_LUKS 2                     1322bbd9-d585-4ac2-9438-b9acdc0bbfb0                
  └─cryptroot zfs_member  5000  rpool           10106504503940527360                                

However, i still dont get the suspend option. What am i missing?

You should be able to suspend to RAM, but NixOS explicitly disables hibernation with the nohibernate kernel param when ZFS is enabled because there are known bugs in ZFS that will irreparably corrupt imported pools when resuming from hibernation. You can set boot.zfs.allowHibernation = true; if you really want, because the bugs that causes the pools to break are pretty unlikely. But it’s risky and I wouldn’t.

1 Like

Are those issues present regardless of whether or not swap is on a zvol?

I thought the corruption issues only applied to systems trying to hibernate to a zvol.

No. The problem with swap on zvol is just that it’ll deadlock. It doesn’t cause corruption. The problem with hibernation is simply that the freeze procedure in ZFS is buggy, regardless of what swap is stored on. IIRC the freeze procedure doesn’t actually stop ZFS from doing a little more IO before the kernel actually shuts down. But that IO happened too late and isn’t tracked in the state of the memory in the hibernation image. So when you resume the state on disk is effectively in the future compared to the information ZFS has in memory, and it can cause the whole pool to become unusable.

1 Like