Hibernation and Sleep
Mac users have become quite familiar with using Sleep mode. In Sleep mode, Macs go into a very low-power mode, while saving the current session for later use. Putting a Mac to sleep will continue to power RAM in sleep mode, so that whatever was in RAM when the computer went to sleep will still be there when the computer wakes. Sleep mode is almost instantaneous, consumes very low power, and as a PowerBook owner its indispensable to me. Still though, it requires a power-source (however low) and there are times when laptop batteries are completely depleted or a user wants to completely power-off their Mac.
Similar to Sleep, Windows “Hibernates,” while Linux “Software Suspends”. They are not as fast as Sleep mode, but they take it a step further by not using any power. When Hibernating, a PC quickly saves the current session to the hard drive, shuts-down, and completely powers-off the computer. Upon powering-on, the user is quickly returns to the previous session.
Up until recently, Mac users didn’t have a similar Sleep mode which required no power. When Apple announced new PowerBooks in October 2005, it also introduced Safe Sleep to Mac OS X, an extention to Sleep mode that allows for hibernation without power.
According to an Apple article:
Safe Sleep ensures that data stored in main memory will not be lost should the system shut down due to a loss of power during sleep mode. Prior to your system entering sleep, Safe Sleep automatically saves the contents of main memory […] to the hard drive. In the event the battery becomes completely depleted while the system is asleep, the computer will shut down. But when a power adapter is connected or a freshly charged battery is installed, the PowerBook can be restarted and it will automatically return to the desktop state that existed prior to entering sleep.
When restarting a PowerBook from Safe Sleep, a progress bar indicates that the PowerBook is waking from Safe Sleep. The screen is also in gray-scale and slightly blured. It is impossible to get an actual screen-shot of this, so I’ve created the following renderings:
How to Enable Safe Sleep
Safe Sleep is so-far only officially available on the new PowerBooks. But Safe Sleep is very much software based , not hardware based. With Apple’s release of Mac OS 10.4.3, Safe Sleep can be enabled on many Macs thanks to an excellent hack. To enable Safe Sleep you must be running Mac OS X Tiger, and be up-to-date to with version 10.4.3 (or above).
Reportedly working laptops include (but not necessarily limited to) iBook G4s, Aluminum PowerBook G4s. You may also try Safe Sleep on desktops. For a much more technical look into enabling it, visit the source information on the hack.
Warning: Enabling Safe Sleep is essentially a hack. It is very likely to work on recent Macs, but enabling Safe Sleep may not work as intended or wake your Mac properly. Print out this article before continuing, so that you can discard Safe Sleep and undo changes if needed.
1. Apply Safe Sleep Property
To summarize, new PowerBooks have the “has-safe-sleep” property. To apply this property to your Mac, something needs to be run in Open Firmware at boot. In the Terminal enter the folling, hitting return at the end of each line:
sudo nvram nvramrc='" /" select-dev " msh" encode-string " has-safe-sleep" property unselect ' sudo nvram "use-nvramrc?"=true
In a Terminal shell it should look as follow:
Last login: Fri Nov 11 11:11:11 on ttyp1 Welcome to Darwin! computer:~ User$ sudo nvram nvramrc='" /" select-dev > " msh" encode-string " has-safe-sleep" property > unselect > ' computer:~ User$ sudo nvram "use-nvramrc?"=true
The Mac must be restarted to set the changes.
2. Allow Hibernate Mode
To continue, you must have at least as much free disk space as physical memory , plus 750MB. To enable Sleep Safe, in the Terminal enter:
sudo pmset -a hibernatemode 3
This should create the file /var/vm/sleepimage.
If (and only if) you have secure virtual memory enabled, enter 7 (rather than 3) to disable encrypted hibernation. Encrypted Safe Sleep does not yet work.
When your Mac is set to sleep, it will now enter regular Sleep mode first (consuming minimal power). It will only enter Safe-Sleep if the battery is very low on power, or is unpluged. If you prefer to skip regular sleep, and use Safe Sleep mode instead (note: it takes a few seconds more to sleep and wake-up) enter:
sudo pmset -a hibernatemode 1
Enter 5 (rather than 1) with secure virtual memory.
To disable Safe Sleep:
sudo pmset -a hibernatemode 0
The Mac does not need to be restarted to set the changes to hibernate mode.
What is secure virtual memory?
Secure virtual memory is a software feature that encrypts your swap-files and sleep-image. The option is found in the Security pane in System Preferences. It is not enabled by default, and is does not need to be enabled to use Safe Sleep. In-fact, encrypted Safe Sleep appears to not yet work.
3. Verify Sleeping
Put the Mac to sleep and wait for the light to start pulsing. Wait a few more seconds. Wake it normally (by hitting the space bar for example).
Open Console and view system.log, or simply open the file /var/log/system.log. Look for a line indicating that the process worked. It is similar to:
Nov 11 12:15:33 computername kernel: System SafeSleep
4. Verify Safe Sleep
Now attempt to actually Safe Sleep for real. Put the Mac to Sleep, and wait for the light to start pulsing. Remove the power-source plug and the battery. Wait for the light to stop pulsing and turn off, which may take a a couple of minutes. Your Mac should now be in Safe Sleep mode. Plug the power back in and add the battery. Start-up. It should show the previous saved desktop (blurred and in grayscale) along with a progress bar as pictured above. The system should be back to the way you left it.
Safety: To be safe, don’t use FireWire target disk mode on a Mac that is in Safe Sleep/hibernation, since you may end up with filesystem corruption.
You may have problems with a bad hibernate images, which may repeatedly kernel panic. Try restarting which will start the image again. It may work. It may not, and repeatedly fail. This can happen if you don’t set “hibernatemode” properly when using secure virtual memory. If a bad hibernate image keeps booting then crashing reboot the mac holding down Command-Option-O-F to get in to Open Firmware. Type:
Hit return, then enter:
Disable Safe Sleep
To disable Safe Sleep enter in the Terminal:
sudo pmset -a hibernatemode 0
No need to restart.
For a more full undo, disable all nvramrc variables:
sudo nvram "use-nvramrc?"=false
Enter password, then restart.
Safe sleep isn’t perfect yet for all users. Safe Sleep should really only serve as a backup to regular Sleep, for times when the laptop battery is depleted or you need to unplug and move your desktop.
You should not use Safe Sleep as a replacement to regular Sleep. Regular Sleep is much faster, and uses very little power.It take about 15 seconds to enter Safe Sleep, and about 40 seconds to wake-up from it. That is much longer than the 2 seconds it takes for regular Sleep and wake-up.
Safe Sleep seems very promising though and it will be interesting to see if Apple officially supports it with older laptops.
[Updated on Nov 14, 2005 with wording changes and info on secure virtual ram.] [Updated on Nov 15, 2005 with warning on using target disk mode.]