This is already the default setting - uncommenting it does nothing.
I think you have a conceptual problem.
If the system is suspended - it is suspended.
You’ll have to wake it up to have it then again enter a different state, hibernate this time.
It’s hard to automate this when the machine isn’t running.
Then there is hybrid sleep - it first hibernates, to write the data to disk, then it comes back and suspends.
If the battery runs out and the RAM content is lost, the system will wake up from disk instead.
For me, the output of: cat /sys/power/mem_sleep
is: s2idle [deep]
I do not know whether that is different for you or could easily be adapted.
The information in the second link seems to suggest something.
The default suspend mode (ie. the one to be used without writing anything into
/sys/power/mem_sleep) is either “deep” (if Suspend-To-RAM is supported) or
“s2idle”, but it can be overridden by the value of the “mem_sleep_default”
parameter in the kernel command line.
But I do not know nor can I judge the possible significance of this for you.
Perhaps it is some helpful info though.
I have never tested how long my laptop will be able to be in suspend mode before the battery runs out - if I anticipate that it will be a long time, I use hybrid sleep - then it does not matter whether the battery runs out.
There are also two modes combining suspend and hibernate:
systemctl hybrid-sleep suspends the system both to RAM and disk, so a complete power loss does not result in lost data. This mode is also called suspend to both.
systemctl suspend-then-hibernate initially suspends the system to RAM and if it is not interrupted within the delay specified by HibernateDelaySec in systemd-sleep.conf(5), then the system will be woken using an RTC alarm and hibernated.
This is default on my Manjaro 21.2.5 (Gnome) system, after properly configuring swap to file for BTRFS and enabling hibernation:
However it also does not do what I want (not sure if it ever did, I do believe something changed after an update):
I want hybrid sleep, always. If you have a fast SSD, there is really no reason not to do this. Always write to both SSD and RAM.
I want SuspendThenHibernate after 60min suspend.
I want this regardless whether I am on battery or not (because I could unplug the system after it has suspended.
The Arch Wiki is in my opinion the best documentation, far better than any other distribution like Ubuntu. But when it comes to sleep, it lets me down a little I have read these article and this article in the wiki, but no where is stated what values to use:
Sorry but you are 100% incorrect, not according to me, but to the definition in the Arch wiki, it clearly states the definition of hybrid-sleep:
suspends the system both to RAM and disk
That is exactly not what you are writing, as you clearly mention 2 actions for Hybrid sleep, first suspend, then it comes back and does hibernate. That is not Hybrid Sleep. Not according to the wiki.
No, they litterally do not. Hybrid sleep, when initiated, immediately writes to BOTH and then it is done performing any actions. It does not wake up to write to disk.
No, because after Hybrid Sleep, the system stays suspended (and keeps consuming power). There is no other action after HibernateDelaySec is reached, because this value is for suspend-then-hibernate, it has nothing to do with Hybrid Sleep. If you want your system to wake up from suspend to go into hibernate (no power consumption), it does not matter whether data has been written only to RAM or (because of Hybrid Sleep instead of Suspend) to both RAM and swap already.
They do not exclude each other.
It is perfectly fine to decide you want it to hibernate after 60 minutes of suspend. Since that is exactly what Suspend-Then-Hibernate is for. Why suddenly this functionality is blocked simply because the required data is already in swap makes no sense. It could only benefit from that.
I recommend you read the Arch wiki a couple of times.
Then you will also understand suspend-then-hibernate means there are plenty of cases where hibernate is not triggered. That is why the combination with Hybrid Sleep (which is simply Suspend but with ram also written to swap at the same time) is very handy.
Seriously, just read that first quote… You are mixing up definitions, which is actually very understandable, because the definitions are easy to mix up Hybrid Sleep is not what wakes up your system… that is what suspend-then-hibernate does.
Find 1 person who has read the Arch Wiki and agrees with you please…
… this is funny
you say things that I never said - and then try to correct me on it
Have you actually tried and observed one method, then the other?
It may be hard with an SSD as it is already so fast.
With a spinning disk you’ll see clearly what happens.
hybrid-sleep will write to disk, then suspend to RAM
and will wake up from RAM if it was preserved (the power was not interrupted)
and it will wake up from disk if power was not preserved.
suspend-then-hibernate will wait some time (in suspend to RAM state)
then wake up and suspend to disk
Wake up is from disk after that point - RAM is not preserved anymore.
The battery isn’t drained/power isn’t needed anymore.
I wonder why you can’t get to work what you so well understand.
That is the part I am trying to help you understand, is closer to the definition of suspend-then-hibernate, not hybrid-sleep. Or you could just read the wiki… because it is not even the definition of suspend-then-hibernate.
What you are describing is litterally hibernate-then-suspend, which does not really exist But I do understand the effort you made here.
Back on topic, following the documentation exactly, this is now part of my post-install script. I use Gnome, but this is not dependent on Gnome:
# GOAL: system should not use Suspend anymore. Always use Hybrid Sleep and Suspend-Then-Hibernate. Use Hibernate when power key is hit. Use Suspend-Then-Hibernate when lid is closed.
# follow https://wiki.archlinux.org/title/Power_management#Hybrid-sleep_on_suspend_or_hibernation_request
# follow https://man.archlinux.org/man/sleep.conf.d.5
# Disable regular suspend, we only allow Hybrid Sleep, to prevent data loss when battery dies
sed -i -e 's@#AllowSuspend=yes@AllowSuspend=no@g' /etc/systemd/sleep.conf
# Disabling suspend implies disabling suspend-then-hibernate and hybrid-sleep, override to allow both again
sed -i -e 's@#AllowHybridSleep=yes@AllowHybridSleep=yes@g' /etc/systemd/sleep.conf
sed -i -e 's@#AllowSuspendThenHibernate=yes@AllowSuspendThenHibernate=yes@g' /etc/systemd/sleep.conf
# Define the method of suspend to be Hybrid Sleep, this is also used by suspend-then-hibernate to determine how to suspend.
sed -i -e 's@#SuspendMode=@SuspendMode=suspend@g' /etc/systemd/sleep.conf
sed -i -e 's@#SuspendState=mem standby freeze@SuspendState=disk@g' /etc/systemd/sleep.conf
# when suspend-then-hibernate is used, go into hibernation (0.0 power consumption) after 60min of suspend unless interrupted
sed -i -e 's@#HibernateDelaySec=180min@HibernateDelaySec=60min@g' /etc/systemd/sleep.conf
# Now define what to do on user initiated actions: go into hibernation when hitting power key
sed -i -e 's@#HandlePowerKey=poweroff@HandlePowerKey=hibernate@g' /etc/systemd/logind.conf
# Use suspend-then-hibernate when lid is closed, even when on external power since you could disconnect from power during suspend
sed -i -e 's@HandleLidSwitch=ignore@HandleLidSwitch=suspend-then-hibernate@g' /etc/systemd/logind.conf
sed -i -e 's@#HandleLidSwitchExternalPower=suspend@HandleLidSwitchExternalPower=suspend-then-hibernate@g' /etc/systemd/logind.conf
this is just changing values according to the Wiki. Will test all of it.
@xakraz hibernation wasn’t working, the wiki to enable this on BTRFS filesystem is updated and now it works again. I have updated my script. More info here:
The Arch wiki articles on how to enable suspend-then-hibernate are incorrect, this suspend-then-hibernate isn’t even a supported value in sleep.conf and logind.conf, contrary to what the wiki says. The only way to get it working is by symlinking it to the suspend service. See my script.
You can still also enable hybrid sleep by changing the State in sleep.conf to disk, but it is less useful with the way suspend-then-hibernate now works.