enabling hibernation in ubuntu and let the system do it automatically on idel


A- Check swap settings and resize it if needed

1- check swap

swapon --show


2- resize Swap

sudo swapoff /swapfile

sudo dd if=/dev/zero of=/swapfile bs=1MB count=$((4*1024)) status=progress

sudo chmod 600 /swapfile

sudo mkswap /swapfile

sudo swapon /swapfile

- check swap

swapon --show

- check swap size

free -h

- updater grup

-- get system drive uuid

sudo blkid /dev/sda3



-- get swap file offset number

sudo filefrag -v /swapfile | head --lines=10

sudo gedit /etc/fstab

- add swap line

 - edit grup settings

sudo gedit /etc/default/grub

Add the text resume=UUID=<your-root-filesystem-UUID> resume_offset=<swapfile_physical_offset> at the end of the GRUB_CMDLINE_LINUX_DEFAULT  

sudo update-grub


- show hibernate on power menu

sudo apt-get install gnome-shell-extensions-alternative-status-menu

open the app and enable the hibernate option


- enable hibernate on sleep 

gsettings set org.gnome.settings-daemon.plugins.power sleep-inactive-ac-type 'hibernate'