434

In Ubuntu 12.04 and newer, hibernation has been disabled by default in policykit. How can I enable this back?

Pandya
  • 35,771
  • 44
  • 128
  • 188
Dima
  • 9,857
  • 11
    Why did they disable it in the first place? Does it have anything to do with losing audio? – Ali Oct 15 '13 at 16:01
  • 2
    for 13.10 see http://askubuntu.com/questions/361734/hibernation-is-still-missing-from-menu-in-13-10-after-enabling-via-polkit-how-t – rogerdpack Jan 06 '14 at 14:54
  • 4
    To answer Ali's question, it was disabled because many people had problems hibernating due to problems with their swap partitions. However, in Ubuntu 14.10 Utopic Unicorn, there are plans to get hibernation working for good, with a button and everything. – John Scott Jun 01 '14 at 19:29
  • 1
    For 15.04, you may need this question http://askubuntu.com/q/614662/178596 – Wilf May 04 '15 at 09:53
  • Hibernate might not work when btrfs partition is used. See here http://askubuntu.com/questions/768136/how-can-i-hibernate-on-ubuntu-16-04 – Anwar Sep 11 '16 at 08:31
  • for 18.04, see https://askubuntu.com/a/1064114/921494 – Yossarian42 Jul 25 '19 at 03:35

10 Answers10

340

If this answer does not work in Ubuntu 13.10, see here for an alternative answer


Hibernation was disabled on 12.04 for machines that are not certified with Ubuntu.

In order to enable hibernation you need to test whether it works correctly by running sudo pm-hibernate in a terminal. The system will try to hibernate. If you are able to start the system again then you are more or less safe to add an override.

To do so, start editing:

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

Fill it with this:

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

Or in 14.04 and later:

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

[Re-enable hibernate for multiple users by default in logind]
  Identity=unix-user:*
  Action=org.freedesktop.login1.hibernate-multiple-sessions
  ResultActive=yes

Save by pressing Ctrl-O then enter and then exit nano by pressing Ctrl-X.

Restart and hibernation is back!

Or run killall unity-panel-service to just reset the menu.

Some users will then need to run sudo update-grub to get the hibernate option to be available in the power menu. Some users may also have to at least log out then log in to get it to appear in the (upper right) power menu.

K7AAY
  • 17,202
