Make my Macbook Pro Hibernate

Filed Under Apple on 2008-02-25, 08:41

Bunki suspends to RAM to enable quick startup

I don’t like to waste battery life, especially when traveling. I love the Hibernate feature in Windows, and have all of my laptops set to hibernate when the lid is closed. The few extra seconds it takes to wake up is worth the saved battery life in my eyes. For those that don’t know here are the different states of the Macbook Pro:

  • On – Computer is awake, screen is on, battery is being consumed based on your power settings
  • Off – Computer is using no power from the battery
  • Sleep – Computer has turned off the screen and has suspended the operating system to RAM (volatile memory).
  • Hibernation – Computer has turned off most hardware and has suspended the operating system to the harddrive

Usually when you close the lid of your MBP, it will be put to sleep, and wake up quite quickly when you open the lid again. While it’s sleeping it’s still consuming battery power, albeit a small amount compared to normal usage. When the battery reaches a certain low level, the MBP will automatically switch to hibernation mode and basically shut off so you don’t lose any of your work. Sleep is great for when you’re actively using your computer, but when you want to stretch out battery life for as long as possible, you want to hibernate. Also to note is that it appears that the newer Macbook Pros also write information to the harddrive when sleeping so that when the battery drops to dangerous levels it can jump instantly into hibernation. Apple calls this “Safe Sleep”. (More info on all the technical stuff here)

A few examples of why you would want to hibernate with your laptop:

  • You’re about to head to the airport on an international flight and you want to use your machine during the flight but still leave enough juice to be able to pull up a map/email/info when you get to your destination.
  • You toss your laptop in a bag and may or may not use it on a weekend trip but don’t want to worry about charging it.
  • You want to conserve every little bit of power you can.

And when you would want to stick with sleep:

  • Your laptop isn’t running off battery power
  • You will be opening and closing your lid quite often
  • You’re running around but actively using your laptop (conferences, meetings, etc.)

Basically you sacrifice the speed of restoring your machine to gain a little bit of battery power or vice versa. Personally I like to get every last bit of electricity that I can.

After some searching I came across a post that explained how to basically force your MBP into hibernation when the lid is closed. It requires a quick bit of work in terminal, but is painfully simple.

In Terminal/iTerm/etc run the following command to determine your current sleep mode:
pmset -g | grep hibernate

This should return one of the following:

  • 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”.

Now edit and save your /Users/username/.bash_profile file with the following lines:

alias hibernateon="sudo pmset -a hibernatemode 5"
alias hibernateoff="sudo pmset -a hibernatemode 0"

hibernateon and hibernateoff can be any text you want, you just need to remember what you used

Execute the following:

source .bash_profile

Now you have a handy little command that will let you enable and disable instant hibernation on a whim. Whenever you want your machine to hibernate when you close the lid, just drop to a terminal window and type “hibernateon”. When you’d prefer your laptop to just sleep, type “hibernateoff”.

Tagged: ,


Comments

