How do I use pm-suspend-hybrid by default instead of pm-suspend?
Solution 1:
Indirect hybrid sleep
This is the older method: first suspend and then wake up to hibernate after a delay (15 minutes by default). Use this with a Linux kernel before 3.6, or if you like that it does not use any power after 15 minutes any more.
Add the file /etc/pm/config.d/00-use-suspend-hybrid
:
# Always use suspend_hybrid instead of suspend
if [ "$METHOD" = "suspend" ]; then
METHOD=suspend_hybrid
fi
# The delay after which hibernation gets triggered (default: 900 seconds, 15 minutes):
PM_HIBERNATE_DELAY=900
You might want to make sure that the hybrid method is supported on your system via the following code. If it says "0" it should work:
sudo pm-is-supported --suspend-hybrid && echo $?
Real hybrid suspending with Linux 3.6+
If you have a Linux 3.6 kernel, you can use the following, which will suspend to both disk and RAM from the beginning.
Add the file /etc/pm/config.d/00-use-suspend-hybrid
:
# WORKAROUND: always set the default hibernate mode first (normal mode)
# (not required if you have the patch mentioned by Rohan below (http://askubuntu.com/a/344879/169))
HIBERNATE_MODE=platform
# Always use hibernate instead of suspend, but with "suspend to both"
if [ "$METHOD" = "suspend" ]; then
METHOD=hibernate
HIBERNATE_MODE=suspend
fi
# Make sure to use the kernel's method, in case uswsusp is installed etc.
SLEEP_MODULE=kernel
This will always write the image to disk and then suspend to RAM, having the benefits that resuming will always be fast (as long as the battery does not run out) and that the machine will not wake up for a short time (after PM_HIBERNATE_DELAY) to hibernate for real.
The drawback is that the process takes longer (because it always hibernates to disk), and that your battery might run out in the long run (e.g. after 12 hours).
- Corresponding blog post (not updated)
Solution 2:
Ubuntu 18.04 a timed option
In Ubuntu 18.04 has has a new timed option. In systemd
is availiable a new mode suspend-then-hibernate
. This will start with the sleep mode and then transition to the hibernate mode after a fixed time.
In the hybrid-sleep
mode, the hibernate part gets effective only when the battery is critically low and the system shuts down.
To start using this function you need to create a file /etc/systemd/sleep.conf
with the next content:
[Sleep]
HibernateDelaySec=3600
This will go from sleep to hibernate after 1 hour of sleep. You can edit HibernateDelaySec
to change the delay to hibernate.
First, test if suspend-then-hibernate works using systemd
Open a terminal by pressing Ctrl+Alt+T and enter:
sudo systemctl suspend-then-hibernate
If it works make it permanent.
- The following works when I close the lid.
Open the file /etc/systemd/logind.conf
using your preferred editor. You will need to invoke your administrative power by sudo
, gksudo
or pkexec
to edit this file.
Find the two lines:
#HandleSuspendKey=suspend
#HandleLidSwitch=suspend
Note, These lines are commented out with #
in front of them. The suspend
is the default action. Remove the #
and change suspend
to suspend-then-hibernate
in these two lines so that they look like this:
HandleSuspendKey=suspend-then-hibernate
HandleLidSwitch=suspend-then-hibernate
Save the file. Log out and log back in or restart logind
service by the command:
systemctl restart systemd-logind.service
warning! your user session will be restarted
Source: Lid Closed Suspend then Hibernate
Ubuntu 16.04 and above
The solution by blueyed for Real hybrid suspending with Linux 3.6+ did not work for me. I suspect this is because Ubuntu 16.04 uses systemd
and does not use the file /etc/pm/config.d/00-use-suspend-hybrid
.
First, test if hibernate and hybrid-sleep works using systemd
Open a terminal by pressing Ctrl+Alt+T and enter:
sudo systemctl hibernate
This should get your computer to hibernate. To try hybrid-sleep, enter:
sudo systemctl hybrid-sleep
If it works make it permanent.
- The following works when I close the lid.
Open the file /etc/systemd/logind.conf
using your preferred editor. You will need to invoke your administrative power by sudo
, gksudo
or pkexec
to edit this file.
Find the two lines:
#HandleSuspendKey=suspend
#HandleLidSwitch=suspend
Note, These lines are commented out with #
in front of them. The suspend
is the default action. Remove the #
and change suspend
to hybrid-sleep
in these two lines so that they look like this:
HandleSuspendKey=hybrid-sleep
HandleLidSwitch=hybrid-sleep
Save the file. Log out and log back in.
Note:
- Other than
suspend
orhybrid-sleep
there is a third option,hibernate
. - My laptop does not have a physical sleep button. So I could not test it.
- Clicking on the
Suspend
from the cog menu puts the computer to normal suspend not hybrid-sleep.
Source: https://superuser.com/questions/719447/how-to-use-systemd-hybrid-sleep-instead-of-suspend-under-gnome-in-linux
I hope this helps
Solution 3:
In 12.04 I noticed that when hibernation is triggered (using PM_HIBERNATE_DELAY=XX
), the resume/thaw the shell scripts do not unset the grub recordfail variable. Therefore grub does not autoboot.
Timeout is set to -1 and it awaits user selection. I am guessing this requires some editing of scripts in /etc/pm/sleep.d/10_grub-common
. Am a novice so I haven't dabbled to figure out the exact change unfortunately.
Solution 4:
This question comes up frequently enough in Google that I think it's worth bumping. The method described here is (imo) not hybrid suspend. It is "hibernate after X minutes in suspend". True hybrid suspend writes your RAM out to disk and then goes in low-power state (sleep mode). While it takes longer, the resume is instant while the machine has battery left, otherwise resumes form hard disk. This behaviour is what most people know as hybrid sleep, and used by default in the newer Windows and Mac laptops.
Here's how to enable the real hybrid suspend:
- Follow the first part of the top answer. This overrides "suspend" call to do a "hybrid_suspend" in pm-utils.
% cat /etc/pm/config.d/00-use-suspend-hybrid # Always use suspend_hybrid instead of suspend if [ "$METHOD" = "suspend" ]; then METHOD=suspend_hybrid fi
- Make a backup of /usr/lib/pm-utils/pm-functions
- Get the patch from here: https://bugs.freedesktop.org/attachment.cgi?id=68712
- This patch enables hybrid suspend if available (i.e. on kernels 3.6+)
- Either apply it using 'patch -p0' or manually merge it if that fails
This method works for me on my Sony Vaio SVS.
PS: Reproducing the patch here in case the file is deleted in the future:
diff --git a/pm/pm-functions.in b/pm/pm-functions.in --- a/pm/pm-functions.in +++ b/pm/pm-functions.in @@ -316,8 +316,28 @@ if [ -z "$HIBERNATE_MODULE" ] && \ { [ -n "${HIBERNATE_MODE}" ] && \ grep -qw "${HIBERNATE_MODE}" /sys/power/disk && \ + HIBERNATE_MODE_SAVE=$(cat /sys/power/disk) && \ + HIBERNATE_MODE_SAVE="${HIBERNATE_MODE_SAVE##*[}" && \ + HIBERNATE_MODE_SAVE="${HIBERNATE_MODE_SAVE%%]*}" && \ echo -n "${HIBERNATE_MODE}" > /sys/power/disk echo -n "disk" > /sys/power/state + RET=$? + echo -n "$HIBERNATE_MODE_SAVE" > /sys/power/disk + return "$RET" + } +fi + +# for kernels that support suspend to both (i.e. hybrid suspend) +# since kernel 3.6 +if [ -z "$SUSPEND_HYBRID_MODULE" ] && \ + [ -f /sys/power/disk ] && \ + grep -q disk /sys/power/state && \ + grep -q suspend /sys/power/disk; then + SUSPEND_HYBRID_MODULE="kernel" + do_suspend_hybrid() + { + HIBERNATE_MODE="suspend" + do_hibernate } fi
Sources:
- https://bugzilla.redhat.com/show_bug.cgi?id=843657
- https://bugs.freedesktop.org/show_bug.cgi?id=52572