Is it possible to hibernate with swap-file?

#1

Hello everyone,

One one of my nixos installation I’m using swapfile and noticed that hibernation never works.
I made sure that resume=/var/swap-file and resume_offset=myoffset are present in my kernel boot args.
I did calculate resume_offset using filefrag -v /var/swapfile | awk '{if($1=="0:"){print $4}}' as per information that i found on arch wiki https://wiki.archlinux.org/index.php/Power_management/Suspend_and_hibernate#Hibernation_into_swap_file.

I also noticed that in init script following lines:

# Clear the resume device.
if test -n "$resumeDevice"; then
    mkswap "$resumeDevice" || echo 'Failed to clear saved image.'
fi

Does this mean that swap device will be always flushed?

Here is relevant part of my configuration:

  boot.kernelParams = [  "resume=/var/swapfile" "resume_offset=450560" ];
  swapDevices = [ { device = "/var/swapfile"; size = 32768; } ];
  boot.resumeDevice = "/var/swapfile";

I’m currently using nixos-unstable channel with 5.0+ kernel version.

Any information would help me understand what is going on better.

Thank you very much in advance!

#2

Ok, this was a problem on my end.

boot.resumeDevice = "/dev/mapper/myroot";

Is the correct option, no need for resume=/var/swapfile in boot.kernelParams also.
resumeDevice should be pointing at partition that swap file resides on.

More info can be found here:

https://www.kernel.org/doc/Documentation/power/swsusp-and-swap-files.txt

1 Like