2

If this is a dupe point me in the right direction and I'll delete this, but I could not find via google.

One feature I really miss from OSX is that when my MBP runs out of power, after being charged, pressing the power button is like waking from hibernate (as opposed to booting from scratch). Is there any way to recreate this effect with ubuntu? I realize this may be somewhat hardware-dependent, I can specify if need be.

Update

The linked dupe looks interesting and useful but doesn't really answer my question.

MacOS (and I realize this may be intrinsically tied to apple hardware, but IDK) seems to have some sort of setup where, when the battery gets critically low, it automatically saves the state of the system (I'm assuming to disk, since RAM would be wiped with loss of power) before powering down. Then when you plug it in it restores that state rather than booting from scratch. The other question seems to be about the behavior on lid-close.

user68186
  • 33,360
  • 1
  • @user68186 that's really useful, but not what I'm after. MacOS (and I realize this may be intrinsically tied to apple hardware, but IDK) seems to have some sort of setup where, when the battery gets critically low, it automatically saves the state of the system (I'm assuming to disk, since RAM would be wiped with loss of power) before powering down. Then when you plug it in it restores that state rather than booting from scratch. Your answer on that other question seems to be about the behavior on lid-close. – Jared Smith Feb 20 '20 at 15:23
  • Based on the comments of the OP and the edit to the question, I am retracting the duplicate-close vote. I seem to remember another Mac user asked a similar question a year or two ago and we may have closed that as duplicate. We should keep this one as a question related to replicating MacOS behavior in Ubuntu regarding hybrid-sleep. – user68186 Feb 20 '20 at 22:07
  • I will change the title to reflect the MacOS behavior replication in the question. – user68186 Feb 20 '20 at 22:14

1 Answers1

2

The Safe Sleep mechanism MacOS

I don't know about MacOS, so I take your word for it. The process you describe has three steps:

  1. System enters sleep (also called suspend to RAM) when you close the lid or press a button or click on an icon.
  2. If battery gets critically low, the system wakes up and saves the system-state in disk, thus entering into the hibernate mode and then powers off.
  3. When you turn the system back on again it starts in the same state it was left in, with all the applications open and unsaved files intact.

If you want Ubuntu to behave exactly like MacOS as described above, there is no way to do it.

Ubuntu Does It Defferently

The difference is in step 2. Ubuntu has no way of waking the system and saving the state in the disk when the battery is critically low. However, it can get the same results in two different ways. I will describe them below:

Hybrid-sleep

This method is the closest to "Safe Sleep" in MacOS

In this method, at step 2, when you close the lid, first thing Ubuntu does is, save the state of the system (which applications are open, etc.) into the disk. Once all that information is safely in the disk (either in the swap file or partition depending on your setup) Ubuntu suspends to RAM or more simply put, goes to sleep.

If you open the lid before battery gets too low, then the laptop wakes up from sleep as normally and as quickly as in the normal sleep mode. The information saved in the swap file/partition is discarded in the background. This process is usually faster than booting the laptop.

If battery gets critically low, Ubuntu will shutdown. However, since the information is already saved, it will not be normal shutdown. Instead it will hibernate. That is, when you power up the laptop again it will boot up at the state you left it when you closed the lid.

The disadvantage of this method is, it takes longer for the laptop to initially go to sleep after you close the lid as it takes a bit of time to save the information in the disk first. So, when you close the lid, the LED lights on the laptop will continue to glow for a while, before the lights change to indicate that the laptop has entered in the sleep mode.

If the system runs out of power, hybrid-sleep will restore it to the state you left it in as you want.

suspend-then-hibernate

This is similar to hybrid-sleep but with a twist. In this mode laptop enters the sleep mode as soon as you close the lid. However, you configuration you setup a time period (say one hour). After one hour has passed, the laptop saves the information in the RAM to the disk, and then turns itself off.

If you come back to your laptop within an hour (or the time you set), when you open the lid, it will wake up from sleep quickly as usual.

If you go for lunch and meet an old friend and decide to take the rest of the day off, and come back to work the next day, you will be able to turn the laptop back on without plugging it in first (assuming it had some juice left after an hour of sleep) and start working where you left off the previous day before lunch.

The disadvantage is if you return from lunch five minutes past the hour, it will take longer for the laptop to spring back to life (in the state you left it), as it has transitioned from sleep to hibernate mode.

The system does not run out of power as it turns itself off after the set time and restore itself to the state you left it when you turn it back on.

Both Solutions

Both solutions are described in the answer How do I use pm-suspend-hybrid by default instead of pm-suspend?

This is why I consider this question a duplicate. However, I wrote this answer to make it clearer based on the comments and updated question.

Hope this helps

user68186
  • 33,360
  • I still don't think it's a duplicate (the answer to my question appears to be "no" lol). But your answer to the other one is as close as I'm going to get, so thank you. – Jared Smith Feb 20 '20 at 21:26
  • 1
    I usually wait 24 hours before accepting an answer, but if no one else throws down with something better you've got it. – Jared Smith Feb 20 '20 at 22:03
  • 1
    @JaredSmith it has been a little more than 24 hours. I hope you still find my answer satisfactory. :-) – user68186 Mar 17 '20 at 14:10