What is the Differences Between Sleep/Standby and Hibernate
Have you ever thought of what is the differences between Sleep and Hibernate options provided by Windows Vista shutdown function? Both commands provide a easy and quick way to leave your computer in existing last state and come back to work on it at exactly the same state later without waiting too long to system to restore itself. However, fundamentally there are significant different between them that allows users to easily choose whether they should use Sleep or Hibernate.
Sleep is commonly known as Standby in Windows system or S3 in ACPI. In Sleep mode, the power supply to non-essential and non-critical component is withheld, and most system operation is shutdown and stopped. All data in physical memory (RAM module) is still kept in internal memory, and whole system is place in stand-by mode, which can be woke up and used almost immediately. In Sleep mode, the power load reduce considerably, saving a lot of energy. However, the power must not be cut off, and must be continue to supply to the computer. Once out of power, the system will have to start again just like a newly boot computer just started from power off state.
Windows Vista has enhanced sleep mode so that on notebook computer, sleeping computer will automatically hibernate when battery power level is low. It also has built-in Hybrid Sleep mode which ensure that system state is preserved when there is power lost.
Hibernate, or S4 in ACPI, meanwhile will save the data in physical memory to hard disk drive (HDD), and then power off the computer. In Hibernate mode, a file named hiberfil.sys which has the same file size as the amount of system memory will be created on the local disk. When user wants to use the computer again, the computer will boot up and load back the state at the last hibernation. The advantage of Hibernation mode is that no power is wasted for maximum saving of power. In Hibernation dormancy, no electricity is consumed by system. Beside, restore from Hibernate is generally faster than computer reboot, and is totally different from fresh start, as users can return to the exact state of last hibernation with all programs running and documents opened intact, instead of empty desktop. The disadvantage of Hibernate is that after a period of time, there may have fragmentation of file. Users will need to defragment the volume that stores the hibernation file frequently.
ACPI(Advanced Configuration and Power Interface),即高级配置与电源接口,有以下几种模式:
S0 平常的工作状态。
S1 也称为POS(Power on Suspend),这时除了通过CPU时钟控制器将CPU关闭之外,其他的部件仍然正常工作。
S2 CPU处于停止运作状态,总线时钟也被关闭,但其余的设备仍然运转。
S3 除了内存外的部件都停止工作。
S4 内存信息写入硬盘,所有部件停止工作。
S5 关机。
待机(Standby),将系统切换到该模式后除了内存,电脑其他设备的供电都将中断,只有内存依靠电力维持着其中的数据。这样当希望恢复的时候,就可以直接恢复到待机前状态。这种模式并非完全不耗电,因此如果在待机状态下供电发生异常,那么下一次就只能重新开机,所以待机前未保存的数据都会丢失。但这种模式的恢复速度是最快的,一般五秒之内就可以恢复。
休眠(Hibernate),将系统切换到该模式后,系统会自动将内存中的数据全部转存到硬盘上一个休眠文件中,然后切断对所有设备的供电。这样当恢复的时候,系统会从硬盘上将休眠文件的内容直接读入内存,并恢复到休眠之前的状态。这种模式完全不耗电,因此不怕休眠后供电异常,但代价是需要一块和物理内存一样大小的硬盘空间。而这种模式的恢复速度较慢,取决于内存大小和硬盘速度。
睡眠(Sleep),是Windows Vista中的新模式,这种模式结合了待机和休眠的所有优点。将系统切换到睡眠状态后,系统会将内存中的数据全部转存到硬盘上的休眠文件中(这一点类似休眠),然后关闭除了内存外所有设备的供电,让内存中的数据依然维持着(这一点类似待机)。这样,当我们想要恢复的时候,如果在睡眠过程中供电没有发生过异常,就可以直接从内存中的数据恢复(类似待机),速度很快;但如果睡眠过程中供电异常,内存中的数据已经丢失了,还可以从硬盘上恢复(类似休眠),只是速度会慢一点。 不过无论如何,这种模式都不会导致数据丢失。
正因为睡眠功能有这么多优点,因此Windows Vista开始菜单上的电源按钮默认就会将系统切换到睡眠模式。所以我们大可充分利用这一新功能,毕竟从睡眠状态下恢复,速度要比从头启动快很多。而且睡眠模式也不是一直进行下去的,如果系统进入睡眠模式一段时间后(具体时间可以设定)没有被唤醒,那么还会自动被转入休眠状态,并关闭对内存的供电,进一步节约能耗。
备注:中文参考文章中说S1/S3 在BIOS里面可以设定Standby Mode为何,是要S1还是S3,S1和S3不能共存。但是某些主板支持S1&S3状态,也就是说内存还在工作,其它的部件停止工作了,CPU进入HALT/STOP状态,可以响应鼠标、键盘等中断,唤醒系统。
中文参考文章:http://www.360doc.com/content/09/0609/10/59579_3825214.shtml
英文参考文章:http://en.wikipedia.org/wiki/Advanced_Configuration_and_Power_Interface
小结:
1. 一般Windows XP系统中的"待机"或"Standby”其实是Suspend to RAM,即S3 in ACPI。
这就是为什么已经加密的系统盘,运行"Standby”,唤醒系统后,没有提示要输入解密系统盘的密码。
2. Standby: 即Suspend to RAM(挂起到内存)状态,简称STR。STR就是把系统进入STR前的工作状态数据都存放到内存中去。在STR状态下,电源仍然继续为内存等最必要的设备供电,以确保数据不丢失,而其他设备均处于关闭状态,系统的耗电量极低。一旦系统被唤醒,马上从内存中读取数据并恢复到STR之前的工作状态。
3. Hibernate: 即Suspend to Disk(挂起到硬盘)状态,简称STD,数据是保存在硬盘中。
按Power按钮给主板上电后,BIOS启动,Windows XP的NTLDR启动后,如果在系统根目录下发现有Hiberfil.sys文件且该文件有效,那么NTLDR将读取Hiberfil.sys文件里的信息并让系统恢复到休眠以前的状态,这时并不处理Boot.ini文件。
如果系统盘是加密,需要自己的引导程序(bootloader)在NTLDR或者bootmgr启动之前,提示用户输入密码,挂载(Mount)和解密Hiberfil.sys文件所在的分区,即boot.ini或者BCD(boot configuration data)所在的引导分区,然后跳转到 NTLDR或者bootmgr开始正常的启动过程。
4. dm-crypt加密Swap分区,不能使用Random data作为密钥,因为Hibernate文件保存在Swap分区,重启后无法正确读取Hibernate文件。Linux的引导程序(如Grub)需要挂载Swap分区,提示用户输入密码或者从特定的地方读取密钥文件,否则唤醒系统会失败。
5. Windows XP Embedded和Windows Embedded Standard 7 中的EWF(Enhanced Write Filter) 在支持Hibernate的存在限制的原因,下面一篇文章中会讲解。