Ansible role that configures swap file and hibernation on Ubuntu 18.04
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
taha@asks2 63c2bb74d6 Merge branch 'hibernate' into main 1 month ago
defaults Edited comments for clarity 1 month ago
tasks Hibernation and wake up achieved! 1 month ago
README.md Hibernation and wake up achieved! 1 month ago

README.md

Swap and hibernation

This role configures swap file (not partition) on Ubuntu/Debian hosts. Additionally, it sets up hibernation (suspend to disk).

Swap

Presently, this role cannot handle hosts with swap partitions, only swap files. https://stackoverflow.com/questions/24765930/add-swap-memory-with-ansible/33071279 Future work: modify this role so it can handle swap partitions too.

For example,

$ swapon --show
NAME      TYPE      SIZE USED PRIO
/dev/dm-2 partition 980M   0B   -2

For extra points, tweak this role to only disable and recreate if the existing swap size is different to requested swap_size (e.g., check using swapon --show or free -m). Because at the moment, this role is rather aggressive and always destroys any existing swap size irrespective of whether it's of the desired size, before creating a new swap file.

Hibernation

Does the kernel support hibernation? /sys/power/state needs to contain disk. It does:

taha@asks2:~
$ cat /sys/power/state
freeze mem disk

Also check the contents of /sys/power/disk, it should not say disabled.

$ cat /sys/power/disk
[platform] shutdown reboot suspend test_resume

It works!

No frills, no locked screen on wake, etc. But it works! Looking forward to massive electricity savings.

To hibernate, sudo systemctl hibernate.

Press any key to wake up.