3

How can I enable hibernate on fresh installed system if it's possible.

# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
# / was on /dev/nvme0n1p2 during installation
UUID=c14a936e-6c0f-4228-beec-c39bc515b157 /               ext4    errors=remount-ro 0       1
# /boot/efi was on /dev/nvme0n1p1 during installation
UUID=1036-AA2D  /boot/efi       vfat    umask=0077      0       1
/swapfile                                 none            swap    sw              0       0

I tried In /ect/default/grub - GRUB_CMDLINE_LINUX_DEFAULT="quiet splash resume=UUID=c14a936e-6c0f-4228-beec-c39bc515b157", but this is not working. Thanks.

zarok13
  • 43
  • When using a swapfile you need to also add resume_offset to /ect/default/grub. See answer below. – C.S.Cameron Nov 07 '20 at 10:19
  • C.S.Cameron thanks for reply, I done steps below and in result powering off(takes some longer) without saving opened programs and windows. I am doing something wrong? – zarok13 Nov 07 '20 at 17:02
  • Writing swap data to disk takes longer than just shutting down. Booting the swap data also takes longer. How big is your RAM? Try booting, opening Terminal only and then typing sudo systemctl hibernate. and then reboot. What does sudo swapon -s say? – C.S.Cameron Nov 08 '20 at 01:02
  • /swapfile file 2097148 0 -2 Hibernate not working similar like in Windows OS, opened programs not staying opened after power on. – zarok13 Nov 08 '20 at 15:35
  • In Terminal what does sudo swapon -s report? What does Free report? – C.S.Cameron Nov 09 '20 at 02:09
  • free report - total used free shared buff/cache available Mem: 7915688 1732996 4514864 218924 1667828 5687960 Swap: 2097148 0 2097148 – zarok13 Nov 09 '20 at 06:10
  • My understanding is that for hibernation you should have 8GB swap space for 8GB of RAM. You show 2GB of swap. That might be enough to resume if you only have Terminal open, maybe not. Use fallocate or dd to enlarge swapfile to 8GB as show below. Please also send results of sudo swapon -s – C.S.Cameron Nov 09 '20 at 06:30
  • sudo swapon -s result Filename Type Size Used Priority /swapfile file 2097148 0 -2. Maybe I need to change swapfile to swap partition? – zarok13 Nov 09 '20 at 19:40
  • If you switch to a swap partition you will still require 8GB swap for your 8GB RAM. But you will not require resume_offset=. Personally I would try a 8GB swapfile before changing to a swap partition, but this is just personal preference. Some people prefer swap partitions. – C.S.Cameron Nov 10 '20 at 07:51
  • 5
  • Looks like yes, thanks. – zarok13 Aug 09 '21 at 09:11

1 Answers1

4

To enable Hibernation in 20.04:

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.

C.S.Cameron
  • 19,519