Monday 10 October 2011

MacBook Air and Filevault 2 won't sleep together

I've just got a new MacBook Air and I'm not sure if it is mourning Steve's passing last week :( but I've been having a lot of trouble getting it to wake up from hibernate. Hibernate is the state that (by default) the computer will go into when it runs out of battery (after the reserve power warning appears).

In this state it will immediately write the contents of memory to a swapfile on the solid state storage - by default to /var/vm/sleepimage. My theory is that there is a race condition with Filevault that may corrupt the memory image whilst both processes try to do their stuff on the storage. When the MacBook is plugged into a power source and the power button is pressed, the backlight lights but the screen stays black. I can see the backlight through the Apple logo on the lid. It stays in this state forever and needs to be hard reset by holding power for 10 seconds, releasing and pressing it again to switch the computer back on.

I actually brought the MacBook Air back to the Apple Store and got a replacement which exhibits the same problem, so with the second one I did a little bit of experimentation to narrow down on the root cause. I did the following -
  1. A complete Lion clean install (Command-R at bootup).
  2. Let the battery run dry, MacBook Air hibernates and wakes successfully after applying power.
  3. Applied Filevault.
  4. Let the battery run dry, MacBook Air hibernates and crashes on wake after applying power.
  5. Reset both PRAM and the SMC - neither helped.
It's pretty clear Filevault is the problem.

The Workaround

To work around this until Apple (hopefully) fix what is quite a glaring problem (happened on 2 MacBook Airs for me) it is possible to turn off hibernation. This means that the machine will only sleep - contents of memory remain in RAM which remains powered for as long as the battery holds up. Remember, this differs from "SafeSleep" or hibernate - it persists memory to flash storage so that even if the battery runs out, the memory image can be restored and you can just carry on with your work.
  • First off, check your existing hibernate mode (it will usually be 3 - the default)
Open a Terminal window and type -

sudo pmset -g | grep hibernatemode
Password: <enter password>
hibernatemode 3
  • Look at the man page for pmset to see the valid hibernate modes -

    man pmset

    The relevant part -

    We do not recommend modifying hibernation settings. Any changes you make are not supported. If you choose to do so anyway, we recommend using one of these three settings. For your sake and mine, please don't use anything other 0, 3, or 25.

    hibernatemode = 0 (binary 0000) by default on supported desktops. The system will not back memory up to persistent storage. The system must wake from the contents of memory; the system will lose context on power loss. This is, historically, plain old sleep.


    hibernatemode = 3 (binary 0011) by default on supported portables. The system will store a copy of memory to persistent storage (the disk), and will power memory during sleep. The system will wake from memory, unless a power loss forces it to restore from disk image.


    hibernatemode = 25 (binary 0001 1001) is only settable via pmset. The system will store a copy of memory to persistent storage (the disk), and will remove power to memory. The system will restore from disk image. If you want "hibernation" - slower sleeps, slower wakes, and better battery life, you should use this setting.

  • The crash happens for both hibernatemode 3 and 25 (I've tested both). To set hibernatemode to 0 (i.e. turn it off) use the following command -

    sudo pmset -a hibernatemode 0

  • And to switch it back to the default -

    sudo pmset -a hibernatemode 3
Hopefully Apple fix this one soon. With the workaround about just bear in mind that if you go into sleep after the reserve power warning you will have some leeway to get to power, but don't leave it a really long time otherwise you could end up losing work. Best to save if you hit reserve power anyway.

As a side effect of this change it is possible to remove the safe sleep image (which is exactly the size of the memory on your MacBook Air) as obviously Lion won't write to it with hibernation turned off -

sudo rm /var/vm/sleepimage

All these steps at your own risk, but it works for me. Other posts on this topic can be found here -

Apple Discussion 1
Apple Discussion 2

UPDATE Should have mentioned that this testing was done on Mac OS X Version 10.7.1 and I've tested hibernatemode 3 on 10.7.2 and see the same behaviour - so no bug fix yet :(

UPDATE Bug filed at the Apple Bug Reporter (#10288882)

UPDATE Macbook Air EFI 2.3 fixed this issue for me!

12 comments:

  1. I have this same issue. I hope it is fixed with an EFI update and/or 10.7.3.

    ReplyDelete
  2. Did the Macbook Air EFI 2.3 fix this issue?

    ReplyDelete
  3. I'm not sure but I'll give it a test today and report back.

    ReplyDelete
  4. @Tim @Joe
    It seems to be fixed in EFI update 2.2 - see the post update.

    ReplyDelete
  5. I have this problem since the first day I bought my macbook air 2011, EFI 2.2 did not fix this issue for me. Any ideas?

    ReplyDelete
  6. update: i have done a reset to the nvram and smc and my air 2011 is now recovering from hibernation correctly.

    ReplyDelete
  7. unhappy customer7 December 2011 at 16:57

    have same issue. Apple was not able to identify it after repairs (exchanged logic board, then exchanged SSD).
    opened again new case. after 3 weeks the response is technicians are working on it. premium product for premium price - so do I want have it. Thinking about returning it back, especially since it's 1/2 year through since MBA2011 release and next MBA generation lines up already in 2012 according to usual websites. I bought an MBA, which was not acceptable to use since 4 months (including waiting times for the repair roundtrips) - really unhappy and p...ed.

    ReplyDelete
  8. Technology changes over the years and so does the process to be able to accommodate those changes. heat exchanger

    ReplyDelete
  9. MacBook and MacBook Air just aren't powerful enough for most modern games, though could be enough if you only want to play older titles or less intensive indie games. qual macbook comprar

    ReplyDelete
  10. At five to seven hours of uninterrupted use, it becomes possible to turn any location into your own personal office. While most laptops' actual performance time off the cord is around 2-3 hours, what the MacBook promises, it actually delivers. how to speed up mac, clean my mac

    ReplyDelete
  11. Nothing beats the performance of a brand new Mac. It's quick to load up, and can tackle multiple tasks with ease clean my mac pro

    ReplyDelete
  12. During the test I used everyday apps like Microsoft words and Safari. To mix things up some light 3D work was thrown into the mix.https://www.targetlaptop.com/best-laptops-for-college-student/

    ReplyDelete