Thursday, November 8, 2007

Mac OS X Hibernate Issue


I have been searching for ways for Mac OS X to behave the same as Windows when it comes down to hibernation. Mac OS X has this concept of "Sleep" and "Shutdown".

By default, "Sleep" will turn the computer off but my MacBook Pro will still have the white light, switching between dim and bright. In this case, you cannot totally switch off your MacBook Pro as you would like to do in Windows.

However, if you "Sleep" using your laptop battery, once the battery runs out, MacBook Pro is smart enough to save all contents in your RAM to hard disk. This is called a "Safe Sleep".


Wouldn't it be nice if we could choose to hibernate whenever we want so that if we are not using the laptop for a few hours, instead of putting the laptop to "Sleep", which will still drain the battery, we can "hibernate" the laptop and restore our applications (as it is) when we start it up again.


Macworld has an article that contains comprehensive information about this. Here is the summary.
  • First find out what is the current setting of your sleep mode, using:
> pmset -g | grep hibernate

This will tell you which sleep mode you are currently on. The following displays different sleep mode:

0 - Legacy sleep mode. It will save everything to RAM upon sleeping but does not support "Safe Sleep". Very fast sleep.
1 - Legacy "Safe Sleep". This is the "Safe Sleep". Everything your laptop goes into sleep, it will save everything to harddisk. Slow on Sleep and Startup.
3 - Default. As described above, when sleeping, contents are saved to RAM. When battery runs out, hibernate occurs.
5 - Behaves as 1 but applicable only for modern Mac that uses "Secure virtual memory".
7 - Behaves as 3 but applicable only for modern Mac that uses "Secure virtual memory".

  • For me, I am using MacBook Pro and I know that I am using "Secure virtual memory" (System Preferences -> Security), so 5 is my choice. I want my Mac to hibernate everything I sleep.
  • Make an alias in your .bash_profile under your home directory:
alias hibernateon="sudo pmset -a hibernatemode 5"
alias hibernateoff="sudo pmset -a hibernatemode 0"

  • "Source" your bash_profile file and your are done!
  • Whenever you want to hibernate your computer, if it is not set already, just go to terminal and execute hibernateon. If you want to turn it off, hibernateoff and you are all set.


It was known that if you want to avoid hassle setting up in command line, there is a dashboard widget, called Deep Sleep that will do the trick do. Somehow it does not work on my MacBook Pro.


Resuna said...

Since Security Update 2008-005 neither DeepSleep nor my own script using pmset seem to work. I don't know what DeepSleep is using (I've wondered about that) but mine uses Applescript 'tell Application "Finder" to Sleep' and that seems to have no effect any more.

Sven said...

Use this hibernation tool.

It still works after the Security Update 2008-005 and does not need administrative rights.

Resuna said...

That script and tool are all doing exactly what my own script does.

Elizabeth said...

you are awesome! i just got the new macbook (the macbook white since my old one's hard drive died recently and was determined to figure out how to make my computer hibernate this time. this solution worked perfectly.

Sejanus said...

Works on MacBook Pro 2.16GHz / 10.5.5.

Thanks for the tip :-)))

Conan said...

That hibernation tool worked on a MacBook (aluminum 13") OS X 10.5.6.

Powered on with no battery, hibernated, inserted battery, disconnect power cord, powered up successfully all all prior apps still there.

inetwiz said...

Deep Sleep is a great tool, highly recommended.

Anonymous said...
This comment has been removed by a blog administrator.
steven said...

I have a black macbook (the latest one, right before the aluminum) and I tried setting mine up to hibernate (both with secure memory and without). In either case, it will work perfectly the first time, but unless I restart, the next time I hibernate it will fail. The white sleep light will stay on, and the screen will stay on with a blank black screen, and I have to do a hard reset. Does anyone have any information on this? Thanks.

Simone said...

Great tool, but how to enable the login screen if I suspend my laptop from the widget? Safety first, you know...

Alex said...

There is a DeepSleep Widget that will hibernate your Mac or MacBook with one click and it maintains regular sleep when you shut the lid. Check it out

Roland said...

works for me.

Trọng said...

I don't know what DeepSleep is using (I've wondered about that) but mine uses Applescript 'tell Application "Finder" to Sleep' and that seems to have no effect any more.
online bingoSightline Payments

jaume.llarden said...

On a MacBook Pro 15" (early 2011) with 10.6.8 I use:

alias hoff='sudo pmset -a hibernatemode 3'
alias hon='sudo pmset -a hibernatemode 25'

**Check pmset arguments with 'man pmset' !!**

Carl-Erik said...

Great post, but it might be a bit outdated. At least the values for pmset are, as they did not work when I just tried them.

The values that jaume.llarden provided did work however (25, not 5, sets suspend to disk), and reading up on the man page, they also seem correct.

I wrote a script for anyone interested, that will immediately suspend you computer to disk and restore whatever sleep settings you had set earler on after resuming.

I uploaded it at pastebin:
hibernate for os x

mahasiswa teladan said...

hi...Im student from Informatics engineering nice article,
thanks for sharing :)

Jesús López González said...

Works on iMac 21" with Yosemite OS (10.10.2). Thanks