View Comments to “Make my Macbook Pro Hibernate”

  1. Vahan Hartooni on March 19th, 2008 9:22 pm

    So if I ever want to set everything to default, I just set the hibernate to 3, right? (BTW I’m using the MacBook Pro w/ core 2 duo)

  2. Vahan Hartooni on March 20th, 2008 12:22 am

    So if I ever want to set everything to default, I just set the hibernate to 3, right? (BTW I'm using the MacBook Pro w/ core 2 duo)

  3. Ed on March 20th, 2008 12:59 pm

    Check to see if you’re using Secure Virtual Memory (System Prefs -> Security) and then set hibernatemode back to 3 or 7

  4. Ed on March 20th, 2008 3:59 pm

    Check to see if you're using Secure Virtual Memory (System Prefs -> Security) and then set hibernatemode back to 3 or 7

  5. Patrick on April 7th, 2008 10:35 am

    Could you please explain this step in more detail:

    Now edit and save your /Users/username/.bash_profile file with the following lines:

    alias hibernateon=”sudo pmset -a hibernatemode 5″
    alias hibernateoff=”sudo pmset -a hibernatemode 0″

    I’m having trouble finding that file.

    Thanks!

  6. Ed on April 7th, 2008 10:52 am

    .bash_profile (notice the period) is a “hidden” file in your home directory. Try the following command:

    pico ~/.bash_profile

    and then add the two alias lines

  7. Patrick on April 7th, 2008 1:35 pm

    Could you please explain this step in more detail:

    Now edit and save your /Users/username/.bash_profile file with the following lines:

    alias hibernateon=”sudo pmset -a hibernatemode 5″
    alias hibernateoff=”sudo pmset -a hibernatemode 0″

    I'm having trouble finding that file.

    Thanks!

  8. Ed on April 7th, 2008 1:52 pm

    .bash_profile (notice the period) is a “hidden” file in your home directory. Try the following command:

    pico ~/.bash_profile

    and then add the two alias lines

  9. Andreas on April 15th, 2008 2:03 pm

    excellent tweak!

  10. Andreas on April 15th, 2008 5:03 pm

    excellent tweak!

  11. Mark B on April 15th, 2008 8:11 pm

    “I’m having trouble finding that file.”

    There is no .bash_profile by default with Leopard. Just touch ~/.bash_profile and your done.

  12. Mark B on April 15th, 2008 11:11 pm

    “I’m having trouble finding that file.”

    There is no .bash_profile by default with Leopard. Just touch ~/.bash_profile and your done.

  13. Sunnz on April 29th, 2008 9:16 am

    It also works if you put it in ~/.profile which comes with Leopard/Tiger by default. I guess it is a BSD thing… all both OpenBSD and FreeBSD had its default shell reading ~/.profile

  14. Sunnz on April 29th, 2008 12:16 pm

    It also works if you put it in ~/.profile which comes with Leopard/Tiger by default. I guess it is a BSD thing… all both OpenBSD and FreeBSD had its default shell reading ~/.profile

  15. waine on May 15th, 2008 10:44 am

    May I advise you “smartsleep” (http://www.jinx.de/SmartSleep.html) – and you’ll find a sleep, eventually.

    best,
    waine

  16. waine on May 15th, 2008 1:44 pm

    May I advise you “smartsleep” (http://www.jinx.de/SmartSleep.html) – and you'll find a sleep, eventually.

    best,
    waine

  17. philou on July 6th, 2008 3:57 am

    Thanks waine for the very useful SmartSleep app.

    I found another tiny cool tool to disable the sleep mode on Apple Laptops. Works also if You close the lid of your machine. InsomniaX is also able to change the sleep mode very easy and quick and You can set a hotkey to enable and disable the tool…

    http://semaja2.net/insomniaxinfo/

    Hope it’d be useful to all of You :)

    Greetings from Berlin (Germany)

  18. philou on July 6th, 2008 6:57 am

    Thanks waine for the very useful SmartSleep app.

    I found another tiny cool tool to disable the sleep mode on Apple Laptops. Works also if You close the lid of your machine. InsomniaX is also able to change the sleep mode very easy and quick and You can set a hotkey to enable and disable the tool…

    http://semaja2.net/insomniaxinfo/

    Hope it'd be useful to all of You :)

    Greetings from Berlin (Germany)

  19. sam smiht on July 16th, 2008 3:38 pm

    I have just bought a MacBook Air!

    No option to hibernate,and all this command line stuff to achieve what is a menu option in windows and has been for years in windows!

    Boy these things are supposed to be easy on a mac

    A Joke! P.S. I am a .NET programmer, but things should be easy.

    Apple add a simple hibernate option in menu!

  20. sam smiht on July 16th, 2008 6:38 pm

    I have just bought a MacBook Air!

    No option to hibernate,and all this command line stuff to achieve what is a menu option in windows and has been for years in windows!

    Boy these things are supposed to be easy on a mac

    A Joke! P.S. I am a .NET programmer, but things should be easy.

    Apple add a simple hibernate option in menu!

  21. Jonathan on July 20th, 2008 12:16 am

    I am doing this with both my windows and mac machines and in windows it necessary to shut it down once a month atleast to clear system cache to speed up the performance. In mac, there is no fear. You can always hibernate than shuting it down. It not only saves battery, but also reduces the startup delay.

  22. Jonathan on July 20th, 2008 3:16 am

    I am doing this with both my windows and mac machines and in windows it necessary to shut it down once a month atleast to clear system cache to speed up the performance. In mac, there is no fear. You can always hibernate than shuting it down. It not only saves battery, but also reduces the startup delay.

  23. Sidu on July 24th, 2008 9:17 am

    Or, just use “SmartSleep”

  24. Sidu on July 24th, 2008 12:17 pm

    Or, just use “SmartSleep”

  25. James on July 25th, 2008 4:20 am

    I just got my got MBP this past Monday. I came across your tip and it worked like a charm. Right now, I want to learn the little details about the Mac OS because I just swtiched from Windows. I am little shy in using programs like SmartSleep or InsomniaX just yet. So, please keep posting tips like this for others to find. Thank you.

  26. James on July 25th, 2008 7:20 am

    I just got my got MBP this past Monday. I came across your tip and it worked like a charm. Right now, I want to learn the little details about the Mac OS because I just swtiched from Windows. I am little shy in using programs like SmartSleep or InsomniaX just yet. So, please keep posting tips like this for others to find. Thank you.

  27. Sven on August 14th, 2008 12:35 pm

    This Hibernation Tool does not need any administrative rights and is easier to use in contrary to the “sudo” commands above:
    http://blog.kaputtendorf.de/2007/08/17/hibernation-tool-for-mac-os/

  28. Sven on August 14th, 2008 3:35 pm

    This Hibernation Tool does not need any administrative rights and is easier to use in contrary to the “sudo” commands above:
    http://blog.kaputtendorf.de/2007/08/17/hibernation-tool-for-mac-os/

  29. Eileen on August 28th, 2008 8:26 am

    sven,

    I downloaded that application that you suggested. I have always been a PC user and when I try and get out of hibernate, all I had to do was press a key to re-start the machine. I wasn't able to do that this time. How do I wake up my computer from hibernate mode using the tool you suggested above?

    Thanks,Eileen

  30. Fabio on January 14th, 2009 8:22 pm

    I am having some problem with hibernatemode on my macbook (10.5.6). I wrote the alias lines to my .bash_profile. the first time I put mac to hibernate it works fine, but, the second time the macbook doesn't hibernate, the screen turn off and the sleep light turn on .. so, I need to hold on Power button some seconds to power off and start it again … This happen just the second time, the first time works great … If I power off or restart the mac after the first time, I am able to hibernate again …

    Does somebody have some idea?

  31. Tom G on January 17th, 2009 5:58 pm

    I would try the Hibernation Tool mentioned above. It works great for single uses too since the script automatically reverts the sleep setting to 0. Otherwise the Smart Sleep preference pane works well too. As for the bash, I would try to rewrite the alias. That's a strange problem that I haven't seen myself. Anyway, options 1 and 2 are the simplest unless you really dig terminal.

  32. Mark Wheadon on February 2nd, 2009 4:06 am

    Or, if you'd like the machine to go back to its normal hibernate behaviour after it's been hibernated, without having to remember to run hibernateoff, then how about:

    http://www.markwheadon.com/blog/2009/01/hiberna...

    Cheers,

    Mark

  33. Detaer on June 5th, 2009 2:21 pm

    http://www.jinx.de/SmartSleep.html

    I have been using this, I am still looking for a single button to initiate hibernation rather than having to change system settings.

  34. Detaer on June 5th, 2009 2:22 pm

    Ohh look and here is an app to put the macbook directly to sleep!
    http://blog.kaputtendorf.de/2007/08/17/hibernat...
    Thanks for posting your link here Mark Wheadon, you are my epal.

  35. max13 on July 25th, 2009 6:59 am

    Than I put pmset -g | grep hibernate in terminal, It's return me nothing. What should I do to fix that?

  36. Mai on August 4th, 2009 3:35 am

    hmm so when i put in the last execute file it said no such file exists but when i typed in 'hibernateon' it still allowed me to hibernate…did i do something wrong?

  37. Osama Gamal on September 19th, 2009 8:30 pm

    I tweaked your command a little to satisfy my needs :D

    alias hibernate=”sudo pmset -a hibernatemode 5; sudo shutdown -s now && sudo pmset -a hibernatemode 3″

    Check my full article here: http://blog.osama-gma.net/?p=232

    Thanks, you helped me a lot ;)

  38. JP on March 24th, 2010 9:03 pm

    Worked like a gem – fast, easy, effective! Surprisingly so.

  39. Gerald on May 23rd, 2010 3:54 pm

    i used the link above …. http://semaja2.net/insomniaxinfo/ … and downloaded the app there. its muuuch simpler. it added an icon in my applications folder and all i do is click the icon there. it asks me “do you want to hibernate” and i click yes and boom it goes into hibernation. i have a macbook pro that i just bought a couple of days ago. this is my first mac and it is going very well for me.

  40. Gerald on May 23rd, 2010 10:54 pm

    i used the link above …. http://semaja2.net/insomniaxinfo/ … and downloaded the app there. its muuuch simpler. it added an icon in my applications folder and all i do is click the icon there. it asks me “do you want to hibernate” and i click yes and boom it goes into hibernation. i have a macbook pro that i just bought a couple of days ago. this is my first mac and it is going very well for me.

Leave a Reply




blog comments powered by Disqus