Does Mac OS X support hibernation?

40

23

On Windows, you can hibernate your computer, so that it starts a lot faster while consuming zero energy while "hibernating".

I see an option to Sleep on my Mac mini but not hibernate. Does Mac support hibernation?

I am on Leopard.

AngryHacker

Posted 2009-10-22T23:59:48.320

Reputation: 14 731

Answers

34

OS X only has only one "sleep" option. You cannot change its name, but to change its behaviour, I use an old version of SmartSleep on a Mac mini (though in the MacBook-like "sleep & hibernate" mode). It works for a mini, though the website only refers to MacBooks.

(SmartSleep was still free when I wrote this in 2009.)

I occasionally get complains about hardware not having been removed properly (but OS X never tells me what hardware, and my Time Machine USB disks seem fine — I should peek into the logs one day, and I assume this is related to OS X, not to SmartSleep).

I've quickly tested SmartSleep's "hibernate only" on that mini (Intel; running 10.5), and it seems to work as well. Doing these tests, I noticed that after the display goes black the power light starts pulsing (like to indicate sleep rather than hibernate) for a few seconds. Maybe it's still writing RAM to disk then. (Until now, I always thought that on my MacBook the pulsing indicated that all was done. But now I think that, whichever sleep mode one is using, one should probably not unplug the power too soon). After a short while, it powers down completely.

In 2006, Macworld explains how to achieve the same without that SmartSleep preference pane. To check the current setup:

pmset -g | grep hibernatemode

According to Macworld's old article the following applies, but be sure to read Lauri's answer that suggests that nowadays only 0, 3 and 25 should be used instead:

  • 0 — Old style sleep mode, with RAM powered on while sleeping, safe sleep disabled, and super-fast wake.
  • 1 — Hibernation mode, with RAM contents written to disk, system totally shut down while “sleeping,” and slower wake up, due to reading the contents of RAM off the hard drive.
  • 3 — The default mode on machines introduced since about fall 2005. RAM is powered on while sleeping, but RAM contents are also written to disk before sleeping. In the event of total power loss, the system enters hibernation mode automatically.
  • 5 — This is the same as mode 1, but it’s for those using secure virtual memory (in System Preferences » Security).
  • 7 — This is the same as mode 3, but it’s for those using secure virtual memory.

And the same numbers can be used to change the sleep mode setting:

sudo pmset -a hibernatemode 1

Arjan

Posted 2009-10-22T23:59:48.320

Reputation: 29 084

11

I wrote a script that will let you enter hibernation immediately (without changing your settings permanently). I find it quite useful, as I like the default settings, but want to forcibly enter hibernation when on the road. Maybe someone else will find it useful too ;-)

#!/bin/bash

# Utility to force your mac immediately into hibernation mode/suspend to disk,
# thus conserving battery considerably (at the cost of slower startup)
# @date 2012-02-10
# @author Carl-Erik Kopseng. Contact at oligofren.wordpress.com

# must be run as root by using sudo or to avoid entering the password, change the pmset
# executable settings by entering
# sudo chmod +s /usr/bin/pmset
# sudo chmod +s /sbin/shutdown

MODE_BACKUP=/tmp/hibernate_mode.bak
SUSPEND_TO_DISK=25 #see man pmset

display_settings() {
    echo "Current settings: " $(pmset -g | grep hibernatemode)
}

save_settings() {
    echo "saving settings"
    pmset -g | grep hibernatemode | awk '{print $2}' > $MODE_BACKUP
}

restore_settings() {
    echo "restoring settings"
    pmset -a hibernatemode $(cat $MODE_BACKUP)
}

set_only_disk_hibernate() {
    echo "changing settings to only suspend to disk (slow, but does not use battery)"
    pmset -a hibernatemode $SUSPEND_TO_DISK
}

hibernate() {
    echo "going into hibernation"
    shutdown -s now
}

save_settings
set_only_disk_hibernate && hibernate
restore_settings

Adding to the Menu Bar

If you want to invoke this script from the Menu Bar ("systray"), I would:

  1. Put this script in a suitable location (like /usr/local/sbin/).
  2. Create an AppleScript that simply invokes this script. Call it "Hibernate"
  3. Add your apple scripts as an icon in the Menu Bar

Now you can trigger the script by clicking the Menu Bar->AppleScripts->Hibernate

oligofren

Posted 2009-10-22T23:59:48.320

Reputation: 842

Please make a systray version. – qed – 2014-10-09T20:46:40.383

Hi, thanks for the comments. Unfortunately, the newer MacBook Pro I got in 2013 has way better standby performance than my previous mac, and keeps its battery life much better. So there's unfortunately little insentive for me to go ahead and learn Cocoa for making a systray version anymore. I'll remove that sentence now. – oligofren – 2014-10-10T11:58:36.373

This is very interesting, how does it work? Does shutdown -s now not take effect immediately? – SilverWolf - Reinstate Monica – 2018-05-31T17:04:40.437

First it saves the old settings, then it sets the new settings to take effect on shutdown, then calls shutdown (now using its new settings), which suspends the script. Once the computer resumes, so does the script, which then proceeds to restore its old settings – oligofren – 2018-05-31T17:45:29.127

