118

How should I successfully hibernate Ubuntu 16.04?

I've tried almost every solution on the web but non of them was actually helpful. I found my problem almost completely similar to this one

Mahyar
  • 1,281

11 Answers11

81

Hibernation using systemctl and getting it working in tough cases

For me, pm-hibernate always fails. After some tweaks, I was able to hibernate using the interface of systemd (init system in 16.04 and above). I also managed to get it working on 17.04 with a swap file. This case study may be useful for others with problems.

First try:

sudo systemctl hibernate

If that fails, begin troubleshooting: in the hibernate state (HTD or ACPI S4) the machine state is written to disk so that no power is needed to preserve it. The state is written either to a swap partition or to a swap file. Note: if using Btrfs DO NOT attempt to use a swap file as this may cause filesystem corruption

Your swap partition or swap file may need to be the same size as RAM to allow hibernation, but there is a good chance you will be able to hibernate if it is at least 2/5 the size of RAM, according to the Arch wiki page, so try other steps first before increasing swap size.

If your problem is that you get a clean boot instead of the expected resume, at a minimum you most likely need to set a boot parameter to find the disk image

Find your swap partition:

grep swap /etc/fstab

for me this returns (partial output)

# swap was on /dev/mmcblk0p3 during installation

where /dev/mmcblk0p3 is the partition to specify

Add a boot parameter:

sudoedit /etc/default/grub

To the line starting GRUB_CMDLINE_LINUX_DEFAULT add resume=/dev/YourSwapPartition to the section in quotes (replace with the the partition you identified earlier). Using my example:

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

Any time you change this file, you must run sudo update-grub or the changes will have no effect.

Now you need to reboot. Then you can try to hibernate, by issuing the command:

sudo systemctl hibernate

To resume, press the power button and the system will boot.

If you still have problems, start debugging.

I include my case below as an example, but detailed information on debugging S states can be found in this blog and also this one.

Set some more boot parameters to capture more information. Remove quiet and splash and add initcall_debug and no_console_suspend which will cause init system calls to be printed to the console so you can watch what is going wrong. I set this:

GRUB_CMDLINE_LINUX_DEFAULT="resume=/dev/mmcblk0p3 no_console_suspend initcall_debug"

Which helped me see what was going wrong on resume from hibernation. You can also try using dmesg.

In my case, after resume I lost WiFi, and the kernel clearly was upset as most commands (for example reading anything from /sys, reloading modules or any systemctl command) would not work - the process would appear to start and just hang (all this would be returned to normal after reboot of course). Watching the system very slowly shut down and reading all the debug messages, I noticed that there were a lot of problems with "brcm", so I guessed my Broadcom wireless driver module was to blame. Sure enough I adjusted my hibernation procedure to unload the module first:

sudo modprobe -r brcmfmac
sudo systemctl hibernate

on resume I reinsert the module

sudo modprobe brcmfmac

And everything worked perfectly. I also have to blacklist the btsdio module which seems to be incompatible with brcmfmac


Update: Hibernation using a swap file on 17.04.

Once again with help from the Arch wiki page and some additional tinkering, I managed to get hibernation to work on 17.04 with a swap file. This required an additional boot parameter, resume_offset=n where n is the first number under physical_offset in the output of sudo filefrag -v /swapfile:

$ sudo filefrag -v /swapfile
Filesystem type is: ef53
File size of /swapfile is 1425873920 (348114 blocks of 4096 bytes)
 ext:     logical_offset:        physical_offset: length:   expected: flags:
   0:        0..   32767:      34816..     67583:  32768:            
   1:    32768..   63487:      67584..     98303:  30720:            
   .... 

Therefore, the additional boot parameter in my case is resume_offset=34816. You still need to set a boot parameter for the partition to resume from. This will be the root partition (or whatever partition your swap file is located on) My parameters are now:

GRUB_CMDLINE_LINUX_DEFAULT="no_console_suspend initcall_debug resume=/dev/mmcblk1p2 resume_offset=34816"

Where /dev/mmcblk1p2 is my root partition (yours is more likely to be something like /dev/sda2).

During resume I saw the image loading successfully, but in my case (just an example - YMMVAPD) then some more drivers (i2c_designware) threw some errors and I got a complete system freeze on resume. Hibernation works if I unload those modules in addition to brcmfmac, but the system quickly becomes unusable without those modules. I therefore made a sort of script to unload the buggy modules and immediately reinsert them on resume:

