Ubuntu – Ubuntu 16.04 doesn’t shut down after suspend or hibernate

16.04hibernateshutdownsuspend

Why no answer accepted

For the simple reason that I haven't been using Ubuntu for a long time, so I couldn't test the answers.

The question

Actually my question can appear identical to this one in this forum (and also this one elsewhere); indeed the question is the same, but I'm asking it anyway because I can give more informations and because I tried some solution found on the web (possibly getting things worse).

I used to hibernate Ubuntu 15.10 (closing the lid).
Now that I've updated it to 16.04 (I thought it was a good thing, since this version is LTS, unlike the 15.10), I cannot use hibernation (nor suspension!) anymore: if I try to use it, Ubuntu doesn't shut down, just the screen goes black, the power led is on, and I cannot do anything else than shutting it down manually (long press of the power button).
When I power it on again, I see the following lines

enter image description here

then Ubuntu boots up.

From here I tried with

sudo -s
echo shutdown > /sys/power/disk
echo disk > /sys/power/state

and

sudo -s
echo platform > /sys/power/disk
echo disk > /sys/power/state

Only the first partially worked and only once: by partially I mean that after the brutal shut down the session was recovered.

Then I tried to follow this suggestion. I didn't understand the comments written after the commands, so I literally entered the commands as they are (thinking that some error like "this command/folder doesn't exist" would have been occurred if there was something to substitute in the commands):

EDIT

cat /proc/meminfo
sudo swapoff -a
sudo dd if=/dev/zero of=/swapfile bs=1024 count=8M
sudo chmod 600 /swapfile && sudo mkswap /swapfile && sudo swapon /swapfile
sudo -b gedit /etc/fstab
free -m
swapon

mount | grep " / "
sudo blkid -g
sudo blkid
sudo filefrag -v /swapfile | grep "First block:"
sudo filefrag -v /swapfile
echo "resume=UUID=cdXX--X18 resume_offset=66050" | sudo tee /etc/initramfs-tools/conf.d/resume
sudo -b gedit /boot/grub/menu.lst
sudo -b gedit /etc/default/grub
GRUB_CMDLINE_LINUX_DEFAULT="... resume=UUID=cdXX--X18 resume_offset=66050"
sudo update-grub -y
sudo update-initramfs -u

Maybe this has been a terrible idea, since now I get this.

IMG:

In the end I found the question linked above and I went here, but I don't know what to do.

EDIT 2 At the moment if I enter

...$ sudo swapon -s

I obtain absolutely nothing

...$

Best Answer

Forcing hibernate to power off the machine:

After looking around a long time for an answer to this that actually addressed the issue (not related ones), I found a tip here which got the job done for me:

Create a file in the pm config directory:

sudo vim /etc/pm/config.d/hibernate_mode

that sets the variable HIBERNATE_MODE like so:

HIBERNATE_MODE="shutdown"

After doing this, hibernate powered down the machine on completion like expected. An explanation for what setting HIBERNATE_MODE does is in the manual for pm-hibernate:

Default method to power down the system when hibernating. If not set, the system will use the kernel default as a default value. Check /sys/power/disk for valid values. The default value will be surrounded by [square brackets].

My default in that file was platform. Setting the variable above to shutdown overrides this, and gets what we want happening.

Related information and tips for getting hibernate to work correctly:

As for those "related issues" everyone seems to have with hibernating, quick debugging tips:

  1. Check that the command sudo pm-hibernate actually does something. If not, none of these other tips will make any difference. If it doesn't work, ensure 1) the size of your swap partition is greater than that of your RAM and 2) secure boot is disabled in your BIOS.

  2. Only once that command works, look at integrating hibernate into your system as you please. A couple of common ones:

    • Add hibernate to the Ubuntu menu: This seems to be the best answer to me. Official documentation also has a slightly different version.
      Note: once hibernate is added to the Ubuntu menu, you may also need to fix the alternative call to sudo systemctl hibernate. Apparently, (at least for Ubuntu 16.04) the Ubuntu menu option calls sudo systemctl hibernate instead of sudo pm-hibernate. systemctl hibernate was fixed for me by adding the following content to file /etc/systemd/sleep.conf:

      [Sleep]
      HibernateMode=shutdown

      If the file doesn't exists yet, you can create it. More info here.

    • Change the behaviour of the power button (by default it displays in interactive menu): To change it to directly hibernate, or shutdown you need to modify the associated gsettings entry. A lot of other answers go through the GUI way if that floats your boat. To see the available options use gsettings range org.gnome.settings-daemon.plugins.power button-power