0

Somehow I could install Ubuntu 18.10 without creating any SWAP partition nor I seem to have a SWAP file. I wonder if I still could get hibernation to work, without having both of them. I tried already creating a SWAP-file and hibernate with it, but that did not work.

Is there a way around the SWAP file and get hibernation running?

2 Answers2

1

I fear creating a SWAP file is your only option. Your RAM state needs to be held somewhere on the disk while power is off. Maybe you created too small SWAP – it is recommended to have the SWAP space at least as big as your RAM (+ some small reserve). I have Ubuntu 18.10 with 16 GB of RAM and 19 GB of SWAP file and it works well.

Nevertheless, it seems you didn't tell the system it should use SWAP to resume from hibernation. Modify /etc/default/grub (sudoedit /etc/default/grub), edit the line GRUB_CMDLINE_LINUX_DEFAULT and put there parameters resume (with your /dev/ UID of partition having the SWAP file) and resume_offset with the starting value of physical_offset of this swap.

(You'll get this value by checking output of sudo filefrag -v /swapfile | head.)

Finally, reload by sudo update-grub.

For more thorough answer about setting GRUB, see an excellent section Hibernation using a swap file: How can I hibernate on Ubuntu 16.04?

Tell us if you succeeded.

  • 1
    Thanks for you answer. I will test this as soon as possible but the last time I did not tell Grub to use it. – SnowGepard Feb 18 '19 at 17:10
  • I just tried to follow the steps given here [https://askubuntu.com/questions/768136/how-can-i-hibernate-on-ubuntu-16-04]. But with the first command grep swap /etc/fstab I get back /swapfile none swap sw 0 0 which does not help a lot. I know that I have a swap file right now of 2Gb of size, which is way to less for my system. – SnowGepard Feb 19 '19 at 09:55
  • I tried the option with the swapfile and increased the size to 38Gb, since my system has 32Gb RAM. It did not work. I followed this manual https://www.linuxuprising.com/2018/08/how-to-use-swap-file-instead-of-swap.html, but without changing '/etc/initramfs-tools/conf.d/resume' since this file does not exist on my system. It does not work and I am not sure how to continue without breaking initramfs. – SnowGepard Feb 23 '19 at 10:36
1

Yes you can find answers elsewhere searching for hibernate + linux + file but I post the super-short answer:

sudo filefrag -v /swapfile |grep " 0:"| awk '{print $4}'

in my system for example it gives: 57643008.. (for the sake of curiosity this is the offset of the swap file the file system...) put away this number (we will use it later) and find another number:

lsblk -o UUID,MOUNTPOINT

in my system for example it gives:

0ec9c519-c7ec-43e3-b812-967d81842458 /home

eb343dae-82e4-4155-9026-18c891d3252b /

since the swap file is in / it is this the UUID of interest. Then add to /etc/default/grub:

GRUB_CMDLINE_LINUX_DEFAULT="quiet splash resume=UUID=eb343dae-82e4-4155-9026-18c891d3252b resume_offset=57643008"

sudo update-grub

and you are done (use your UUID and OFFSET numbers obviously). Test it with the command:

sudo hibernate

PS: according to some kernel docs that I can't find now, it should be sufficient a swap file of half of your RAM size or less (they say 2/5). Check with: cat /sys/power/image_size

ciampix
  • 604
  • In combination with https://linuxize.com/post/how-to-add-swap-space-on-ubuntu-18-04/ this solved my question. Now I just need to figure out how to add the option back in the power menu, so that I can select that the laptop goes into hibernation when not plugged in and I close the lid. – SnowGepard Mar 15 '19 at 08:42