# remove buggy modules
modprobe -r brcmfmac i2c_designware_platform i2c_designware_core &&
# hibernate
echo disk > /sys/power/state
# reinsert
modprobe i2c_designware_core i2c_designware_platform brcmfmac

When I want to hibernate, I run sudo bash script. This works great.


TL;DR

Use systemd, set a boot parameter for resume from swap, identify buggy drivers and unload them before initiating hibernation. If the system can't work for long without those modules or you need to unload several, it may be easier to use a simple script to initiate hibernation.

Zanna
  • 70,465
  • Where is that information from, that 2/5 of the RAM size might be enough, and under which circumstances? I have a user option in Gnome, "Hibernate" and it does seem to hibernate, but on waking up, it doesn't work properly. I have a swap partition of 8GB and 32GB RAM. That's not 2/5, but before creating a 32GB swap file (or partition) it'd be nice to know. – cslotty Dec 13 '16 at 15:11
  • @cslotty I got that information from the Arch wiki IIRC - let me know if you do manage it please – Zanna Dec 13 '16 at 15:52
  • Thanks, @Zanna. I found out that it's actually not hibernate, what I want, but suspend (S3/STR) - sry. – cslotty Dec 13 '16 at 16:36
  • @cslotty no worries at all. In that case, swap is not your problem as it's not related. – Zanna Dec 13 '16 at 16:53
  • 1
    Thanks, I needed a synthesis of this answer as well as the tip on disabling SecureBoot to make it work in the end. – oligofren Dec 18 '17 at 12:55
  • @oligofren thanks for sharing that! I can't run Ubuntu at all with Secure Boot on, so that wouldn't be something I could catch. – Zanna Dec 18 '17 at 13:14
  • With 18.04, the problem for me was that the installer has created a much too small swap partition in an encrypted volume. Enlarging it was the (troublesome) way to go, then hibernation worked out of the box, including UI buttons (in LXQt). – Murphy Jan 04 '19 at 08:01
  • 1
    In my case, on Dell Latitude 5501 - Ubuntu 20.04, I need to set the swap by it's UUID to make the hibernate works. Then the resume option in grub also has to be UUID like resume=UUID=your-swap-uuid-here. – Oki Erie Rinaldi Jul 10 '20 at 11:26
  • help with offset – Oleksandr IY Aug 13 '20 at 16:04
67

You can use

sudo pm-hibernate 

to check if hibernate works on your system (this will hibernate your computer).

If it does not work , check if your swap size is at least as large as your RAM.

To add the option to the settings menu, you can create a configuration file. Open a terminal window and run this command:

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

It opens nano with an empty file. Copy the lines below and paste them into the nano window.

