Saturday, April 27, 2024
 Popular · Latest · Hot · Upcoming
2
rated 0 times [  2] [ 0]  / answers: 1 / hits: 980  / 2 Years ago, mon, march 28, 2022, 12:10:57

I have used Windows a couple years. Sometimes I had to shutdown laptop because of power loss or travel and the hibernate feature helped me. Now after switching to Ubuntu I found there is no hibernate feature. I have read some questions specifically this one.
How to enable hibernate option in Ubuntu 20.04?
Now after reading this guy's answer as he told I should have swap partition not swap file. Now unfortunately I have swap file. Now what if I wanted to hibernate WITH the swap file?


More From » swap

 Answers
7

To enable Hibernation in 20.04 using Swapfile:


Increase swapfile size to match RAM size up to 8GB.



  • Check the swap that is in use:


    sudo swapon -s


  • If swap partition(s) are found:


    sudo swapoff -a
    sudo nano -Bw /etc/fstab


  • Add # before the UUID of the swap partition(s):


    # UUID=XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX   none   swap    sw     0       0


  • Add a line for the swapfile, if one does not exist:


    /swapfile   none    swap     sw      0       0


  • Create the swapfile:


    sudo fallocate -l XG /swapfile*

    where X is swapfile's size in GB:


    sudo mkswap /swapfile
    sudo chmod 0600 /swapfile
    sudo swapon /swapfile


  • Reboot:


    sudo reboot



Add resume location and offset to grub.cfg:



  • Edit /etc/default/grub:


    GRUB_CMDLINE_LINUX_DEFAULT="quiet splash resume=UUID=XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX resume_offset=XXXXX"


  • Use UUID from root.



  • Use offset from:


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


  • Update GRUB:


    sudo update-grub


  • Test hibernation:


    sudo systemctl hibernate



A hibernate button can be added using GNOME extensions.


Note that there is a slight possibility of getting holes in a swapfile when creating it with fallocate. /var/log/syslog can be searched for the phrase swapon: swapfile has holes to ensure there will be no data loss.


A swap file can alternatively be created using dd:


sudo dd if=/dev/zero of=/swapfile bs=1G count=8

An error when using dd may overwrite your HDD.


[#1295] Tuesday, March 29, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
nuehan

Total Points: 253
Total Questions: 109
Total Answers: 120

Location: Singapore
Member since Sat, Jul 25, 2020
4 Years ago
nuehan questions
Sun, Dec 18, 22, 17:34, 1 Year ago
Fri, Jun 24, 22, 11:39, 2 Years ago
Thu, Apr 28, 22, 20:54, 2 Years ago
Fri, Aug 20, 21, 01:06, 3 Years ago
Fri, Dec 9, 22, 15:02, 1 Year ago
;