Enable Hibernation with LUKS on LVM and extras.

Write tutorials here
There are more tutorials here http://community.linuxmint.com/tutorial/welcome
Forum rules
Please don't add support questions to tutorials,start your own thread in the appropriate sub-forum instead. Before you post please read this
Post Reply
User avatar
amendoza
Level 1
Level 1
Posts: 3
Joined: Thu Jan 31, 2019 4:56 pm

Enable Hibernation with LUKS on LVM and extras.

Post by amendoza »

Hello, I write this guide so that it can help anyone that is trying to achieve the same, which is enable hibernation on an encrypted install, had been looking for some time how to do it, and found out there's no easy to follow guide or, they use outdated methods, so here it is!

Preamble:

This was done in Linux Mint 19.1, Cinnamon, so have no idea if it works on other versions, tho I don't see why it shouldn't, just make sure your version is also using systemd.
The configuration is made on a full disk encryption, specifically LUKS on LVM.

AS A GOOD PRACTICE, REMEMBER TO MAKE COPIES OF ANY FILE YOU CHANGE, SO THAT YOU CAN REVERT THIS EASILY IF ANYTHING GOES WRONG.

Step 1:
Check /etc/fstab to find out where your swap partition is mounted on boot:

sudo cat /etc/fstab

In my case, it was on:

/dev/mapper/mint--vg-swap_1 none swap sw 0 0

So we will use the part that says: /dev/mapper/mint--vg-swap_1

2.- Edit the grub so that it enables hibernating to that swap partition,

open /etc/default/grub

sudo vim /etc/default/grub

And ADD the value we got from step one, to the line that reads: GRUB_CMDLINE_LINUX_DEFAULT=

In my case, that line looks like this after the change:

GRUB_CMDLINE_LINUX_DEFAULT="quiet splash resume=dev/mapper/mint--vg-swap_1"

After editing and saving the file, update grub:

sudo grub-update

Wait for it to finish, and restart the machine.
(Optional) After you come back, check that hibernation is properly working now:

systemctl hibernate

3.- Add the hibernation option to Mint's power menu:
Create/open the following file:

sudo vim /etc/polkit-1/localauthority/50-local.d/com.ubuntu.enable-hibernate.pkla

And add this content to it, and save it:

[Re-enable hibernate by default in upower]
Identity=unix-user:*
Action=org.freedesktop.upower.hibernate
ResultActive=yes

[Re-enable hibernate by default 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


If Everything went nicely, now you should have the new options in the power menu, and power settings, also you can enable now a fully functional hybrid-sleep.

As an extra step, in my case I'd like my laptop to hibernate after 2 hours into sleep, so if you want this you need to do this extra steps:

1.- Create the file /etc/systemd/sleep.conf

sudo vim /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]

HibernateDelaySec=7200


2.- Modify logind.conf so that it goes to suspend-then-hibernate mode instead of normal suspend.

sudo vim /etc/systemd/logind.conf

And modify this two lines for sleep key and closing the lid actions if that's how you want it:

HandleSuspendKey=suspend-then-hibernate
HandleLidSwitch=suspend-then-hibernate


3.- Lastly, disable cinnamon-settings from overriding dlogin.conf, just remember that whatever you change in dlogin.conf will override whatever you configure in power settings:

dconf write /org/cinnamon/settings-daemon/plugins/power/inhibit-lid-switch false

4.- Reboot, and check that everything is working as intended.

Hope it works for you guys, it was a game changer for my laptops battery to be able to have it encrypted, and with working hibernation and suspend-then-hibernate mode :)

Please let me know if you have further questions, and also if you make it work with some other mint version so that I can update it accordingly. Be safe and have fun!
User avatar
LMDE2Fan1
Level 1
Level 1
Posts: 4
Joined: Fri Nov 17, 2017 6:18 pm
Location: US

Re: Enable Hibernation with LUKS on LVM and extras.

Post by LMDE2Fan1 »

I'm on Linux Mint 19.2 with LUKS, LVM and swap partition. This works great. I just had to add nouveau.modeset=0 to my Grub kernel command line. Otherwise the nouveau driver will cause a system freeze when doing a shutdown or restart after resuming from hibernate or suspend.

Here's what my Grub kernel command line is now:
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash resume=/dev/mapper/mint--vg-swap_1 nouveau.modeset=0"

Thanks for the awesome post. There are hundreds of posts regarding how to get hibernate and suspend to work since after 17.10 (and even before with 16.04 or earlier). Including hundreds more asking for help with system freezes on startup and/or shutdown or restart after getting hibernate and resume to work.

Hopefully all this will help many others too. At this point not many distributions even have the basic suspend working properly when released. Many freeze up when trying to resume on brand new / clean installs.

:D
Post Reply

Return to “Tutorials”