I have added an alias into ~/.bashrc
file
alias hibernate='sudo echo "Hibernating..."; gnome-screensaver-command -l; sudo pm-hibernate;'
So that it locks the screen before hibernating.
14.04 and beyond
Mitch points out in his answer for 14.04 and 16.04 that you should check 10-vendor.d/com.ubuntu.desktop.pkla
before modifying anything. Also check that you have Secure Boot disabled and if that brings the menu option back.
Re-enabling the hibernation option in the menu
To re-enable the hibernation option in the menu, your /etc/polkit-1/localauthority/50-local.d/com.ubuntu.enable-hibernate.pkla
should be modified to look like the following in saucy (13.10):
[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
ResultActive=yes
Then reboot or run killall indicator-session-service
in your session and you should have your hibernate functionality/menu option back. Create the file if it doesn't exist already.
Investigation from bug report
Citation from Jeffery To's post on Launchpad Bug Report #1232814:
For Saucy, indicator-session was updated to use logind
(org.freedesktop.login1) instead of upower.
If you check
/var/lib/polkit-1/localauthority/10-vendor.d/com.ubuntu.desktop.pkla,
you'll see that hibernate is disabled by default in both upower and
logind.
So the first step to re-enable the Hibernate option is to edit
/etc/polkit-1/localauthority/50-local.d/com.ubuntu.enable-hibernate.pkla
to something like:
[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
ResultActive=yes
After rebooting, the login screen session menu should have a Hibernate
option.
[...]
All thanks and credit go to Jeffery!
Why was hibernation disabled?
There exists a bug report on launchpad that suggests disabling suspend/hibernate instead of tracking which hardware "certifies" for which power modes. It's claimed to be a more scalable approach.
Another thing to mention is that using UEFI Secure Boot and hibernation appears to be possible but may be a risk to circumvent the former. (1, 2) As a reminder, when you use hibernation you store everything in RAM to disk without encryption, this includes passwords for encrypted filesystems and containers.
At some point with 16.04 I had to disable Secure Boot to be able to hibernate my laptops. In my case I used uswsusp and testing with s2disk returned the message below. This may give you a hint that your issue, why you can't hibernate although everything else is in place, is related to Secure Boot:
s2disk: Could not open the snapshot device. Reason: Operation not permitted
However, please understand that this is not a place to complain and please be nice.
Related questions
Best Answer
Update for 16.04 (September, 2016)
Hibernate might not work not even it is successfully enabled if you have
btrfs
partitions. As revealed in a question hereIt was also revealed that enabling UEFI can cause problem with hibernation too.
Enable the Hibernate option
To enable Hibernate, I followed this answer from Dima.
After enabling hibernate you will have an option to hibernate in the indicator session menu at top panel. But, though you can hibernate you may not resume from hibernate. You will just be given a new session. The fixes are below.
The fixes to be able to resume from hibernate (12.04)
Several readers confirmed this working on 14.04 too
There is two way to fix this.
1. Editing the
/etc/initramfs-tools/conf.d/resume
fileFirst get the UUID of the swap partition.
This will output a line similar to this:
The actually line will not match with this. Copy the value of UUID in between
"..."
double quote.Open the resume file
And in that file, add a line like this
Don't forget to replace the actual UUID value you get from step 1. Save the file and exit gedit
Then in terminal, execute this command
You will now be able to resume from hibernation
2. Editing the
/etc/default/grub
file.Open a terminal and execute the below command to open it
There will be a line like
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"
. Edit the line to insertRESUME=UUID=<your-uuid-value-here>
after the wordsplash
.For example in my case, the line looks like this after editing
Make sure, you used your UUID value you get from
sudo blkid | grep swap
command.Then do this command
This also enable you to successfully get resumed from hibernate.
Tested on two Ubuntu installation, both worked