1

I am unable to get the "Suspend" functionality to work correctly on Ubuntu 18.04. However the Hibernate functionality works as expected.

Problem description: When I use Suspend from either the Power Menu or "sudo systemctl suspend" the behavior is:

  • The machine goes into Sleep mode and the power button LED slowly blinks (breaths).
  • When the laptop is restarted, the OS starts up, I see the usual login screen, but none of the applications that were running are restored.

What I have done so far:

$ sudo apt-get install uswsusp
$ sudo update-initramfs -u
$ sudo systemctl edit systemd-suspend.service

I pasted in the following lines into systemd-suspend.service:

[Service]
ExecStart=
ExecStartPre=-/bin/run-parts -v -a pre /usr/lib/systemd/system-sleep
ExecStart=/usr/sbin/s2ram
ExecStartPost=-/bin/run-parts -v --reverse -a post /usr/lib/systemd/system-sleep
  • saved the file. It gets saved in /etc/systemd/system/
  • run:

    $ sudo systemctl daemon-reload

  • Test it:

    $ sudo systemctl suspend

The results are as described above, the laptop sleeps, however the saved session is not restored on restart.

I do know that the systemd-suspend.service script is being called. If I change the line ExecStart=/usr/sbin/s2ram to ExecStart=/usr/sbin/s2disk the laptop goes into Hibernate and restores the session.

Additional info:

In order to get Hibernate to work I changed grub:

sudoedit /etc/default/grub

changed this line:

GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"
 to:
GRUB_CMDLINE_LINUX_DEFAULT="no_console_suspend initcall_debug resume=UUID=<string of hex> resume_offset=34816"
  • then ran:

    $ sudo update-grub

Kernel info:

lsb_release -a

Distributor ID: Ubuntu
Description:    Ubuntu 18.04.2 LTS
Release:    18.04
Codename:   bionic

uname -a 
Linux <machinename> 4.18.0-21-generic #22~18.04.1-Ubuntu SMP Thu May 16 15:07:19 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux


sudo s2ram -K
This kernel has KMS support.

Is there some step or configuration item that I'm missing?

2

After much searching for an answer and banging my head on the table I arrived at a solution on my own by cobbling together bits and pieces of information from various sources. This solution works on my Sony Vaio Model VPCEB15FM running Ubuntu 18.04, your mileage may differ.

Part of the problem with getting hibernate/suspend to work correctly was the way that Ubuntu loads and assigns /dev/sda2, /dev/sdb2, etc. since the drive assignment order sometimes changes from boot to boot. So the first step is to identify the UUID of the swap partition. Since the UUID is constant it makes a much more reliable mount point.

The UUID can be gotten from:

sudo blkid

Look for the entry that says "swap"

/dev/sda2: UUID="5c555600-2e37-477d-62df-6013d61dc36" TYPE="swap" PARTUUID="2f501554-02"

Your UUID will be different than mine. Don't use mine, use yours.

If you're using a swap file instead of a swap partition then use the UUID of the main linux partition, and you will also need to know the offset to the swapfile.

To get the offset to the swap file:

sudo filefrag -v /swapfile

The output will look similar to 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:

The offset you're after is the first "physical_offset", in this case it would be 34816.

Now you have the information you need to get started.

Modify /etc/default/grub

sudoedit /etc/default/grub

change the line:

GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"

if using a swap partition to:

GRUB_CMDLINE_LINUX_DEFAULT="no_console_suspend initcall_debug resume=UUID=5c555600-2e37-477d-62df-6013d61dc36"

if using a swapfile to:

GRUB_CMDLINE_LINUX_DEFAULT="no_console_suspend initcall_debug resume=UUID=5c555600-2e37-477d-62df-6013d61dc36 resume_offset=34816"

Install uswsusp.
This installs the s2disk, s2ram, and s2both methods.

sudo apt-get install uswsusp

Set up systemd-hibernate.service and systemd-suspend.service.
These files are in /etc/systemd/system/ or will be created there if they don't already exist.

sudo systemctl edit systemd-hibernate.service

Paste in these lines:

[Service]
ExecStart=
ExecStartPre=-/bin/run-parts -v -a pre /lib/systemd/system-sleep
ExecStart=/usr/sbin/s2disk
ExecStartPost=-/bin/run-parts -v --reverse -a post /lib/systemd/system-sleep

Note: my system has a path to /lib/systemd/system-sleep, others might have a different location like /usr/lib/systemd/system-sleep.

sudo systemctl edit systemd-suspend.service

Paste in these lines:

[Service]
ExecStart=
ExecStartPre=-/bin/run-parts -v -a pre /lib/systemd/system-sleep
ExecStart=/usr/sbin/s2both
ExecStartPost=-/bin/run-parts -v --reverse -a post /lib/systemd/system-sleep

Note use s2both instead of s2ram in the "suspend" configuration. s2ram didn't work on my system, but s2both always does.

Edit /etc/uswsusp.conf.
Use the UUID and if using a swapfile the offset:

sudo nano /etc/uswsusp.conf

Modify to use your UUID, etc.

# /etc/uswsusp.conf(5) -- Configuration file for s2disk/s2both 
resume device = UUID=5c555600-2e37-477d-62df-6013d61dc36
compress = y
# early writeout = y
# image size = 1741570539
# RSA key file = /etc/uswsusp.key
shutdown method = platform
# only needed if using a swapfile
# resume offset = 34816

Note: There is a man page for uswsusp.conf that fully describes all the parameters. There's a bunch of other settings, this is the minimum required. The commented lines were left in so you can see some of the other options.

Edit /etc/initramfs-tools/conf.d/resume

sudo nano /etc/initramfs-tools/conf.d/resume

add this line: RESUME=UUID=5c555600-2e37-477d-62df-6013d61dc3

Note: if using a swapfile then the offset needs to be added. add: resume offset = 34816 after the UUID

Okay, that should take care of the various configuration items.

Update grub and initramfs:

sudo update-grub
sudo update-initramfs -u  or update-initramfs -u -k all  to do all kernels

Restart Ubuntu.
After the reboot test the hibernate and suspend functionality. Hibernate can take several minutes to write the resume file to the swap and shutdown the machine. Don't Panic. Suspend is a bit faster.

Test it all out!

sudo systemctl hibernate
sudo systemctl suspend

What you should see:

  • hibernate - shuts down system completely, will take several minutes. After restarting the computer and logging back in your applications should be resumed. Note: The resume process can take a few minutes and the machine may appear hung while resume takes place. Be patient.
  • suspend - the system goes into "sleep" mode and the power light slowly blinks (breaths). Pressing the main power button wakes up the machine. You should see the login screen and your applications should be resumed.

Further steps:
You should be able to enter sleep/suspend mode from the power menu drop down. When you open the drop down press the Alt key. The Power Icon should change into the sleep icon.

A Hibernate menu option can be added too. There are already some good tutorials on that which can be found by searching for "ubuntu add hibernate power menu"

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.