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?
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.
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.
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.
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.
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.
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
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
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.