wiki-system/right-fit-swap-for-laptop-h...

153 lines
5.5 KiB
Markdown
Raw Normal View History

2020-06-22 15:02:29 +02:00
# 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/)
2020-06-22 10:33:08 +02:00
* [doc.ubuntu-fr.org - Comment activer l'hibernation](https://doc.ubuntu-fr.org/tutoriel/activer_hibernation)
2020-06-22 10:43:53 +02:00
* [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 10:30:18 +02:00
## bios setup
2020-06-22 15:02:56 +02:00
You have to **disable secure boot** in bios to permit Hibernate because of *kernel lockdown prevent hibernation* see links bellow :
2020-06-22 10:30:18 +02:00
2020-06-22 10:32:01 +02:00
* [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*
~~~{.shell}
MEMSIZE=$(cat /proc/meminfo | grep MemTotal | awk -F' ' '{print $2}')
SWAPVOLSIZE=$(( MEMSIZE / 1024 ))
~~~
like bellow :
~~~{.shell}
2020-06-22 10:34:50 +02:00
# Convert to MiB to align the size on the size of a block
2020-06-22 09:51:26 +02:00
SWAPVOLSIZE=$(( SWAPSIZE / 1024 / 1024 ))
MEMSIZE=$(cat /proc/meminfo | grep MemTotal | awk -F' ' '{print $2}')
SWAPVOLSIZE=$(( MEMSIZE / 1024 ))
prepare_target "${TARGET}"
format_disk "${DISK}" "${PARTBASE}" "${PARTESP}" "${PARTBPOOL}" "${PARTRPOOL}" "${SWAPVOLSIZE}"
init_zfs "${TARGET}" "${DISK}${PARTBASE}${PARTBPOOL}" "${DISK}${PARTBASE}${PARTRPOOL}"
init_system_partitions "${TARGET}" "${DISK}${PARTBASE}1" "${DISK}${PARTBASE}${PARTESP}"
~~~
Run ubiquity to start the installer and install as normal, selecting “Use entire disk” and the option to use ZFS.
2020-06-22 10:02:40 +02:00
## activate hibernation in system
2020-06-22 10:01:56 +02:00
Disable secure boot in bios to permit Hibernate.
~~~
apt install pm-utils
~~~
~~~
printf "RESUME=UUID=$(blkid | awk -F\" '/swap/ {print $2}')\n" | head -n 1| sudo tee /etc/initramfs-tools/conf.d/resume
~~~
you can check with : *blkid*
~~~
update-initramfs -u -k all
~~~
change /etc/default/grub : add your resume UUID into GRUB_CMDLINE_LINUX_DEFAULT
~~~
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash resume=UUID=75034ff5-...-9e4564e16d34"
~~~
2020-06-22 15:05:44 +02:00
Edit file : /etc/polkit-1/localauthority/50-local.d/com.ubuntu.enable-hibernate.pkla
2020-06-22 10:01:56 +02:00
~~~
[Réactive hiberner par défaut dans upower]
Identity=unix-user:*
Action=org.freedesktop.upower.hibernate
ResultActive=yes
[Réactive hiberner par défaut dans logind]
Identity=unix-user:*
Action=org.freedesktop.login1.hibernate;org.freedesktop.login1.handle-hibernate-key;org.freedesktop.login1;org.freedesktop.login1.hibernate-multiple-sessions;org.freedesktop.login1.hibernate-ignore-inhibit
ResultActive=yes
~~~
## 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
## encrypt swap partition
2020-06-22 15:01:17 +02:00
source : [wiki.archlinux.org - dm-crypt/Swap encryption](https://wiki.archlinux.org/index.php/Dm-crypt/Swap_encryption#LVM_on_LUKS)
2020-06-22 10:01:56 +02:00
~~~
apt-get install ecryptfs-utils
swapoff -a
cryptsetup luksFormat --cipher aes-xts-plain64 --verify-passphrase --key-size 256 /dev/nvme0n1p2
2020-06-22 14:51:50 +02:00
cryptsetup open /dev/<device> swapDevice
mkswap /dev/mapper/mkswap /dev/mapper/swapDevice
2020-06-22 10:01:56 +02:00
~~~
2020-06-22 14:49:17 +02:00
edit : /etc/default/grub
2020-06-22 10:01:56 +02:00
~~~
2020-06-22 14:55:01 +02:00
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash resume=/dev/mapper/swapDevice"
2020-06-22 13:12:46 +02:00
~~~
2020-06-22 14:49:17 +02:00
~~~
update-grub
~~~
2020-06-22 14:58:48 +02:00
Now ajust /etc/fstab to use your mapper, replace your swap UUID device to :
~~~
/dev/mapper/swapDevice none swap discard 0 0
~~~
~~~
swapon -a
~~~
2020-06-22 14:37:25 +02:00
### to be solve
~~~
cryptsetup: ERROR: Couln't resolve device rpool/ROOT/ubuntu_...
cryptsetup: WARNING: Couln't determine root device
~~~
2020-06-22 13:12:46 +02:00
## xfce4-power-manager suspend to hibernate option
2020-06-22 13:59:08 +02:00
source : [docs.xfce.org - Frequently Asked Questions - Xfce4 Power Manager](https://docs.xfce.org/xfce/xfce4-power-manager/faq)
2020-06-22 14:34:26 +02:00
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
* To have logind handle the lid open/close event
2020-06-22 13:12:46 +02:00
~~~
xfconf-query -c xfce4-power-manager -p /xfce4-power-manager/logind-handle-lid-switch -n -t bool -s true
~~~
If you want everything time related, then you can set them with settings in /etc/systemd : **sleep.conf** and **logind.conf**