Skip to content

Instantly share code, notes, and snippets.

@nealfennimore
Last active July 26, 2022 04:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nealfennimore/f842e0cf9a4b6f4e6b839f94ce1c21bc to your computer and use it in GitHub Desktop.
Save nealfennimore/f842e0cf9a4b6f4e6b839f94ce1c21bc to your computer and use it in GitHub Desktop.
PopOS BTRFS LUKS encrypted swap hibernation

Originally from: wmutschl/mutschler.eu#13 (comment)

  1. Create a LUKS partition for swap with the same password as cryptdata:
cryptsetup luksFormat /dev/nvme0n1p4

Ensure swap partition shows as linux-swap in gparted. If not, open gparted and decrypt the swap drive and then reformat as swap again.

If it has a new LUKS UUID, make sure to update in the /etc/crypttab, then close encryption on gparted in order to remount to the proper location that cryptswap is expecting.

cryptsetup luksOpen /dev/nvme0n1p4 /dev/mapper/cryptswap
swapon -a 
  1. Change /etc/crypttab to look like this:
cryptdata UUID=something-something none luks,discard,keyscript=decrypt_keyctl
cryptswap UUID=bla-bla-bla none luks,discard,swap,tries=1,keyscript=decrypt_keyctl
  1. Add "resume=/dev/mapper/cryptswap" as a kernel flag:
sudo kernelstub -a "resume=/dev/mapper/cryptswap"

(or manually add it to the "user" section of /etc/kernelstub/configuration)

  1. Add line RESUME=/dev/mapper/cryptswap to /etc/initramfs-tools/conf.d/resume, or replace RESUME line if it exists.

  2. Update initramfs:

update-initramfs -c -k all

From https://support.system76.com/articles/enable-hibernation/

Add Extension:

To add Hibernate and Hybrid Sleep to the power menu, we'll need to add this GNOME-Shell extension: Hibernate Status Button

Add .pkla file:

NOTE: Pop!OS and Ubuntu require a file at /etc/polkit-1/localauthority/10-vendor.d/com.ubuntu.desktop.pkla

To create this file, run:

sudo nano /etc/polkit-1/localauthority/10-vendor.d/com.ubuntu.pkla

Then copy these contents into the newly created file:

[Enable hibernate in upower]
Identity=unix-user:*
Action=org.freedesktop.upower.hibernate
ResultActive=yes

[Enable hibernate in 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

Save (ctrl+s) and close the file (ctrl+x).

On your next boot, you should now have an Hibernate option in the top-right, drop-down, Power Off / Logout Options menu. The Hibernate option is located alongside the existing Suspend and Power Off options.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment