Can't seem to get hibernation to work properly

So I have configured swap via a swapfile which resides in /swapfile. I have edited /etc/fstab file and added this line /swapfile none swap defaults 0 0

I have rebooted the system and I have verified that the swapfile is successfully configured with 8 GB.

I have now attempted to modify the grub file in /etc/default/grub and added inside this line GRUB_CMDLINE_LINUX="" this part GRUB_CMDLINE_LINUX="ro resume=/swapfile" then I ran sudo grub-mkconfig -o /boot/grub/grub.cfg` to rebuild the grub file. After a reboot I get a warning message claiming that the root partition cannot be mounted and it will be read only. While on KDE it is showing I can hibernate but when i click on it it does nothing other than to shut down the PC.

I removed this line and rebooted and while the warning message is gone, the hibernation option is still showing but I can’t hibernate. I am not too sure why it is not working?

made it by https://wiki.archlinux.org/index.php/Swap#Swap_file ?

also edit the rights for the swapfile as on wiki?

1 Like

Specifying the swap file for hibernate is a bit trickier: https://wiki.archlinux.org/index.php/Power_management/Suspend_and_hibernate#Hibernation_into_swap_file

1 Like

I usually follow this guide when I setup hibernation. I don’t think you also set the resume_offset properly

Also, if you don’t want to type out the whole sudo grub mkconfig -o /boot/grub/grub.cfg every time you update grub. . . .yay -S update-grub

2 Likes

Hey man.

Ok so this is from the website that you linked to.

image

This is what it looks like for me. So which one is under the physical_offset? Is it the 2392064.. or 2621439:?

Interesting, thanks for letting me know :slight_smile:

2392064

Thanks bro.

Thank me when it works. Hopefully, you should be good after though!

1 Like

Unfortunately the same problem.

GRUB_CMDLINE_LINUX="resume=/swapfile resume_offset=2392064" I literally added this I don’t get why this is happening.

That is not correct. The right side of the assignment should contain the partition info where the swapfile exists, according to the links.

1 Like

Ah damn I didn’t realise I thought it was pointing to where the swap partition was located. Thanks

The /swapfile is located in /dev/sda3. I added GRUB_CMDLINE_LINUX="resume=/dev/sda3" resume_offset=2392064" and it is still not working, even after updating the grub files and rebootiing the system.

I’m no expert on this, but the link
https://wiki.archlinux.org/index.php/Power_management/Suspend_and_hibernate#Hibernation_into_swap_file
shows there are more steps to be made.

Please note that I’m not using a swapfile, and never tried a swapfile. I have used swap partition, but currently no more as I have lots of RAM.
If swap partition is OK for you, then that might be easier to make work.

1 Like

Try this for the correct grub entry.

  1. Get required information:

sudo findmnt -no UUID -T /swapfile
will give you the uuid of your swapdevice.

sudo filefrag -v /swapfile | awk '{ if($1=="0:"){print $4} }'
will give you the resume offset (ignore the two dots).

  1. Add the resume information to /etc/default/grub

GRUB_CMDLINE_LINUX_DEFAULT="[...] resume=UUID=<the-UUID-from-above> resume_offset=<your-ID-offset>"

  1. Update Grub

sudo grub-mkconfig -o /boot/grub/grub.cfg


Note that with 8GB of RAM your swapfile should be at least this size to guarantee hibernation in all cases.
Also, if your swapfile resides on a btrfs filesystem the above method of getting the resume offset will not work.

1 Like

Make sure you are getting correct output from cat /sys/power/resume and cat /sys/power/resume_offset. The first should produce the major and minor device numbers of the volume on which the swap file is located. You can get them with lsblk -o NAME,UUID,MAJ:MIN (last column of the correct device). The second command should show the resume_offset you specified in the kernel parameters.

Also, don’t forget to add resume hook to the HOOKS array in /etc/mkinitcpio.conf ( https://wiki.archlinux.org/index.php/Power_management/Suspend_and_hibernate#Configure_the_initramfs ).

And how are you actually trying to hibernate? Via systemctl?

Why? I’m successfully hibernating into a swap file on a btrfs filesystem…

2 Likes

Quoting the ArchWiki [2020-07-25]:
“The resume_offset number can be computed using the tool btrfs_map_physical.c. Do not try to use the filefrag tool, on Btrfs the “physical” offset you get from filefrag is not the real physical offset on disk; there is a virtual disk address space in order to support multiple devices.”

The last time I actually checked filefrag information against btrfs_map_physical.c was at the end of 2019. Maybe the current systemd, filefrag etc. don’t have this issue anymore; the ArchWiki entry still refers to the alternate method for btrfs though, so I assumed it was still critical. I apologize if this isn’t the case anymore; didn’t mean to unsettle anybody.

1 Like

Thank you for the explanation, I just somehow managed to miss that information in the archwiki. I’m certainly seeing different offsets in the output of filefrag and btrfs_map_physical.c. Still can hibernate normally using the one from filefrag, weird. It is gentoo though and 5.4.48 kernel. Just got lucky I guess.

edit: actually not, the offset returned by filefrag is correct, sorry. I just forgot to divide by the page size :woman_facepalming:

2 Likes

Thanks for the link. I wish I could use a swap partition. However cause I am using MBR, I can’t create more than 4 partitions. I have already maxed out on that.

Thanks mate. It didn’t work but after adding the resume inside the HOOKS as suggested by @Tasia91 it works

@unix_lover
What about this?
cat /etc/fstab

1 Like

It shows all my mounted partitions and my swap file (I did add the swap file manually myself) but anyways it all works now. I guess I just needed to add the resume inside the HOOKS inside etc/mkinitcpio.conf and rebuild it.