Sagar Behere

I doubt, therefore I might be

Hibernate with encrypted LVM

The situation: Your Linux installation is on an encrypted LVM, there is no swap partition and you wish to enable hibernation.

The solution:

  • Allocate swap space for storing system state
sudo fallocate -l 8000m /swap   #creates 8000MB swap file
sudo mkswap /swap
sudo swapon /swap

Add the line below to /etc/fstab

/swap   swap    swap    defaults        0       0
  • Set swappiness to 1 (A swappiness setting of zero means that the disk will be avoided unless absolutely necessary (you run out of memory), while a swappiness setting of 100 means that programs will be swapped to disk almost instantly.)
sudo sysctl -w vm.swappiness=1  

To make the swappiness setting permanent, put vm.swappiness=1 in a file /etc/sysctl.d/local.conf

  • Install and configure uswsusp
sudo apt-get install uswsusp  
sudo dpkg-reconfigure -pmedium uswsusp  

edit /etc/uswsusp.conf and modify the resume device, setting it to whatever LV your / is on

resume device = /dev/mapper/maya-root

Tip: resume offset in above file can be calculated with sudo swap-offset /swap

  • Modify GRUB2

Add the following line to /etc/default/grub

GRUB_CMDLINE_LINUX_DEFAULT="resume=/dev/mapper/maya-root"

update grub

sudo update-grub

Now, the computer can be hibernated with the command sudo s2disk