# right fit swap for laptop hibernation - Ubuntu 20.04 full ZFS install
2020-06-22 10:32:01 +02:00
## sources
* [rephlex.de - How to hibernate and resume from swap file in Ubuntu 20.04 using full disk encryption](https://rephlex.de/blog/2019/12/27/how-to-hibernate-and-resume-from-swap-file-in-ubuntu-20-04-using-full-disk-encryption/)
* [help.ubuntu.com - Enable Hibernate With Encrypted Swap](https://help.ubuntu.com/community/EnableHibernateWithEncryptedSwap#Preparation)
* [tlbdk.github.io - encrypted swap on Ubuntu 18.10](http://tlbdk.github.io/ubuntu/2018/10/22/encrypted-swap.html)
2020-06-22 10:42:05 +02:00
2020-06-22 15:10:00 +02:00
## prerequisite
2020-06-22 10:30:18 +02:00
2020-06-22 15:10:00 +02:00
* This setup is based on an almost full ZFS install see : [Unbuntu-20.04-encrypt-ZFS-install](./Unbuntu-20.04-encrypt-ZFS-install)
* bios setup : You have to **disable secure boot** in bios to permit Hibernate because of *kernel lockdown prevent hibernation* see link : [stackexchange - Why does the kernel lockdown prevent hibernation?](https://unix.stackexchange.com/questions/591488/why-does-the-kernel-lockdown-prevent-hibernation)
2020-06-22 10:30:18 +02:00
2020-06-22 09:51:26 +02:00
## create swap partition to permit Hibernate
2020-06-22 15:04:26 +02:00
With default Ubuntu zsys-setup full ZFS install swap will have 2GB wich is maybe not enough for your systeme. We have to create a swap partition with a size which fit RAM size for hibernation.
2020-06-22 09:51:26 +02:00
add theses 2 lines in : */usr/share/ubiquity/zsys-setup*
## configure hibernate to auto switch from sleep to hibernate
2020-06-22 10:25:22 +02:00
source : [Linux Mint Forums : Enable Hibernation with LUKS on LVM and extras](https://forums.linuxmint.com/viewtopic.php?t=287015)
2020-06-22 10:01:56 +02:00
edit : */etc/systemd/sleep.conf*
And add this value to it (The number represents seconds you want to pass in sleep, after which the computer will switch to hibernation, so you can put it in 60 seconds or something short just to check it's working and after that you can put whatever ammount of time you want):
~~~
[Sleep]
2020-06-22 14:14:07 +02:00
HibernateDelaySec=1200
2020-06-22 10:01:56 +02:00
~~~
2020-06-22 14:14:07 +02:00
Here I choose 1200 for 20min, I think that I can move from one place to an other in less than 20min if it's more systeme goes to hibernate mode.
2020-06-22 10:30:18 +02:00
Modify this two lines in /etc/systemd/logind.conf for sleep key and closing the lid actions if that's how you want it:
2020-06-22 10:01:56 +02:00
2020-06-22 10:30:18 +02:00
~~~
HandleSuspendKey=suspend-then-hibernate
HandleLidSwitch=suspend-then-hibernate
~~~
2020-06-22 10:01:56 +02:00
2020-06-22 13:12:46 +02:00
## xfce4-power-manager suspend to hibernate option
Because it's not possible to configure suspend-then-hibernate for Lid close inside XFCE Power Manager Control Panel, you will make logind handle button events instead of xfce4-power-manager.
2020-06-22 13:59:08 +02:00
2020-06-22 15:06:55 +02:00
* To have logind handle the lid open/close event, has your normal user do this in a terminal :