1

I am trying to let my XPS 13 7390 hibernate when closing the lid.

I followed this guide to set my system up to do this. But I think it is not working properly.

When I run sudo systemctl suspend-then-hibernate I can see new "hibernation" logs, when running cat /var/log/syslog | grep hibernate:

Dec  8 14:04:16 jonas-XPS-13-7390 systemd[1]: Starting Suspend; Idle into hibernate...
Dec  8 14:05:32 jonas-XPS-13-7390 systemd[1]: Started Suspend; Idle into hibernate.
Dec  8 14:05:32 jonas-XPS-13-7390 systemd[1]: Reached target Suspend; Idle into hibernate.
Dec  8 14:05:32 jonas-XPS-13-7390 systemd[1]: suspend-then-hibernate.target: Unit not needed anymore. Stopping.
Dec  8 14:05:32 jonas-XPS-13-7390 systemd[1]: Stopped target Suspend; Idle into hibernate.

And searching for "sleep" I get the following lines:

Dec  8 14:04:16 jonas-XPS-13-7390 systemd-sleep[11380]: Suspending system...
Dec  8 14:05:32 jonas-XPS-13-7390 systemd-sleep[11380]: System resumed.

But when i close the lid, or press the power button, NO new hibernation is logged. But when i search for the term "sleep" it shows the same logs as when i've run the hibernation command manually from terminal:

Dec  8 14:10:51 jonas-XPS-13-7390 systemd-sleep[12481]: Suspending system...
Dec  8 14:11:29 jonas-XPS-13-7390 systemd-sleep[12481]: System resumed.

Now I want to know:

  • How can I find out if my system was actually hibernating (using less energy than sleeping is my main focus here)?
  • How can I make my elementary installation sleep when closing the lid?

2 Answers 2

1

I actually found the solution to the problem in "Linux Magazin".

My full workflow looks like this:

Lid Hibernate Ubuntu

  • Make sure you have SWAP > RAM

SWAP to fstab

find swap UUID:

blkid | grep swap

should output

/dev/nvme0n1p1: UUID="90ee7315-b16a-4e2g-bd07-cg83703750b9" TYPE="swap" PARTUUID="abadca41-942a-6c83-88d2-db28cf41ce13"`

copy the UUID, without the " :

UUID=90ee7315-b16a-4e2g-bd07-cg83703750b9

add swap to fstab

sudo nano /etc/fstab

add

UUID=90ee7315-b16a-4e2g-bd07-cg83703750b9 none swap sw 0 0

  • reboot

add swap to grub

sudo nano /etc/default/grub

edit GRUB_CMDLINE_LINUX_DEFAULT="quiet splash" to GRUB_CMDLINE_LINUX_DEFAULT="resume=UUID=90ee7215-c16a-4e2f-bd07-cd83703750b6"

if you DONT want kernel messages to be shown and keep the plymouth animation during boot, change to:

GRUB_CMDLINE_LINUX_DEFAULT="quiet splash resume=UUID=90ee7215-c16a-4e2f-bd07-cd83703750b6"

update grub with the new settings: sudo update-grub

try with

sudo systemctl hibernate

after reboot it should show all the same windows again

activate automatic hibernation after delay

To start using this function you need to create a file

sudo nano /etc/systemd/sleep.conf

add

[Sleep]
HibernateDelaySec=3600

try

sudo systemctl suspend-then-hibernate

Should sleep for the time specified and then the screen turns on shortly and it hibernates. Try rebooting after this happened.

If it works make it permanent.

sudo nano /etc/systemd/logind.conf

change

#HandleSuspendKey=suspend
#HandleLidSwitch=suspend

to

HandleSuspendKey=suspend-then-hibernate
HandleLidSwitch=suspend-then-hibernate

Save the file. Restart logind service by the command:

systemctl restart systemd-logind.service

sources:

6
  • I have already tried all of this with no success. Can you mark your answer as the accepted one in order to be usefull for somebody else?
    – Bo rislav
    Jan 3, 2020 at 18:23
  • @Borislav Do you have your swap encrypted? Jan 6, 2020 at 15:00
  • no, it is not. I have tried all the steps you describe following a lot of different guides, but when I execute systemctl hibernate the screen becomes black, after a second or something it lights again and then after like couple of seconds it turns off. When I start the computer, it is like normal boot, the swap is empty but I see a messages for a lot of orphaned inodes, just like if I do hard shutdown by holding the poweroff button. If I execute systemctl suspend-then-hibernate, first it suspends, and after the delay specified it behave the same way..
    – Bo rislav
    Jan 6, 2020 at 15:08
  • @Borislav do you have a duplicate GRUB_CMDLINE_LINUX in /etc/default/grub ? I had a duplicate one and realised it was overwriting my GRUB_CMDLINE_LINUX_DEFAULT so none of the settings there were picked up.
    – David Wu
    Apr 3, 2020 at 13:28
  • I have GRUB_CMDLINE_LINUX_DEFAULT="quiet......" and GRUB_CMDLINE_LINUX="" but I do not think that they are duplicates, are they?
    – Bo rislav
    Apr 3, 2020 at 22:04
0

I have managed to achieve hibernation following one guide, but I did some changes noticed into the comments to the post there. Sources are below, but first the steps with the updated (working) for me code:

1. Edit the hibernation service with

sudo systemctl edit systemd-hibernate.service

2. Paste the following code

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

Save Ctr+o and exit with Ctr+x

3. Update systemd

sudo systemctl daemon-reload

4. Test if it is working

sudo systemctl hibernate

After the above command the screen should go into terminal view, a counter shows the progress of the disk write into swap partition and computer turns off. When I start it the procedure is like a normal start of the system but there is no login screen (pantheon-greeter) - after the plymouth animation the system is restored to the state with opened windows and settings applied before the hibernation command.

If everything works well for you too, you can add this functionality when the lid is closed - edit the logind.conf file, because there is no such an option into System settings - Power anymore:

5. Set hibernation on a lid close

sudoedit /etc/systemd/logind.conf

find and edit the line at the end of the file with HandleLidSwitch=whatever_you_choosed_from_power_settings, if there is a comment (a # sign in front) remove it or just paste below:

HandleLidSwitch=hibernate

Ctrl+o and Ctrl+x to save and close the file. In order the changes to take effect immediately - sudo service systemd-logind restart or just reboot the computer.

I have tried doing the same with suspend-then-hibernate, but if I edit the suspend-then-hibernate.service like this, ofcourse it do not suspend first but immidately hibernates and if I do not edit it but try to execute the systemctl suspend-then-hibernate command - after the sleep interval it executes the default hibernation process which do not work on my system - it leads to a shutdown with orphaned inodes, which is not nice.

Sources:

hibernation - https://unix.stackexchange.com/a/386837/355963 - notice the comments of the post

lid close - https://askubuntu.com/a/372616/730454

@zagatta-sonah Thanks for asking this question and sharing your attempt - it inspired me to found at least this functionality I spent days of not successfull tries, because on my system suspend is not nice on a battery power for a long time.

If somebody can share how to achieve suspend-then-hibernate the same way it will be really nice, but at least only hibernate is much much better than just suspend.

1
  • i think i found the solution. see what i answered for my own question. Regards for your input Jan 3, 2020 at 16:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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