Ubuntu – How to go automatically from Suspend into Hibernate


Is it possible to make Ubuntu go into Hibernate state from Suspend, aka "Suspend Sedation"?

What I am looking for is this:
When I close the lid, the laptop is put into Suspend. Then, after a pre-determined time (even if the battery is going strong) if I still don't use it, it should put itself into a Hibernate to save battery power.

For example, my laptop is set up to go into a Suspend once I close the lid. If then I don't use it for entire day, the battery goes flat, because even in suspend mode the hardware still consumes a small amount of power, and the battery eventually discharges.
What I want is to be able to tell Ubuntu that even if it is suspended, it still needs to go into Hibernate after some hours of inactivity.

Windows can do that.
Ubuntu can be programmed to go into Standby or Hibernate on timer, but not both.

Best Answer

In Ubuntu 18.04 and newer it much more easier. In systemd is available a new mode suspend-then-hibernate. To start using this function you need to create a file /etc/systemd/sleep.conf with the next content:


Then you can test it by command:

sudo systemctl suspend-then-hibernate

you can edit HibernateDelaySec to reduce delay to hibernate.

If all works fine you can change Lid Close Action, to do it you need to edit the file /etc/systemd/logind.conf

You need to find option HandleLidSwitch=, uncomment it and change to HandleLidSwitch=suspend-then-hibernate. Then you need to restart systemd-logind service (warning! you user session will be restarted) by the next command:

sudo systemctl restart systemd-logind.service

That's all! Now you can use this nice function.