How to Safe Sleep (Hibernate) Your Mac
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.
Safe Sleep
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.
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 do so first insure Mac OS X, is up-to-date to with version 10.4.3 (or above). If not, run Software Update.
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 cause your Mac to explode, implode, melt, freeze, have a heart-attack, or develop an inguinal hernia.
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
If you have secure virtual memory enabled, use 7 rather than 3 to disable encrypted hibernation. Encrypted hibernation does not work. Do not set it to 7 if you do not have secure virtual memory.
This should create the file /var/vm/sleepimage.
When your Mac is set to sleep, it will now enter regular Sleep mode (consuming minimal power) first. If you prefer to enter Safe Sleep mode directly (note: it takes a few seconds more to sleep and wake-up) then instead enter:
sudo pmset -a hibernatemode 1
Use 5 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.
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[0]: 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.
Troubleshooting
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 with secure virtual memory (try alternating between 1+5 or 3+7). 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:
setenv boot-image
Hit return, then enter:
boot
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.
Conclusion
Now that Safe Sleep is working for me, I have set my PowerBook to use Safe Sleep, instead of just regular Sleep mode that consumes power. It take about 15 seconds to enter Safe Sleep, and about 40 seconds to wake-up from it. That is way 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 supports it with older laptops.