Ubuntu 18.04 Hibernate and Suspend Fix

This tutorial assumes a limited familiarity with using Linux already. Most of this will be performed in a terminal emulator window. I recommend you maximize the window size and open two tabs or terminal windows for this. With one we will query the system, and the other we will use to edit files.

The portions of text in code blocks below are what you type or paste into either the commandline queries or the editor. The simplest way to handle this is using mouse-paste feature on Linux. Highlight the text you need by dragging your mouse across it; this puts it into the mouse buffer. At the appropriate place, point your mouse and click the middle mouse button to paste it into the terminal window (or anywhere else you need to use it).

If you don’t understand the use of ‘sudo’ in Ubuntu Linux, you’ll need to look that up. However, the instructions here should be simple enough that even a complete newbie can get it done.

Part 1

When you issue the command to hibernate, the system takes a snapshot of what’s in your active system RAM and packs into a file. This file is saved to your system swap. When you reboot, the system then checks for this hibernation snapshot, which it reloads if it finds one. We have to tell the system very specifically where to look for it.

1. Determine if your swap is a separate partition or a file in your primary partition.

grep swap /etc/fstab

You’ll most likely see one of two things displayed in response (a or b below).

a. If you see something about “/swapfile” then it’s a swap file on your primary partition. Get the UUID code from your primary partition.

grep UUID /etc/fstab

You’ll see something like this in one of the lines displayed:

UUID=0b3e8d9b-a63e-4bdd-8f47-8a9a764fe7ed /

Be sure to use whatever long code shows up on your system, not this one. That “/” at the end tells you this is your “root” or primary partition.

b. If the initial grep command above returns a line with a long UUID code, then you have a swap partition. Use the UUID code for your swap partition.

2. Modify your grub configuration file to include the UUID code so the system knows where to find your hibernate snapshot. We are going to use the Nano editor:

sudo nano /etc/default/grub

When the editor opens, look for a line like this:

GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"

We are going to append the UUID code to end of this line, but between the quotation marks. First, add a space before that last quotation mark. Then insert your UUID with the format you see here so that it’s all between the quotation marks (use your own UUID):

resume=UUID=0b3e8d9b-a63e-4bdd-8f47-8a9a764fe7ed

The line should resemble this (all on one line):

GRUB_CMDLINE_LINUX_DEFAULT="quiet splash resume=UUID=09e601cd-5bac-491a-9115-fda1b2eb4664"

This tells the system where to check for the presence of a hibernation snapshot file.

3. If your swap is a partition (1b above), then you are done. Save the file using the commands at the bottom of the editor window (CTRL+O and CTRL+X).

If your swap is a file (1a above), then you need to determine an additional “resume_offset” parameter and add it to that to that same line in your grub config.

sudo filefrag -v /swapfile

You should get something that looks like this:

ext:     logical_offset:        physical_offset: length:   expected: flags:
   0:        0..   32767:      34816..     67583:  32768:            
   1:    32768..   63487:      67584..     98303:  30720:            
   2:    63488..   96255:     100352..    133119:  32768:      98304:
   3:    96256..  126975:     133120..    163839:  30720:   
etc...

You want the first number, in the first line that’s under the ‘physical_offset’ heading (in this case ‘34816’). Append this to your grub config on the same line where you added the UUID:

resume_offset=34816

The line should resemble this (all on one line):

GRUB_CMDLINE_LINUX_DEFAULT="quiet splash resume=UUID=09e601cd-5bac-491a-9115-fda1b2eb4664 resume_offset=34816"

Save the file using the commands at the bottom of the editor window (CTRL+O and CTRL+X).

Run sudo update-grub and reboot; after that hibernate should work correctly.

sudo update-grub
sudo reboot

Source

Part 2

We need to modify the system configuration so that hibernate is offered as an option in your power settings and in the shutdown menu. The next command is all on one line:

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

Paste the following lines as they are into the editor 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

Save as before and reboot the computer. Now you should see the option in your power settings to use hibernate as a valid option for things like pressing your system power button.

Source

Part 3

How to disable screenlock: If you find it annoying to have to log back into your system after suspend or hibernate, and you perceive there is no significant security risk of other people messing with your computer, take the following steps.

1. Check settings:

gsettings get org.gnome.desktop.lockdown disable-lock-screen

2. If it comes back “false” change to “true”.

gsettings set org.gnome.desktop.lockdown disable-lock-screen 'true'

3. Check again to be sure:

gsettings get org.gnome.desktop.lockdown disable-lock-screen

Restore by reversing #2 above to ‘false’. This should work immediately without having to logout or reboot.

Source

About Ed Hurst

Disabled Veteran, prophet of God's Laws, Bible History teacher, wannabe writer, volunteer computer technician, cyclist, Social Science researcher
This entry was posted in computers and tagged , , . Bookmark the permalink.

9 Responses to Ubuntu 18.04 Hibernate and Suspend Fix

  1. Pingback: Weird colour noise when Ubuntu wakes up from suspend – PaulJonesBlog.com

  2. Mariela M. says:

    hibernate … it does not work for me. Why?

    Like

  3. Mariela M. says:

    Hibernate: Failed to hibernate system via logind: Sleep verb not supported

    Like

  4. Mariela M. says:

    sudo: pm-hibernate: command not found
    Neither… nor

    Like

  5. Ed Hurst says:

    If it says “command not found,” that means the package pm-utils has not been installed. Or there may be some other problem I cannot diagnose for you without having my hands on the machine itself. The message “sleep verb not supported” indicates your hardware may not work properly with Linux. That is likely if you followed the instructions above and it still does not work. There is no magic wand I can wave to force manufacturers to do the right thing.

    Like

  6. Mariela Martínez says:

    Thanks

    Like

  7. Cédric says:

    Worked perfectly for me. If it doesn’t work for you, maybe you don’t have enough space on you swap file or partition. Try to increase the size of your swap or create a new swap file : https://help.ubuntu.com/community/SwapFaq

    Like

  8. mz says:

    incredible, works, thanks

    Like

  9. Nyyr says:

    I received the same message (Failed to hibernate system via logind: Sleep verb not supported) from

    systemctl hibernate

    when I had besides swap/resume partition defined also swapfile (dunno why now). After removing the swapfile (swapoff ) it worked.

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

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