Hibernate between OS X and Bootcamp Win 7

Solution 1:

It is not possible to do this the way you are thinking. The problem lies in the tight integration of Apple's firmware and OS X. OS X and the firmware work with each other to determine the sleep state of the computer.

When Windows hibernates, it dumps the contents of RAM to C:\Hiberfil.sys and sets a flag in the registry that the machine is hibernated. When you first boot a Windows machine, the boot sector code loads the BCD file, which loads that portion of the registry very early in the boot process and sees that the system is hibernated. After performing a basic sanity check, it loads hiberfil.sys back into memory. The important thing here is that all all of this is contained within the filesystem. This is why you can freely boot to OS X, then boot again back to Windows and it will continue to resume from the hibernation file.

The same is not true of OS X. When OS X hibernates, it dumps the contents of RAM to /var/vm/sleepimage the same way Windows does. But it saves the hibernation flag in the PRAM, not the filesystem (the setting is called IORegistryCurrentSleepMode if you're interested). When you turn a Mac back on, the values in PRAM are read before an attempt is even made to boot to the OS. If the flag indicates that the system is hibernated, the first thing it does is flip it back to a normal status. The firmware then immediately boots the system and ignores the Startup Disk preference and any attempts to Option+boot. You don't even get a startup chime. On a Mac, the firmware contains all the logic needed to inspect the filesystem and boot the OS. It does not need boot code the way Windows does.

When you throw rEFIt into the mix, it inserts itself into the process. It replaces the normal /System/Library/CoreServices/boot.efi (which is OS X's boot loader), with its own boot loader file. This is where things get fuzzy for me because this is all Apple proprietary stuff, but the bottom line is that when the firmware is booting OS X, it passes whatever arguments needed to load /var/vm/sleepimage instead of the normal Darwin kernel. rEFIt does not do this properly with Lion and later. But regardless of whether it's an older version of OS X or a newer one, the firmware has already flipped the hibernation bit before rEFIt even loads. This is why resuming OS X from hibernate is no longer possible after the first power-on.