good script sir ! can a systray version be done with automator/applescript ? – leetbacoon – 2019-10-18T11:08:09.903

1@leetbacoon added instructions for adding this to the Menu Bar. I haven't owned a Mac in a couple of years, so I can't paste any screenshots ... – oligofren – 2019-10-18T13:38:43.450

good work my friend @oligofren (: – leetbacoon – 2019-10-19T05:44:51.513

1please, make a systray version :) – DataGreed – 2013-07-10T20:57:50.140

9

The pmset man page also recommends using 25 instead of 1.

0000 1000 (bit 3) encourages the dynamic pager to page out inactive pages prior to hibernation, for a smaller memory footprint.

0001 0000 (bit 4) encourages the dynamic pager to page out more aggressively prior to hibernation, for a smaller memory footprint.

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 set- tings. For your sake and mine, please don't use anything other 0, 3, or 25.

[...]

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.

Some laptops now enter hibernation (standby mode) after about an hour of normal sleep if:

  • Power Nap is not enabled (so not by default)
  • The computer is on battery power
  • The computer is not connected to USB devices or external displays and not paired with Bluetooth devices

Laptops, Mac minis and iMacs use about 0.2-0.4 W when off or hibernating and 0.8-1.4 W in sleep mode. Hibernation (and the hibernation + sleep mode that laptops use by default) might also reduce the lifespan of drives.

Lri

Posted 2009-10-22T23:59:48.320

Reputation: 34 501

6

And for OS X Lion this works better for Hibernation

sudo pmset -a hibernationmode 25

than

sudo pmset -a hibernationmode 1

as hibernationmode 1 can cause crashes for some reason.

Willem

Posted 2009-10-22T23:59:48.320

Reputation: 544

What exactly does 25 stand for? – qed – 2014-10-09T20:48:03.383

25 is binary for 0001 1001 which means that bits 4, 3 and 0 are set (the three 1:s). Those three bits all tell your computer different things. Bit 0 (0000 0001) tells your computer to activate hibernation (which means saving memory to disk before shutting down). Bit 3 (0000 1000) tells your computer to clean out the memory of old junk before saving it to disk (to make it have to save less stuff to disk). Bit 4 (0001 0000) tells your computer to be more aggressive while cleaning out the memory (allowing it to save even less stuff to disk). – Willem – 2014-10-10T19:06:13.820

5

For answers which rely on twiddling the 'hibernatemode' via pmset, it's useful to note that the 'force' option on pmset makes the changes transient. The setting won't be remembered when the system wakes up from hibernation. For example:

pmset -a hibernatemode 25 force

Will change the hibernate mode to represent a traditional hibernate (i.e. system state written to disk and power removed) but only until the next time the system is powered on or the settings are read from disk (pmset touch).

Using the force option avoids the need to save and restore current hibernatemode settings.

user210274

Posted 2009-10-22T23:59:48.320

Reputation: 51

Great tip! You can edit my answer if you bother too :) – oligofren – 2013-07-11T11:14:49.203

3

yup. it's called safe sleep. easiest way to get it is to use the deep sleep widget.

yanokwa

Posted 2009-10-22T23:59:48.320

Reputation: 2 156

2I hate widgets with a passion. Is there something non-widgety? – AngryHacker – 2009-10-23T05:07:09.473

1For laptop owners the easiest way is to close the lid. Apple menu in the upper left corner also has ,,sleep'' option (at least on my Tiger). – Tadeusz A. Kadłubowski – 2009-10-29T18:03:50.703

3

Hibernation will also be triggered automatically if your laptop battery runs down completely.

Bob D

Posted 2009-10-22T23:59:48.320

Reputation: 468

2A Mac mini has no battery... – Arjan – 2009-10-29T17:00:32.283

2

I have read that "Safe Sleep" is on by default on all Intel Macs and some late model PowerPC machines (I think the Intel mini's have this support, but the PPC ones probably do not—without unsupported hacks).

But "Safe Sleep" by itself is not exactly the same as "hibernation". It is a combination of saving RAM to disk but also doing a normal sleep. This allows for a fast wake, and also preserves the system state if the power happens to fail completely while the machine is sleeping.

You can tell if a system is using Safe Sleep by (after at least one sleep) checking for a file /var/vm/sleepimage that is the same size as the installed RAM. Also when Safe Sleep is active there will be a longer delay between clicking the Sleep menu item (or button, or holding Command-Option-Eject) before the machine's status light starts its normal fade-up/fade-down loop.

The final bit of the solution is to get the machine to fully power off after saving RAM the sleepimage. It seems like it is possible to configure this using the command-line program pmset to set the hibernatemode. You might checkout something like Deep Sleep for an automated way of making this configuration change.

Chris Johnsen

Posted 2009-10-22T23:59:48.320

Reputation: 31 786

Safe sleep was not on by default on my Intel Mac mini. I used SmartSleep to enable it, but indeed pmset can achieve the same. – Arjan – 2009-10-29T18:29:57.080