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!

Saturday, 8 October 2011

So long Steve and thanks for all the Lulz

5th October was a sad day - Steve Jobs passed away.


I was walking through the Apple Store yesterday and although I had been thinking that Steve's biggest legacy was his contribution to defining the PC market as it is today, something else struck me.  Upstairs a grandmother with her grandson was setting up her first iPad 2, helped by an Apple Store employee.  I walked downstairs and passed an iPad 2 demonstration.  The audience was full of people aged between 60 and 70, all following along on their iPads.  


When I got home, my daughter was playing her games on her iPad - working with the touch screen like she had been born with it.


I think Steve's legacy was really his ability to make technology and communication span generations and make the experience accessable to all.  I'm not sure we have anyone to take his place.  RIP Steve.