#StackBounty: #18.04 #hibernate #lid Can you execute a custom shell command on power button or lid close?

Bounty: 50

I am trying to make hibernate work on my Ubuntu 18.04.

I followed all the tutorials around (mostly from the answers here: How can I hibernate on Ubuntu 16.04?)

So far, executing pm-hibernate on the shell works well and systemctl hibernate does not.

I am able to recover correctly from pm-hibernate, with the only problem that the screen is not locked, and I am logged in directly afterwards. I was able to fix that with adding an alias that manually locks, and executes pm-hibernate afterwards (How do I lock the screen after resuming from hibernation?)

However systemctl hibernate does not work and if if come back after executing it on the command line, is the same as I have done a force power off.

In the power settings menu, I have selected ‘hibernate’, but it seems that this executes the same thing as systemctl hibernate, because after I press the power off button it is the same as if I have powered off.

I have tried adding a resume parameter in the grub configuration

GRUB_CMDLINE_LINUX_DEFAULT="quiet splash resume=/dev/nvme0n1p2"

where /dev/nvme0n1p2 is my swap partition, but without any help.

So now my idea is to make the power off button execute my hibernate alias that locks and executes pm-hibernate? Also possibly on lid close?

At the moment I have to write hibernate in the terminal to go to hibernation.

Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.