Dima
  • 9,857
  • 1
    This solution also works in GNOME shell 3.4 with the "Alternative Status Menu" extension. – Robert Wohlfarth Sep 18 '12 at 23:58
  • unity --reset is now deprecated in Ubuntu 12.10. – Samik R Nov 10 '12 at 22:29
  • I tried this in Ubuntu 12.10 but it didn't work (using gnome not unity). Any ideas? – shaneonabike Nov 29 '12 at 02:01
  • I found a solution that worked super well here: http://www.krank.se/?p=373 in order for this to appear in the menu for Gnome 3.6 – shaneonabike Dec 03 '12 at 17:51
  • Fixed the Unity part. – RolandiXor Dec 19 '12 at 14:42
  • How to undo this? – w4etwetewtwet Apr 04 '13 at 18:15
  • Didn't work for me on 12.10. Had to delete this file to start Ubuntu or it would get stuck with "Checking battery state...". – Salman Apr 24 '13 at 15:05
  • Weird. sudo pm-hibernate does absolutely nothing for me. It just prints a newline character and goes back to my bash prompt. – Ajedi32 Jun 14 '13 at 20:11
  • 1
    @cuda.geek yep, not gonna bother with the whole gui thing anymore, typing this little command is faster (even faster with alias...) :) – Aditya M P Aug 05 '13 at 07:58
  • 15
    Really? Is this the user friendlier version of changing such a simple setting? It's getting uglier every day... – Esteban Aug 15 '13 at 03:12
  • reboot is not necessary, log-out and log-in does the work. can safely say that for 13.04 – Bleeding Fingers Aug 26 '13 at 17:16
  • Enabling a setting that will cause many people grief need not be user friendly. Particularly when it's as easy as following the instructions above. People who can't use google or command line should not be able to do it. Ideally the function could be fixed so it works more consistently before it reintroduced as default – nhorning Sep 15 '13 at 09:41
  • 8
    I don't think that was Esteban's point. It shouldn't require arcane magic to enable hibernate. Think of something in the /etc/default directory where you change one line from enable_hibernate="false" to enable_hibernate="true". Think of having a system->settings dialog that just lets you turn it on with a warning "this may not work, your machine may not wake up properly." – Scott Marlowe Nov 15 '13 at 05:50
  • what's the difference between this answer and modifying the already-existent entries in /var/lib/polkit-1/localauthority/10-vendor.d/com.ubuntu.desktop.pkla to "yes"? – amc May 26 '14 at 01:13
  • 1
    For this to work on my Ubuntu 14.01 ttyl, I had to use Action value as org.freedesktop.login1.hibernate [Ref: https://bugs.launchpad.net/ubuntu/+source/lxsession/+bug/1300798] – Hamman Samuel Jul 30 '14 at 13:24
  • didn't work for mint 17 – Nikos Aug 26 '14 at 11:19
  • 1
    It doesn't work for me in *Ubuntu 15.04*, I tried the menu reset, the laptop reset, but hibernation option in the menu doesn't appear. But this one: http://askubuntu.com/a/487282/260677 does work for me, so for those, who has an issue with the original solution, please, consider trying this one too. – Mike May 14 '15 at 11:20
53

First you need to test your machine supports hibernation. Test it with the command:

 sudo pm-hibernate # if not found install with "apt install pm-utils"
 # or for newer Ubuntus above 17.04
 sudo systemctl hibernate

Ubuntu 16.04 and above

For enabling in the interface you'll need to run sudo nano /etc/polkit-1/localauthority/50-local.d/com.ubuntu.enable-hibernate.pkla and fill with:

[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.hibernate-multiple-sessions ResultActive=yes

Ubuntu 14.04 and 15.04

For enabling in the interface you'll need to run sudo nano /etc/polkit-1/localauthority.conf.d/52-enable-hibernation.conf for Ubuntu 14.04 and 15.04 and fill with:

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

[Re-enable hibernate by default for login1] Identity=unix-user:* Action=org.freedesktop.login1.hibernate;org.freedesktop.login1.hibernate-multiple-sessions ResultActive=yes

It has several stanzas as you might have multiple users (so that is doesn´t depend of multiple-users or upower as manager instead of login1)

p.s.: official documentation https://help.ubuntu.com/16.04/ubuntu-help/power-hibernate.html

morhook
  • 1,610
  • 14
  • 23
  • 1
    It worked for me on *Ubuntu 15.04*, while the original accepted answer does not. – Mike May 14 '15 at 11:24
  • @MikeB. This worked because since Ubuntu 15.04, the core Ubuntu system starts using systemd- a newer replacement for the old upstart. The last section in the above code having "logind" is for systemd based systems. Hope this sheds some light to your situation. :D – x__x Nov 07 '15 at 20:42
  • Worked for me on ubuntu 16.04. only issue was permission denied error which i solved using sudo. – Sandeep Jun 05 '16 at 16:31
  • The first step sudo pm-hibernate results in command not found. I also tried sudo apt install sudo pm-hibernate, which also isn't available. This is version Ubuntu 16.04. – L. D. James Sep 29 '16 at 18:19
  • Your answer should appear at the top of the list, even though it has fewer votes it is more meaningful to visitors using today's software. – WinEunuuchs2Unix Nov 22 '16 at 01:03
  • @L.D.James , sudo apt install pm-utils laptop-mode-tools – Mr. Pundir Jul 27 '17 at 01:14
  • I am running 18.04. sudo pm-hibernate works on cmd line. sudo systemctl hibernate does not. The menu option seems to use the latter, not the former. How can I force it to use pm-hibernate ? – Stewart Oct 13 '18 at 13:59
33

Additionally, for those who want to disable the suspend button (for various reasons), proceed analogously...

Choose any file name, but this is one is verbose/convention:

sudoedit /etc/polkit-1/localauthority/50-local.d/com.ubuntu.disable-suspend.pkla

Fill it with this:

[Disable suspend by default]
Identity=unix-user:*
Action=org.freedesktop.upower.suspend
ResultActive=no

Ctrl+O, Enter, Ctrl+X

No need to restart, it should be gone as soon as you go into the shutdown menu.

Radu Rădeanu
  • 169,590
nacs
  • 367
14

One more thing:

When you want to add the hibernation option to XFCE's panel, you have to right-click your name (topright) and select properties.

After that a screen pops up:

enter image description here

Make sure, you check Hibernate like I did.

mreq
  • 4,812
14

First, I do recommend that you test if your laptop supports hibernation, because the reason why hibernation is disabled by default is because it sometimes has fatal results on some machines. Test your machine by

Ctrl+Alt+T and then sudo pm-hibernate

Your machine should hibernate. Wake your machine up after hibernation and observe if it misbehaves or if it acts normally. If you experience any abnormality after the hibernation, then I advise you don't continue with the following procedure. However, if it works just fine, continue to activate hibernation by

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

Edit the opened file and add this lines:

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

After this, restart your machine, and upon login, you should see a hibernation option on the top right settings corner.

Braiam
  • 67,791
  • 32
  • 179
  • 269
kelvinelove
  • 1,617
  • 1
  • 16
  • 26
6

Enabling hibernation with a script

I have translated above answers to bash scripts. This makes installation on multiple machines less tiresome.

Script enable-hibernate:

#!/usr/bin/env bash
# https://askubuntu.com/a/94963/164341
cat << '_EOF_' |sudo tee /etc/polkit-1/localauthority/50-local.d/com.ubuntu.enable-hibernate.pkla
[Enable Hibernate]
Identity=unix-user:*
Action=org.freedesktop.upower.hibernate
ResultActive=yes
_EOF_
clear
echo
echo 'Hibernate enabled.'
echo

Script disable-suspend:

#!/usr/bin/env bash
# https://askubuntu.com/a/154821/164341
cat << '_EOF_' |sudo tee /etc/polkit-1/localauthority/50-local.d/com.ubuntu.disable-suspend.pkla
[Disable suspend by default]
Identity=unix-user:*
Action=org.freedesktop.upower.suspend
ResultActive=no
_EOF_
clear
echo
echo 'Suspend disabled.'
echo

Note: Do not forget to chmod +x both scripts to make them executable.

Serge Stroobandt
  • 5,268
  • 1
  • 48
  • 59
5

If the response with /etc/polkit-1/localauthority/50-local.d/com.ubuntu.enable-hibernate.pkla does not work as in my case, don't forget to delete the file by:

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

And try to use TuxOnIce.


First ensure you have enough of swap. It should be the same size or bigger as the amount of your RAM. Use command

free

rule Swap > Mem. If this is not the case, enlarge your swap size. Then install TuxOnIce by

sudo add-apt-repository ppa:tuxonice/ppa
sudo apt-get update
sudo apt-get install tuxonice-userui linux-generic-tuxonice linux-headers-generic-tuxonice

Then you can try to do a hibernate test run by:

sudo pm-hibernate

Do not forget to save your work before you do it.

If all went fine, your computer will switch off. After switching it on, you will get your desktop in the state you left in it before hibernation.

Dee
  • 1,976
4

A simple command which does the exact same thing as the accepted answer except non-interactively:

cat <<EOF | sudo tee /etc/polkit-1/localauthority/50-local.d/com.ubuntu.enable-hibernate.pkla
[Re-enable hibernate by default]
Identity=unix-user:*
Action=org.freedesktop.upower.hibernate
ResultActive=yes
EOF
kiri
  • 28,246
  • 16
  • 81
  • 118
3

In 12.04, I successfully enabled hibernate option in the indicator menu to hibernate. But Still I wasn't able to successfully resume from hibernate. I did follow these steps to fix this problem:

Enable Hibernate in 12.04

To enable Hibernate, I followed this answer from Dima.

After enabling hibernate, I could hibernate. But the problem is, I can't successfully resume from hibernate. Any time I start my PC from hibernate, it boots like a normal boot. So, I had to do these things to be able to resume from hibernate.

The fixes to be able to resume from hibernate

There is two way to fix this.

1. Editing the /etc/initramfs-tools/conf.d/resume file

  1. First get the UUID of the swap partition.

     sudo blkid | grep swap
    

    This will output a line similar to this:

    /dev/sda12: UUID="a14f3380-810e-49a7-b42e-72169e66c432" TYPE="swap"
    

    The actually line will not match with this. Copy the value of UUID in between "..." double quote.

  2. Open the resume file

    gksudo gedit /etc/initramfs-tools/conf.d/resume
    

    And in that file, add a line like this

    RESUME=UUID=a14f3380-810e-49a7-b42e-72169e66c432
    

    Don't forget to replace the actual UUID value you get from step 1. Save the file and exit gedit

  3. Then in terminal, execute this command

    sudo update-initramfs -u
    

You will now be able to resume from hibernation

2. Editing the /etc/default/grub file.

  1. Open a terminal and execute the below command to open it

    gksudo gedit /etc/default/grub

  2. There will be a line like GRUB_CMDLINE_LINUX_DEFAULT="quiet splash" . Edit the line to insert RESUME=UUID=<your-uuid-value-here> after the word splash.

    For example in my case, the line looks like this after editing

     GRUB_CMDLINE_LINUX_DEFAULT="quiet splash resume=UUID=a14f3380-810e-49a7-b42e-72169e66c432" 
    

    Make sure, you used your UUID value you get from sudo blkid | grep swap command.

  3. Then do this command

     sudo update-grub
    

This also enable you to successfully get resumed from hibernate.


Tested on two Ubuntu installation, both worked

Anwar
  • 76,649
  • file this as a seperate question & answer. As people may search for "fail to resume from suspend" and not find your excellent write up. – Dima Oct 04 '12 at 08:44
  • After your suggestion, I created this self-answered question http://askubuntu.com/questions/196364/i-have-enabled-hibernate-but-it-isnt-working-what-can-i-do – Anwar Sep 11 '16 at 08:19
  • this worked for me (option #2) in Ubuntu 18.04 also, Thanks !! – Prashant Adlinge Feb 20 '21 at 16:34
1

I have Ubuntu Gnome 17.04 amd64 on my notebook. I did the following to enable hibernation:

$ sudo apt-get install hibernate (source)

This installed also libx86-1uswsuspvbetool

Then I could successfully hibernate with sudo systemctl hibernate. There is no pm-hibernate executable in my path.

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

Inserted: (source)

[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

Installed https://extensions.gnome.org/extension/755/hibernate-status-button/

ominug
  • 191