[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

Then save the changes and close nano and reboot the system to make Hibernate available appear on "Power options".

Reference: How do I hibernate my computer? in the official documentation for Ubuntu 16.04.

Hope it works. This worked for me after trying all other options.

John D
  • 103
  • 5
NirajW
  • 781
  • We need a reboot after editing the file to make Hibernate available appear on "Power options". – Jus12 Jan 15 '17 at 07:30
  • 23
    'sudo pm-hibernate' killed my system immediately without warning. You should tell people that's what's going to happen. – Yair Daon Jun 09 '17 at 01:27
  • 1
    best answer . This also working on 17.4 and 17.10 as well . – Saurabh Bhandari Sep 23 '17 at 11:40
  • 1
    This answer combined with the one telling to add "resume=" to the GRUB_CMDLINE_LINUX_DEFAULT did solve it for me - thx! – Christoph Nov 03 '17 at 15:21
  • I have 17GB in my swap partition and 16GB of RAM, why is it not working? It seems to be hibernating because it takes forever to turn off the computer whereas if I do "shutdown" it turns off almost immediately. But when I turn my computer back on, everything's closed and I have to start over again. That's not hibernating at all. Why can't it be as simple as in Windows? I'd like some help if anyone has ideas about how I can get it to properly hibernate. – user1271772 Apr 03 '18 at 06:38
  • In my Ubuntu 16.04 no reboot was needed to make hibernate appear on Power options. – loved.by.Jesus Nov 27 '19 at 22:44
21

I think, how to enable hibernate for 16.04 answer is known to all as described in the Ubuntu Wiki (See below if you need the steps). But The things that need checking isn't thorough I think. At least, that's what I found.

Things to check

From my own tests, I've at least found one extra check that you should perform. I haven't found about it anywhere in the Internet.

Here are some checkings -

  1. Check that you're not using any btrfs partitions. Yes. From my test, I found that if you have btrfs partitions, hibernate will not work. Removing or changing the partition type to ext4 didn't help me. I needed to remove the btrfs-tools package.

    sudo apt-get purge btrfs-tools
    

    You might want to check other new partition types which are not well tested. Without removing package, blacklisting the driver might also work, but I haven't tested that.

  2. Also you need to check that you have a swap partition large enough to hold the content of RAM. If your RAM is 4 GB, swap should be at least 4 GB large ( You should allocate few more MB to be safe).

Steps to enable hibernate

It involves these steps

  1. Create a file as root in /etc/polkit-1/localauthority/50-local.d/enable-hibernate.pkla

    sudo -i nano /etc/polkit-1/localauthority/50-local.d/enable-hibernate.pkla
    
  2. Put these contents on that file

    [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
    
  3. Save the file by pressing Ctrl-O. Exit with Ctrl-X

  4. Restart the polkitd daemon

    sudo systemctl restart polkitd.service
    

It should enable hibernate.

Anwar
  • 76,649
  • 2
    Thanks, Anwar. I filed bug #1619846 and referred you your answer above. Any chance you could propose more exact changes/additions to that page in the official documentation? – Gunnar Hjalmarsson Sep 03 '16 at 04:57
  • 1
    @GunnarHjalmarsson I'd propose this caveat. But, I'll need more testers verifying this. Will let you know later – Anwar Sep 03 '16 at 05:54
  • Ok, let's talk more then. – Gunnar Hjalmarsson Sep 03 '16 at 06:00
  • I installed on a btrfs partition and purged btrfs-tools according to your instructions. Still can't hibernate. – Oxwivi Sep 04 '16 at 09:04
  • @Oxwivi what other types of partitions were you mounting with fstab excluding ext3/4? – Anwar Sep 04 '16 at 09:34
  • 1
    On disk there's only vfat for UEFI, and btrfs and swap. I'm actually suspecting it's due to the hardware (AMD laptop). I'm going to test this on another system with btrfs and get back at you. – Oxwivi Sep 04 '16 at 11:03
  • @Oxwivi btrfs there!! you should try in same system without btrfs i think. If you can, make some room for another partition. install an Ubuntu there. enable hibernation. In /etc/fstab don't add any lines to mount the btrfs. Since it's a new installation, ubuntu won't recognize them any way (because, by default ubuntu doesn't know btrfs). now check if it works – Anwar Sep 04 '16 at 18:28
  • Hibernation's worked on the other btrfs system I mentioned. And I also found that UEFI needs to be disabled for hibernation in Ubuntu. Congrats, you won the bounty! – Oxwivi Sep 04 '16 at 20:25
  • @Oxwivi hibernation worked with btrfs mounting of with disabled btrfs? – Anwar Sep 05 '16 at 03:42
  • I only purged btrfs-tools and changed nothing else. – Oxwivi Sep 05 '16 at 08:58
  • @Gunnar Here Oxwivi verifying same thing. btrfs interrupted hibernation – Anwar Sep 05 '16 at 19:01
  • note that on 18.10 btrfs is not a problem. – ukos Feb 27 '19 at 11:53
8

Trying to put the system into hibernate (deep sleep where RAM is written to disk), generated the following error

$ sudo systemctl hibernate
Failed to hibernate system via logind: Sleep verb not supported

The following steps resolve the issue (Tested on Thinkpad X1 Carbon 7th Gen, Ubuntu 19.10). Most of them are borrowed from here.

  1. Turn off Secure Boot in BIOS.
  2. Set "Sleep State" to Linux in BIOS. This options was originally named "Modern Standby" in my BIOS and I had to turn if off, but after a BIOS name the name was changed to "Sleep State".
  3. Create a swap file equal or bigger than RAM. Several steps are involved here which are as follows.

    a. Turn off swap.

    $  sudo swapoff -a
    

    b. Create a file bigger or equal to the RAM. Mine is 16GB, so:

    $ sudo dd if=/dev/zero of=/swapfile bs=1G count=16
    
    16+0 records in
    16+0 records out
    17179869184 bytes (17 GB, 16 GiB) copied, 19.3685 s, 887 MB/s
    

    c. Set the right permissions for the file:

    $ sudo chmod 600 /swapfile
    

    d. Make the file as swap:

    $ sudo mkswap /swapfile
    
    Setting up swapspace version 1, size = 16 GiB (17179865088 bytes)
    no label, UUID=3b2e6f0c-ce12-4a84-9044-d99bfba059ea
    

    e. Turn on swap and check if it is set properly:

    $ sudo swapon /swapfile
    $ cat /proc/swaps
    
    Filename                Type        Size    Used    Priority
    /swapfile                               file        16777212    0   -2
    

    f. In order to make the swap be loaded after reboot, we have to add it to /etc/fstab. Thus run the following command to open the file:

    $ sudo gedit /etc/fstab
    

    And update it by adding the last line like below. Note that I have also commented my original swap as I don't need it.

    /dev/mapper/vgubuntu-root /               ext4    errors=remount-ro 0       1
    # /boot was on /dev/nvme0n1p2 during installation
    UUID=d265e7c4-1a4f-49c4-af29-fea2543490d7 /boot           ext4    defaults        0       2
    # /boot/efi was on /dev/nvme0n1p1 during installation
    UUID=0004-FB5F  /boot/efi       vfat    umask=0077      0       1
    #/dev/mapper/vgubuntu-swap_1 none            swap    sw              0       0
    /swapfile       none    swap    sw      0       0
    

    g. Do a reboot and run this command to see if the swap shows up:

    cat /proc/swaps
    
    Filename                Type        Size    Used    Priority
    /swapfile                               file        16777212    0   -2
    
  4. Now, it's time to update the grub. a. Run this command to open grub:

    $ sudoedit /etc/default/grub
    

    b. Find where root is mounted by running the following command.

    $ mount | grep " / "
    
    /dev/mapper/vgubuntu-root on / type ext4 (rw,relatime,errors=remount-ro)
    

    c. So mind is mounted on /dev/mapper/vgubuntu-root. Find the UUID of this location by running:

    $ sudo blkid
    /dev/mapper/nvme0n1p3_crypt: UUID="AZrE57-dlNc-BiUr-RrTF-SdT2-luVK-vrliNq" TYPE="LVM2_member"
    /dev/mapper/vgubuntu-root: UUID="2331fe68-3e7a-4937-9cfa-74fc7a4b79f6" TYPE="ext4"
    /dev/nvme0n1p1: UUID="0004-FB5F" TYPE="vfat" PARTLABEL="EFI System Partition" PARTUUID="09813156-6b7a-4fc2-b644-a8c6b7d40abf"
    /dev/nvme0n1p2: UUID="d265e7c4-1a4f-49c4-af29-fea2543490d7" TYPE="ext4" PARTUUID="64f5da2f-71d3-4f02-9b1e-3e12d7f6c445"
    /dev/nvme0n1p3: UUID="201acba5-ff20-46ee-9000-34efefef3fbe" TYPE="crypto_LUKS" PARTUUID="16858e70-eb08-4de8-b944-50689cad9d9f"
    /dev/sda1: LABEL="ST64GB" UUID="624AB7B308FE9F38" TYPE="ntfs" PTTYPE="dos"
    /dev/mapper/vgubuntu-swap_1: UUID="af3b29a2-ba6b-44de-89dd-072f4233aaf9" TYPE="swap"
    
    

    The UUID in this case is 2331fe68-3e7a-4937-9cfa-74fc7a4b79f6. Keep this UUID. d. Next, we need to find the offset of the swap file. Run this command:

    $ sudo filefrag -v /swapfile
    
    Filesystem type is: ef53
    File size of /swapfile is 17179869184 (4194304 blocks of 4096 bytes)
    ext:     logical_offset:        physical_offset: length:   expected: flags:
      0:        0..   32767:     835584..    868351:  32768:            
      1:    32768..   49151:     868352..    884735:  16384:            
      2:    49152..   81919:     886784..    919551:  32768:  
      ...
    

    We look for the pysical_offset of the first block. In the above case, it will is 835584. Keep this number too. e. We need to update the grub now. Run the following command:

    $ sudoedit /etc/default/grub
    

    Update with the following content. We update GRUB_CMDLINE_LINUX_DEFAULT and add GRUB_RECORDFAIL_TIMEOUT=0.

    # If you change this file, run 'update-grub' afterwards to update
    # /boot/grub/grub.cfg.
    # For full documentation of the options in this file, see:
    #   info -f grub -n 'Simple configuration'
    
    GRUB_DEFAULT=0
    GRUB_TIMEOUT_STYLE=hidden
    GRUB_TIMEOUT=0
    GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian`
    GRUB_CMDLINE_LINUX_DEFAULT="quiet splash resume=UUID=2331fe68-3e7a-4937-9cfa-74fc7a4b79f6 resume_offset=835584"
    GRUB_CMDLINE_LINUX=""
    
    # Avoiding grub to show up in boot when resuming from hibernation
    GRUB_RECORDFAIL_TIMEOUT=0
    

    f. Once the grub file is updated, run this command:

    $ sudo update-grub
    

That should be it. Now you can put the system into hibernation by running

$ sudo systemctl hibernate
SaTa
  • 996
8

Secure Boot

(I asked a similar question asking for a focus on systemd-based replies, sharing my solution here for people following this question)

This solution comes from Fedora topics (they made the switch to systemd a while ago so there's more material there).

In my case (fresh 16.04.1 install on a machine that always supported hibernation), calling the obsolete sudo pm-hibernate did not seem to do anything, and the up to date systemd approach, systemctl hibernate, would return:

Failed to hibernate system via logind: Sleep verb not supported

It turns out that secure boot was the culprit: installing 16.04 you are asked what you want to do with it (which is a new thing as far as I can recall) and I kept it ON without giving it much thought.

On my machine with secure boot ON, cat /sys/power/disk answered:

 [disabled]

After reboot and disabling secure boot in the BIOS settings (these are machine-specific, but usually pretty straightforward) I tried a cat /sys/power/disk and got:

 [platform] shutdown reboot suspend 

which looks better. And indeed calling systemctl hibernate results in a successful hibernate/thaw sequence.

Moreover, after that I could see hibernation available as an option in various places of the graphical interface, without the need of any polkit hack. So it seems that systemd was actually guessing from /sys/power/disk that the system was not able to hibernate.

Marc
  • 1,252
  • I did exactly what you have explained here. But after I execute "systemctl hibernate" command the screen got black for 3 seconds then the desktop went back with all my opened programs just like before I executed the command. When I executed the command "cat /sys/power/disk"... it shown me this text: "[platform] shutdown reboot suspend test_resume" which it's similar to the result when you executed the same from your side but the last text: "test_resume". Do you have an idea what I could try to solve my problem ? – foxhard May 06 '18 at 16:58
  • Not too sure, looks like hibernation does not work out of the box on your hardware, which is why it is disabled by default as others pointed out. You might want to start a separate question about your specific issue. – Marc May 14 '18 at 09:04
  • Only half-working for me. Hibernates but instead of waking up from hibernation, goes to normal boot, then gets stuck forever until a hard physical shutdown. – matanox Jul 01 '18 at 20:11
6

This instruction worked for my Ubuntu 18.04 installation.

  1. sudo apt install hibernate It will install hibernate and other dependencies which are needed to hibernate
  2. grep swap /etc/fstab (fing UUID)
  3. sudoedit /etc/default/grub At the line GRUB_CMDLINE_LINUX_DEFAULT="quiet splash" add UUID of swap. The line looks like this GRUB_CMDLINE_LINUX_DEFAULT="quiet splash resume=UUID of swap"
  4. sudo update-grub
  5. Restart, and after restart sudo systemctl hibernate. If everything works ok add menu entry's.
  6. sudo gedit /etc/polkit-1/localauthority/50-local.d/com.ubuntu.enable-hibernate.pkla now paste this:
[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

copied from https://askubuntu.com/a/819891/712203

  1. Restart the computer
  2. Install https://extensions.gnome.org/extension/755/hibernate-status-button/
ukos
  • 724
  • 1
    instead of adding a fixed value to /etc/default/grub consider updating the initramfs using update-initramfs -u -k all and look for a message like The initramfs will attempt to resume from /dev/dm-0. This will automatically set the resume device. – ukos Feb 21 '19 at 12:54
  • Thank you, works perfectly on Ubuntu 18.04! Note that if it is the first time you use a gnome extension, you will need to install a browser extension and a connector. This is explained in the extension link at the top. – Karim Sonbol Mar 16 '19 at 09:08
6

For me, it works to install hibernate package, reboot and then run sudo hibernate-disk. I am sure it is possible to add it to menu, but is not worth the time for me.

Aiphee
  • 938
5

Expanding on my own comment to kelvinelove's answer, the file he suggests editing did not exist on my system (fresh Ubuntu 16.04). Instead, I did this:

  1. sudo nano /var/lib/polkit-1/localauthority/10-vendor.d/com.ubuntu.desktop.pkla

  2. Look for these sections (they are right by each other):

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

    [Disable hibernate by default in logind] Identity=unix-user:* Action=org.freedesktop.login1.hibernate;org.freedesktop.login1.handle-hibernate-key; ResultActive=no

  3. Change ResultActive=no to ResultActive=yes for both of them.

  4. Press Ctrl + O to save the file.
  5. Reboot your computer
  6. The Hibernate option is now available in your power menus.

EDIT: Gunnar pointed out that this file gets overwritten if a certain package gets updated, so depending on your intentions it is most likely not the best solution.

Source: http://www.zedt.eu/tech/linux/enable-hibernation-xubuntu-16-04/

fgblomqvist
  • 232
  • 5
  • 14
  • The file in /etc is not supposed to exists by default. It's a configuration file which you create. Editing a package owned file, as you suggest above, is bad advice, since it will be overwritten at next package update. – Gunnar Hjalmarsson Sep 02 '16 at 06:11
  • @GunnarHjalmarsson If that's the case I would argue that it should be stated that it might not exist. I expect more from a top rated Ask Ubuntu answer than a "copy/paste this command"->"type this" -style answer that lacks any kind of verification of whether you are doing the right thing (other than checking if it worked). What if someone finds that answer in a couple of years, but is afraid of trying it since the file is empty, and the instructions clearly state to add to the file, implying that it exists? Nonetheless, I appreciate the information, will add it to the answer for completion. – fgblomqvist Sep 03 '16 at 01:05
  • 1
    Fair point; I edited NirajW's answer with that clarification. It should be noted that the original source of info at this page talks about creation. – Gunnar Hjalmarsson Sep 03 '16 at 05:16
  • This is perfect you saved me brother :) – Azam Alvi Nov 03 '18 at 14:17
3

First, I do recommend that you test if your machine supports hibernation, because the reason why hibernation is disabled by default is because it sometimes has unpleasant results on some machines. Test your machine by opening the terminal (Ctrl+Alt+T) and then typing 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 doing this:

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 after logging in, you should see a hibernation option added on the power menu, on the top right settings corner.

kelvinelove
  • 1,617
  • 1
  • 16
  • 26
  • I have thinkpad -E550 and it has no problem with hibernation when my OS is ubuntu 15.1 or windows8.1 . but using ubuntu 16.04 , when i use the command "sudo pm-hibernate" , it does not completely hibernate and just the screen goes black and the machine is still on. – Mahyar May 06 '16 at 18:14
  • In my case, the command does nothing at all. The terminal goes to the newline and awaits next command i.e. previous command has been executed. But it does nothing at all – axolotl Jul 17 '16 at 18:01
  • This doesn't work for me. Ubuntu 16.04. The Hibernate option do not come up and stay disable in Settings -> Power, anything else? – Daniele Segato Aug 07 '16 at 17:02
  • Editing the already existing policy is better: http://www.zedt.eu/tech/linux/enable-hibernation-xubuntu-16-04/ – fgblomqvist Aug 24 '16 at 01:41
  • Incomplete contents in com.ubuntu.enable-hibernate.pkla. See answer posted by NirajW. – Gunnar Hjalmarsson Sep 02 '16 at 06:31
  • @fgblomqvist: No, it's not, since such edits will be overwritten at next package update. – Gunnar Hjalmarsson Sep 02 '16 at 06:54
3

There are some very good resources here to help you sort out some of the more common hibernate issues under Ubuntu.

In my case, running Ubuntu 16.10 on a Lenovo u300s, in order for hibernate to work correctly I had to do the following:

  • Create an appropriately-sized swap file (I typically set for ~1x in size, but I've heard up to 1.6x and 2x)
  • Edit /etc/default/grub to include the following line:

    GRUB_CMDLINE_LINUX_DEFAULT="splash quiet pci=nomsi RESUME=UUID=92781adb-f2a6-4f15-88fc-e1ce801291dd"
    

The RESUME refers to your specific swap file UUID. In particular, on my machine setting pci=nomsi was the key.

Best of luck!

Anwar
  • 76,649
richbl
  • 2,303
2

You have to manually enable it with a little effort. It's been disabled by default.

http://ubuntuhandbook.org/index.php/2014/04/enable-hibernate-ubuntu-14-04/

Then, if it doesn't work, it's might be a 4.4.0 kernel issue, and you might have to upgrade kernel.

Mookey
  • 4,801