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

  • 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 ;)
  • Mai
    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?
  • max13
    Than I put pmset -g | grep hibernate in terminal, It's return me nothing. What should I do to fix that?
  • 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.
  • 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.
  • 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
  • Tom G
    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.
  • Fabio
    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?
  • Eileen
    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
  • 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/
  • James
    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.
  • Sidu
    Or, just use "SmartSleep"
  • 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.
  • sam smiht
    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!
  • philou
    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)
  • waine
    May I advise you "smartsleep" (http://www.jinx.de/SmartSleep.html) - and you'll find a sleep, eventually.

    best,
    waine
  • Sunnz
    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
  • Mark B
    "I’m having trouble finding that file."

    There is no .bash_profile by default with Leopard. Just touch ~/.bash_profile and your done.
  • Andreas
    excellent tweak!
  • Ed
    .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
  • Patrick
    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!
  • Ed
    Check to see if you're using Secure Virtual Memory (System Prefs -> Security) and then set hibernatemode back to 3 or 7
  • Vahan Hartooni
    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)
blog comments powered by Disqus