Difference between revisions of "Hibernate-script"

From ArchWiki
Jump to: navigation, search
m (Suspending)
(use https for links to archlinux.org)
(17 intermediate revisions by 7 users not shown)
Line 1: Line 1:
{{i18n|Suspending to Disk with hibernate-script}}
+
[[Category:Power management]]
{{poor writing}}
+
[[Category:Power management (English)]] [[Category:Laptops (English)]]  
+
 
{{Article summary start|Summary}}
 
{{Article summary start|Summary}}
 
{{Article summary text|Suspending to disk using hibernate-script with uswsusp and tuxonice}}
 
{{Article summary text|Suspending to disk using hibernate-script with uswsusp and tuxonice}}
Line 11: Line 9:
 
"Hibernating" or suspending to disk writes all the running processes to the disk (typically to the swap partition), then completely powers down the machine. This resembles suspending to RAM, but while a machine suspended to RAM still requires a small charge from a battery or power source, a hibernated machine does not and can remain hibernated indefinitely. This advantage comes at the cost of additional time needed to hibernate and to resume, since disks (especially HDD swap partitions) write and read slower than RAM.
 
"Hibernating" or suspending to disk writes all the running processes to the disk (typically to the swap partition), then completely powers down the machine. This resembles suspending to RAM, but while a machine suspended to RAM still requires a small charge from a battery or power source, a hibernated machine does not and can remain hibernated indefinitely. This advantage comes at the cost of additional time needed to hibernate and to resume, since disks (especially HDD swap partitions) write and read slower than RAM.
  
This guide focuses on hibernate-script (see the [[pm-utils]] page for the alternative), a frontend used with the [http://suspend.sourceforge.net/ uswsusp] ("userspace suspension") and [http://www.tuxonice.net/ tuxonice] (formerly known as suspend2) hibernate backends. Uswsusp generally works without requiring a patched kernel but should be used with initrd/initramfs. Tuxonice requires a modified kernel, but works without initrd/initramfs and also allows suspending to a swap file if a user does not have, or does not want to use, a swap partition.
+
This guide focuses on hibernate-script (see the [[pm-utils]] page for the alternative), a frontend used with the [[uswsusp]] ("userspace suspension") and [[TuxOnIce]] (formerly known as suspend2) hibernate backends. Uswsusp generally works without requiring a patched kernel but should be used with initrd/initramfs. Tuxonice requires a modified kernel, but works without initrd/initramfs and also allows suspending to a swap file if a user does not have, or does not want to use, a swap partition.
  
==Installation==
+
== Installation ==
  
You can install [http://aur.archlinux.org/packages.php?ID=37110 hibernate-script] from the [[AUR]].
+
You can install {{AUR|hibernate-script}} from the [[AUR]].
  
=Uswsusp method=
+
== Uswsusp method ==
 
The userspace method lets you resort to some advanced suspension abilities included in vanilla kernels > 2.6.17.  
 
The userspace method lets you resort to some advanced suspension abilities included in vanilla kernels > 2.6.17.  
  
==Install uswsuap==
+
=== Install uswsusp ===
You need two userspace tools, called s2disk and resume, which do what their names say. They are both included in the [[AUR]] package [http://aur.archlinux.org/packages.php?ID=44473 uswsusp-git] (which includes also s2ram, see [[Suspend to RAM]] ).
+
You need two userspace tools, called s2disk and resume, which do what their names say. They are both included in the [[AUR]] package {{AUR|uswsusp-git}} (which includes also s2ram, see [[Suspend to RAM]]).
If you had installed yaourt, you can do like this:
+
yaourt -S uswsusp-git
+
  
==Editing /etc/suspend.conf==
+
=== Editing /etc/suspend.conf ===
On the contrary, you need to edit the s2disk configuration file, called /etc/suspend.conf. It is essential that you modify the resume device parameter:
+
On the contrary, you need to edit the s2disk configuration file, called {{Ic|/etc/suspend.conf}}. It is essential that you modify the resume device parameter:
 
  resume device = /dev/sda3
 
  resume device = /dev/sda3
  
Line 42: Line 38:
 
This explicitly configures the system to shutdown instead of reboot.
 
This explicitly configures the system to shutdown instead of reboot.
  
==Recreate the initramfs==
+
=== Recreate the initramfs ===
Now you need to recreate an initramfs with the new hook. So edit the /etc/mkinitcpio.conf file. In the HOOKS list add the '''uresume''' hook ('''it is different from the resume hook, which is on the contrary required by the tuxonice method'''). You should put it immediately before the filesystem hook.  
+
Now you need to recreate an initramfs with the new hook. So edit the {{Ic|/etc/mkinitcpio.conf}} file. In the HOOKS list add the '''uresume''' hook ('''it is different from the resume hook, which is on the contrary required by the tuxonice method'''). You should put it immediately before the filesystem hook.  
When the hook is executed the device file for the swap partition (which you have defined in /etc/suspend.conf) needs to exist (the standard udev hook will take care of this). Now proceed to regenerate your initramfs:
+
When the hook is executed the device file for the swap partition (which you have defined in {{Ic|/etc/suspend.conf}}) needs to exist (the standard udev hook will take care of this). Now proceed to regenerate your initramfs:
 
  # mkinitcpio -p linux
 
  # mkinitcpio -p linux
  
 
You need to adjust this command according to the kernel you plan to use and the name of the initramfs in the grub configuration. Anyway you should not need to modify anything in the grub configuration.
 
You need to adjust this command according to the kernel you plan to use and the name of the initramfs in the grub configuration. Anyway you should not need to modify anything in the grub configuration.
  
==Suspend to file support==
+
=== Suspend to file support ===
 
uswsusp also supports suspending to a swapfile (and perhaps a dedicated hibernation file).  The procedure is identical to using a swap partition with these exceptions:
 
uswsusp also supports suspending to a swapfile (and perhaps a dedicated hibernation file).  The procedure is identical to using a swap partition with these exceptions:
  
In addition to specifying the resume device on the kernel command line, an additional parameter is required. The additional parameter is '''resume_offset=<Swap File Offset>'''. This same parameter must be included in ''/etc/suspend.conf'' as '''resume offset'''.
+
In addition to specifying the resume device on the kernel command line, an additional parameter is required. The additional parameter is {{ic|1=resume_offset=<Swap File Offset>}}. This same parameter must be included in {{Ic|/etc/suspend.conf}} as {{ic|resume offset}}.
  
 
To obtain the offset, you can check [[<noinclude>Swap</noinclude>#Swap_file_resuming|Swap file resuming]]
 
To obtain the offset, you can check [[<noinclude>Swap</noinclude>#Swap_file_resuming|Swap file resuming]]
  
Below is an example of ''/etc/suspend.conf'':
+
Below is an example of {{Ic|/etc/suspend.conf}}:
  
 
<pre>snapshot device = /dev/snapshot
 
<pre>snapshot device = /dev/snapshot
Line 70: Line 66:
 
</pre>
 
</pre>
  
Where '''sda3''' is the partition that the swapfile resides and '''4694016''' the <Swap File Offset>. Remember to change these values with your own.
+
Where {{ic|sda3}} is the partition that the swapfile resides, and {{ic|4694016}} the swap file offset. Remember to change these values with your own.
  
==Support for splash screens==
+
=== Support for splash screens ===
The uswsusp-git package does not provide support for splash screens: for Fbsplash there is the [http://aur.archlinux.org/packages.php?ID=16233 uswsusp-fbsplash package] and for Splashy the [http://aur.archlinux.org/packages.php?ID=36053 uswsusp-splashy-git package] in the AUR. For splash see the HOWTO and README in the source tarball for details if you want to modify the PKGBUILD yourself.
+
The uswsusp-git package does not provide support for splash screens: for Fbsplash there is the {{AUR|uswsusp-fbsplash}} and for Splashy the {{AUR|uswsusp-splashy-git}} in the AUR. For splash see the HOWTO and README in the source tarball for details if you want to modify the PKGBUILD yourself.
  
==Setting the suspend method==
+
=== Setting the suspend method ===
If you use hibernate-script, your preferred suspend/hibernation method can be set in the file {{Ic|/etc/hibernate/hibernate.conf}}. If you list several methods, the first one will be used. Note that ''hibernate'' can also be used with [[Suspend to RAM]] or vanilla swsusp).
+
If you use hibernate-script, your preferred suspend/hibernation method can be set in the file {{Ic|/etc/hibernate/hibernate.conf}}. If you list several methods, the first one will be used. Note that ''hibernate'' can also be used with [[Suspend to RAM]] or vanilla uswsusp).
  
 
For Uswsusp use:
 
For Uswsusp use:
 
  TryMethod ususpend-disk.conf
 
  TryMethod ususpend-disk.conf
  
If you use pm-utils: http://wiki.archlinux.org/index.php/Pm-utils#Using_another_sleep_backend_.28like_uswsusp.29
+
If you use pm-utils: https://wiki.archlinux.org/index.php/Pm-utils#Using_another_sleep_backend_.28like_uswsusp.29
  
 
Or just try to do it like:
 
Or just try to do it like:
 
  # echo "SLEEP_MODULE=uswsusp">>/etc/pm/config.d/module
 
  # echo "SLEEP_MODULE=uswsusp">>/etc/pm/config.d/module
  
==Suspending==
+
=== Suspending ===
 
Now you could try to suspend directly calling s2disk from the command line:
 
Now you could try to suspend directly calling s2disk from the command line:
 
  # s2disk
 
  # s2disk
Line 93: Line 89:
 
  # hibernate -F /etc/hibernate/ususpend-disk.conf
 
  # hibernate -F /etc/hibernate/ususpend-disk.conf
  
==Support for encryption==
+
=== Support for encryption ===
 
* generate a key with the suspend-keygen utility included in the package;
 
* generate a key with the suspend-keygen utility included in the package;
* write the name of the key in /etc/suspend.conf;
+
* write the name of the key in {{Ic|/etc/suspend.conf}};
* uncomment or add the following line in /etc/suspend.conf
+
* uncomment or add the following line in {{Ic|/etc/suspend.conf}};
 
  encrypt = y
 
  encrypt = y
 
  RSA key file = <path_to_keyfile>
 
  RSA key file = <path_to_keyfile>
 
* build a new initramfs with the uresume hook just before the filesystem one.
 
* build a new initramfs with the uresume hook just before the filesystem one.
  
=Tuxonice method=
+
== Tuxonice method ==
 
There is a dedicated [[Tuxonice]] page which covers the basics of installing and configuring Tuxonice.
 
There is a dedicated [[Tuxonice]] page which covers the basics of installing and configuring Tuxonice.
  
=Hibernate tricks with the hibernate.script=
+
== Hibernate tricks with the hibernate.script ==
This is a brief overview of the hibernate script. If you want to tweak it further, examine the ''common.conf'' and ''suspend2.conf'' files further and read the excellent and exhaustive man pages for hibernate and hibernate.conf.
+
This is a brief overview of the hibernate script. If you want to tweak it further, examine the {{Ic|common.conf}} and {{Ic|suspend2.conf}} files further and read the excellent and exhaustive man pages for hibernate and {{Ic|hibernate.conf}}.
  
==Editing /etc/hibernate/common.conf==
+
=== Editing /etc/hibernate/common.conf ===
The options in this file are used with any hibernation method (actually, the file is sourced by the configuration files of each method) and also by [[Suspend to RAM]] when accomplished with the hibernate-script. This file is complex and well commented. The man page hibernate.conf describes adequately all the options. Here, we can only stress the most commonly useful parts.
+
The options in this file are used with any hibernation method (actually, the file is sourced by the configuration files of each method) and also by [[Suspend to RAM]] when accomplished with the hibernate-script. This file is complex and well commented. The man page {{Ic|hibernate.conf}} describes adequately all the options. Here, we can only stress the most commonly useful parts.
  
 
Uncomment the lines for any filesystems that have the potential to change while your computer is suspended (for example shared partitions with windows like vfat or ntfs ones). They will be remounted upon resume. Otherwise you would risk corrupting the filesystems.
 
Uncomment the lines for any filesystems that have the potential to change while your computer is suspended (for example shared partitions with windows like vfat or ntfs ones). They will be remounted upon resume. Otherwise you would risk corrupting the filesystems.
Line 119: Line 115:
 
If you do not explicitly restore the volume levels, ALSA may have the sound channels muted after resuming. If this happens, look for:
 
If you do not explicitly restore the volume levels, ALSA may have the sound channels muted after resuming. If this happens, look for:
 
  ### services
 
  ### services
in <code>/etc/hibernate/common.conf</code> and change the line just below to:
+
in {{Ic|/etc/hibernate/common.conf}} and change the line just below to:
 
  RestartServices alsa
 
  RestartServices alsa
  
Line 126: Line 122:
  
 
A common issue is that some drivers do not support suspension, that is they do not work properly after a suspension cycle or even they prevent the system from suspending or resuming properly.  
 
A common issue is that some drivers do not support suspension, that is they do not work properly after a suspension cycle or even they prevent the system from suspending or resuming properly.  
In these cases (which should be reported - at least for modules in the vanilla kernel - to the suspend-devel@lists.sourceforge.net mailing list, so that they can be fixed upstream) you can unload the module before suspension and reload it after resuming: the hibernate-script can automatize this routine with the LoadModules and UnloadModules options. Actually, the hibernate-script already unloads some problematic modules, listed in /etc/hibernate/blacklisted-modules, so you can also add the modules in that file.
+
In these cases (which should be reported - at least for modules in the vanilla kernel - to the suspend-devel@lists.sourceforge.net mailing list, so that they can be fixed upstream) you can unload the module before suspension and reload it after resuming: the hibernate-script can automatize this routine with the LoadModules and UnloadModules options. Actually, the hibernate-script already unloads some problematic modules, listed in {{Ic|/etc/hibernate/blacklisted-modules}}, so you can also add the modules in that file.
  
 
To re-connect to networks after rebooting, you may want to add:
 
To re-connect to networks after rebooting, you may want to add:
Line 137: Line 133:
 
You'll need to set the priority as 05 instead. Its normally best to use something within the range of 20-50 for your user scripts.
 
You'll need to set the priority as 05 instead. Its normally best to use something within the range of 20-50 for your user scripts.
  
If you need/want to eject all PcCards before suspending and reinsert them after resuming, change the ''EjectCards'' setting in ''common.conf'':
+
If you need/want to eject all PcCards before suspending and reinsert them after resuming, change the ''EjectCards'' setting in {{Ic|common.conf}}:
 
  ### pcmcia
 
  ### pcmcia
 
  EjectCards yes
 
  EjectCards yes
Line 144: Line 140:
  
 
Finally, the most problematic aspect is constituted by the video card: its status needs often to be restored after resuming. In other cases, it is necessary to switch from X to the console.
 
Finally, the most problematic aspect is constituted by the video card: its status needs often to be restored after resuming. In other cases, it is necessary to switch from X to the console.
The following options in /etc/hibernate/common.conf will probably fix these issues (whose symptom could be a frozen machine or only a black display after resuming):
+
The following options in {{Ic|/etc/hibernate/common.conf}} will probably fix these issues (whose symptom could be a frozen machine or only a black display after resuming):
 
  ### vbetool
 
  ### vbetool
 
  #EnableVbetool yes
 
  #EnableVbetool yes
Line 156: Line 152:
 
  #DummyXServerConfig xorg-dummy.conf
 
  #DummyXServerConfig xorg-dummy.conf
  
You can uncomment one or many of them in order to see if the problem is solved. In order to use the first block of options, you need to install the vbetool package from the extra repository. Each of the option is documented in man hibernate.conf.  
+
You can uncomment one or many of them in order to see if the problem is solved. In order to use the first block of options, you need to install the vbetool package from the extra repository. Each of the option is documented in man {{Ic|hibernate.conf}}.  
 
Please note that it is very important to try all the different combinations of these options before than anything else, becaause the problems with the display are the most common source of troubles in a suspension cycle.
 
Please note that it is very important to try all the different combinations of these options before than anything else, becaause the problems with the display are the most common source of troubles in a suspension cycle.
  
== NVIDIA specific settings ==
+
=== NVIDIA specific settings ===
If you have an [[NVIDIA]] graphics card and use a driver version >177, you need to add the following line to /etc/hibernate/tuxonice.conf  
+
If you have an [[NVIDIA]] graphics card and use a driver version >177, you need to add the following line to {{Ic|/etc/hibernate/tuxonice.conf}}:
 
  ProcSetting extra_pages_allowance 7500
 
  ProcSetting extra_pages_allowance 7500
  
A value lower than 7500 might also work on certain systems, though 7500 should be a working default. Setting this option should allow you to hibernate and resume without any additional X hacks. You will also need to comment out the nvidia module in /etc/hibernate/blacklisted-modules for this to work.
+
A value lower than 7500 might also work on certain systems, though 7500 should be a working default. Setting this option should allow you to hibernate and resume without any additional X hacks. You will also need to comment out the nvidia module in {{Ic|/etc/hibernate/blacklisted-modules}} for this to work.
  
 
The suggested value for extra_pages_allowance for driver versions <177 is 0:
 
The suggested value for extra_pages_allowance for driver versions <177 is 0:
Line 170: Line 166:
 
This setting has also been reported to help with the binary ATI driver.
 
This setting has also been reported to help with the binary ATI driver.
  
If you have an AGP Nvidia card and are using the binary driver, you might also have to add the following line to your /etc/X11/xorg.conf:
+
If you have an AGP Nvidia card and are using the binary driver, you might also have to add the following line to your {{Ic|/etc/X11/xorg.conf}}:
 
  Option "NvAGP" "1"
 
  Option "NvAGP" "1"
  
== Suspending with fglrx ==
+
=== Suspending with fglrx ===
Following addition to /etc/hibernate/suspend2.conf is required:
+
Following addition to {{Ic|/etc/hibernate/suspend2.conf}} is required:
 
  # For fglrx
 
  # For fglrx
 
  ProcSetting extra_pages_allowance 20000
 
  ProcSetting extra_pages_allowance 20000
  
== Dropping disk caches ==
+
=== Dropping disk caches ===
 
:<small>''From: [http://www.linuxinsight.com/proc_sys_vm_drop_caches.html drop_caches introduction]''</small>
 
:<small>''From: [http://www.linuxinsight.com/proc_sys_vm_drop_caches.html drop_caches introduction]''</small>
  
As a way to speed up suspending, you can free the memory used for disk caches so there will be less to write to the disk. Just add something like this to the common.conf:
+
As a way to speed up suspending, you can free the memory used for disk caches so there will be less to write to the disk. Just add something like this to the {{Ic|common.conf}}:
 
  OnSuspend 00 sync; echo 3 > /proc/sys/vm/drop_caches
 
  OnSuspend 00 sync; echo 3 > /proc/sys/vm/drop_caches
  
=Combining suspend to disk with suspend to RAM=
+
== Combining suspend to disk with suspend to RAM ==
 
If your motherboard or laptop supports [[Suspend to RAM]], you can combine it with suspend2. This will result in the following behavior:
 
If your motherboard or laptop supports [[Suspend to RAM]], you can combine it with suspend2. This will result in the following behavior:
  
Line 193: Line 189:
 
This can be done both with uswsusp and with tuxonice.  
 
This can be done both with uswsusp and with tuxonice.  
  
With uswsusp, you should use s2both. You can also call s2both from the hibernate script (with all its richness of options), resorting to the ususpend-both.conf method. Please note that s2both works only if s2ram (see [[Suspend to RAM]]) works in your system. There is no way to force it to work if your laptop model is not whitelisted in s2ram. See [[Suspend to RAM]] for instructions about how to whitelist your laptop in the local copy of s2ram and how to report that your laptop suspend to ram properly so that it is whitelisted in the next uswsusp release.
+
With uswsusp, you should use s2both. You can also call s2both from the hibernate script (with all its richness of options), resorting to the {{Ic|ususpend-both.conf}} method. Please note that s2both works only if s2ram (see [[Suspend to RAM]]) works in your system. There is no way to force it to work if your laptop model is not whitelisted in s2ram. See [[Suspend to RAM]] for instructions about how to whitelist your laptop in the local copy of s2ram and how to report that your laptop suspend to ram properly so that it is whitelisted in the next uswsusp release.
  
To do it with tuxonice, edit ''/etc/hibernate/suspend2.conf'':
+
To do it with tuxonice, edit {{Ic|/etc/hibernate/suspend2.conf}}:
 
  ## Powerdown method - 3 for suspend-to-RAM, 4 for ACPI S4 sleep, 5 for poweroff
 
  ## Powerdown method - 3 for suspend-to-RAM, 4 for ACPI S4 sleep, 5 for poweroff
 
  PowerdownMethod 3
 
  PowerdownMethod 3
Line 201: Line 197:
 
For this to work, your computer must be able to use suspend to RAM also without s2ram.
 
For this to work, your computer must be able to use suspend to RAM also without s2ram.
  
=Take action based on events=
+
== Take action based on events ==
Tuning hibernate-script for context sensitive modal operation. You need to have {{Package Official|acpid}} installed.
+
Tuning hibernate-script for context sensitive modal operation. You need to have {{Pkg|acpid}} installed.
  
==After pressing power button==
+
=== After pressing power button ===
Edit the following file <code>/etc/acpi/events/power</code>
+
Edit the following file {{Ic|/etc/acpi/events/power}}
 
  # This is called when the user presses the power button
 
  # This is called when the user presses the power button
 
  event=button/power (PWR.||PBTN)
 
  event=button/power (PWR.||PBTN)
Line 213: Line 209:
 
  #action=suspend
 
  #action=suspend
  
==After closing lid==
+
=== After closing lid ===
Edit the following file <code>/etc/acpi/events/lid</code>
+
Edit the following file {{Ic|/etc/acpi/events/lid}}
 
  # This is called when the user closes the lid
 
  # This is called when the user closes the lid
 
  event=button/lid
 
  event=button/lid
Line 222: Line 218:
 
  #action=suspend
 
  #action=suspend
  
You can also install [https://aur.archlinux.org/packages.php?ID=52110 lidsleep] which includes the file altered to use pm-utils and suspend to RAM.
+
You can also install {{AUR|lidsleep}} which includes the file altered to use pm-utils and suspend to RAM.
  
Alternatively you can edit <code>/etc/acpi/actions/lm_lid.sh</code> this is the file that is executed when the lid state is changed
+
Alternatively you can edit {{Ic|/etc/acpi/actions/lm_lid.sh}} this is the file that is executed when the lid state is changed
  
 
Example:
 
Example:

Revision as of 00:51, 6 December 2012

Template:Article summary start Template:Article summary text Template:Article summary heading Template:Article summary wiki Template:Article summary wiki Template:Article summary wiki Template:Article summary end "Hibernating" or suspending to disk writes all the running processes to the disk (typically to the swap partition), then completely powers down the machine. This resembles suspending to RAM, but while a machine suspended to RAM still requires a small charge from a battery or power source, a hibernated machine does not and can remain hibernated indefinitely. This advantage comes at the cost of additional time needed to hibernate and to resume, since disks (especially HDD swap partitions) write and read slower than RAM.

This guide focuses on hibernate-script (see the pm-utils page for the alternative), a frontend used with the uswsusp ("userspace suspension") and TuxOnIce (formerly known as suspend2) hibernate backends. Uswsusp generally works without requiring a patched kernel but should be used with initrd/initramfs. Tuxonice requires a modified kernel, but works without initrd/initramfs and also allows suspending to a swap file if a user does not have, or does not want to use, a swap partition.

Installation

You can install hibernate-scriptAUR from the AUR.

Uswsusp method

The userspace method lets you resort to some advanced suspension abilities included in vanilla kernels > 2.6.17.

Install uswsusp

You need two userspace tools, called s2disk and resume, which do what their names say. They are both included in the AUR package uswsusp-gitAUR (which includes also s2ram, see Suspend to RAM).

Editing /etc/suspend.conf

On the contrary, you need to edit the s2disk configuration file, called /etc/suspend.conf. It is essential that you modify the resume device parameter:

resume device = /dev/sda3

It needs to point to your swap partition: in this case, the third partition of a primary pata-sata drive. It is also a good thing to enable compression, because this speeds up greatly your suspension/resume routine.

Note that it is important that this configuration file be edited *before* recreating the initramfs (done below). Presently, the initramfs build process reads this configuration file, and embeds the current resume parameter. If not changed from the default '<path_to_resume_device_file>', this causes problems such as seeing, on bootup:

# Could not stat the resume device file '<path_to_resume_device_file>'
# Please type in the full path name to try again or press ENTER to boot the system.

If you have experiencing this problem, simply edit the file as appropriate, and then rebuild the initramfs.

Another line that you may want to add to the configuration file is:

shutdown method = shutdown

This explicitly configures the system to shutdown instead of reboot.

Recreate the initramfs

Now you need to recreate an initramfs with the new hook. So edit the /etc/mkinitcpio.conf file. In the HOOKS list add the uresume hook (it is different from the resume hook, which is on the contrary required by the tuxonice method). You should put it immediately before the filesystem hook. When the hook is executed the device file for the swap partition (which you have defined in /etc/suspend.conf) needs to exist (the standard udev hook will take care of this). Now proceed to regenerate your initramfs:

# mkinitcpio -p linux

You need to adjust this command according to the kernel you plan to use and the name of the initramfs in the grub configuration. Anyway you should not need to modify anything in the grub configuration.

Suspend to file support

uswsusp also supports suspending to a swapfile (and perhaps a dedicated hibernation file). The procedure is identical to using a swap partition with these exceptions:

In addition to specifying the resume device on the kernel command line, an additional parameter is required. The additional parameter is resume_offset=<Swap File Offset>. This same parameter must be included in /etc/suspend.conf as resume offset.

To obtain the offset, you can check Swap file resuming

Below is an example of /etc/suspend.conf:

snapshot device = /dev/snapshot
resume offset = 4694016
resume device = /dev/sda3
#image size = 350000000
#suspend loglevel = 2
#compute checksum = y
#compress = y
#encrypt = y
#early writeout = y
#splash = y

Where sda3 is the partition that the swapfile resides, and 4694016 the swap file offset. Remember to change these values with your own.

Support for splash screens

The uswsusp-git package does not provide support for splash screens: for Fbsplash there is the uswsusp-fbsplashAUR and for Splashy the uswsusp-splashy-gitAUR in the AUR. For splash see the HOWTO and README in the source tarball for details if you want to modify the PKGBUILD yourself.

Setting the suspend method

If you use hibernate-script, your preferred suspend/hibernation method can be set in the file /etc/hibernate/hibernate.conf. If you list several methods, the first one will be used. Note that hibernate can also be used with Suspend to RAM or vanilla uswsusp).

For Uswsusp use:

TryMethod ususpend-disk.conf

If you use pm-utils: https://wiki.archlinux.org/index.php/Pm-utils#Using_another_sleep_backend_.28like_uswsusp.29

Or just try to do it like:

# echo "SLEEP_MODULE=uswsusp">>/etc/pm/config.d/module

Suspending

Now you could try to suspend directly calling s2disk from the command line:

# s2disk

However, this is highly likely to fail, because some services could need to be stopped, some modules unloaded, etc. Thus it is probably necessary to resort to a userspace tool which calls internally s2disk, like Pm-utils since version 1.1 (which is now in core) or hibernate-script. See below about details for defining the ususpend-disk method as default in /etc/hibernate/hibernate.conf. For the moment being, remember that you can define specific options in /etc/hibernate/ususpend-disk.conf and, after having configured also /etc/hibernate/common.conf, you can suspend to disk with the uswsusp method with the following command:

# hibernate -F /etc/hibernate/ususpend-disk.conf

Support for encryption

  • generate a key with the suspend-keygen utility included in the package;
  • write the name of the key in /etc/suspend.conf;
  • uncomment or add the following line in /etc/suspend.conf;
encrypt = y
RSA key file = <path_to_keyfile>
  • build a new initramfs with the uresume hook just before the filesystem one.

Tuxonice method

There is a dedicated Tuxonice page which covers the basics of installing and configuring Tuxonice.

Hibernate tricks with the hibernate.script

This is a brief overview of the hibernate script. If you want to tweak it further, examine the common.conf and suspend2.conf files further and read the excellent and exhaustive man pages for hibernate and hibernate.conf.

Editing /etc/hibernate/common.conf

The options in this file are used with any hibernation method (actually, the file is sourced by the configuration files of each method) and also by Suspend to RAM when accomplished with the hibernate-script. This file is complex and well commented. The man page hibernate.conf describes adequately all the options. Here, we can only stress the most commonly useful parts.

Uncomment the lines for any filesystems that have the potential to change while your computer is suspended (for example shared partitions with windows like vfat or ntfs ones). They will be remounted upon resume. Otherwise you would risk corrupting the filesystems.

### filesystems
# Unmount /nfsshare /windows /mnt/sambaserver
# UnmountFSTypes smbfs nfs
# UnmountGraceTime 1
# Mount /windows

If you do not explicitly restore the volume levels, ALSA may have the sound channels muted after resuming. If this happens, look for:

### services

in /etc/hibernate/common.conf and change the line just below to:

RestartServices alsa

The alsa service will be stopped before suspension and restarted after resuming: the sound channels and volumes will be as before. You may want to restart other problematic services here.

A common issue is that some drivers do not support suspension, that is they do not work properly after a suspension cycle or even they prevent the system from suspending or resuming properly. In these cases (which should be reported - at least for modules in the vanilla kernel - to the suspend-devel@lists.sourceforge.net mailing list, so that they can be fixed upstream) you can unload the module before suspension and reload it after resuming: the hibernate-script can automatize this routine with the LoadModules and UnloadModules options. Actually, the hibernate-script already unloads some problematic modules, listed in /etc/hibernate/blacklisted-modules, so you can also add the modules in that file.

To re-connect to networks after rebooting, you may want to add:

OnSuspend 25 netcfg2 -a
OnResume 20 netcfg-auto-wireless <your-network-interface>

This will disconnect from all networks, then should automatically choose the correct one. If you use another way to connect to a network (such as netcfg2 <profile-name> then of-course, put that there instead.

One 'gotcha' to watch out for is the priority level you put on your user-commands, this won't work:

OnSuspend 5 netcfg -a

You'll need to set the priority as 05 instead. Its normally best to use something within the range of 20-50 for your user scripts.

If you need/want to eject all PcCards before suspending and reinsert them after resuming, change the EjectCards setting in common.conf:

### pcmcia
EjectCards yes

This is necessary on some laptops, if the pccards stop working after resume.

Finally, the most problematic aspect is constituted by the video card: its status needs often to be restored after resuming. In other cases, it is necessary to switch from X to the console. The following options in /etc/hibernate/common.conf will probably fix these issues (whose symptom could be a frozen machine or only a black display after resuming):

### vbetool
#EnableVbetool yes
#RestoreVbeStateFrom /var/lib/vbetool/vbestate
#VbetoolPost yes
# RestoreVCSAData yes
### xhacks
#SwitchToTextMode yes
#UseDummyXServer yes
#DummyXServerConfig xorg-dummy.conf

You can uncomment one or many of them in order to see if the problem is solved. In order to use the first block of options, you need to install the vbetool package from the extra repository. Each of the option is documented in man hibernate.conf. Please note that it is very important to try all the different combinations of these options before than anything else, becaause the problems with the display are the most common source of troubles in a suspension cycle.

NVIDIA specific settings

If you have an NVIDIA graphics card and use a driver version >177, you need to add the following line to /etc/hibernate/tuxonice.conf:

ProcSetting extra_pages_allowance 7500

A value lower than 7500 might also work on certain systems, though 7500 should be a working default. Setting this option should allow you to hibernate and resume without any additional X hacks. You will also need to comment out the nvidia module in /etc/hibernate/blacklisted-modules for this to work.

The suggested value for extra_pages_allowance for driver versions <177 is 0:

ProcSetting extra_pages_allowance 0

This setting has also been reported to help with the binary ATI driver.

If you have an AGP Nvidia card and are using the binary driver, you might also have to add the following line to your /etc/X11/xorg.conf:

Option "NvAGP" "1"

Suspending with fglrx

Following addition to /etc/hibernate/suspend2.conf is required:

# For fglrx
ProcSetting extra_pages_allowance 20000

Dropping disk caches

From: drop_caches introduction

As a way to speed up suspending, you can free the memory used for disk caches so there will be less to write to the disk. Just add something like this to the common.conf:

OnSuspend 00 sync; echo 3 > /proc/sys/vm/drop_caches

Combining suspend to disk with suspend to RAM

If your motherboard or laptop supports Suspend to RAM, you can combine it with suspend2. This will result in the following behavior:

  • When you call hibernate, your system will suspend to disk and after that suspend to RAM instead of powering down.
  • When you turn your system back on, it will resume directly from RAM (which only takes a few seconds)
  • If your battery fails in the meantime (and the image in your memory is therefore lost), you will be able to resumes from disk.

This can be done both with uswsusp and with tuxonice.

With uswsusp, you should use s2both. You can also call s2both from the hibernate script (with all its richness of options), resorting to the ususpend-both.conf method. Please note that s2both works only if s2ram (see Suspend to RAM) works in your system. There is no way to force it to work if your laptop model is not whitelisted in s2ram. See Suspend to RAM for instructions about how to whitelist your laptop in the local copy of s2ram and how to report that your laptop suspend to ram properly so that it is whitelisted in the next uswsusp release.

To do it with tuxonice, edit /etc/hibernate/suspend2.conf:

## Powerdown method - 3 for suspend-to-RAM, 4 for ACPI S4 sleep, 5 for poweroff
PowerdownMethod 3

For this to work, your computer must be able to use suspend to RAM also without s2ram.

Take action based on events

Tuning hibernate-script for context sensitive modal operation. You need to have acpid installed.

After pressing power button

Edit the following file /etc/acpi/events/power

# This is called when the user presses the power button
event=button/power (PWR.||PBTN)
# To Hibernate uncomment the following line
#action=hibernate 
# To Suspend uncomment the following line
#action=suspend

After closing lid

Edit the following file /etc/acpi/events/lid

# This is called when the user closes the lid
event=button/lid
# To Hibernate uncomment the following line
#action=hibernate 
# To Suspend uncomment the following line
#action=suspend

You can also install lidsleepAUR which includes the file altered to use pm-utils and suspend to RAM.

Alternatively you can edit /etc/acpi/actions/lm_lid.sh this is the file that is executed when the lid state is changed

Example:

#!/bin/bash
# lid button pressed/released event handler
#laptop mode helps minimized hdd activity
test -x /usr/sbin/laptop_mode && /usr/sbin/laptop_mode auto
# get the -xauth variable so we can access the display
XAUTH="$( ps -C X f | sed -n 's/.*-auth \(.*\)/\1/p' )"
if [[ -z $XAUTH ]]; then
  # if XAUTH is blank try another way to get it 
  XAUTH="$( ps -C xinit f | sed -n 's/.*-auth \(.*\)serverauth.*/\1Xauthority/p' )"
fi
#Find out if the lid is open or closed
if grep -q open /proc/acpi/button/lid/LID/state; then
  # the screen is on, forces it to be on
  ACTION="on"
  XAUTHORITY=$XAUTH /usr/bin/xset -display :0.0 dpms force $ACTION
else
  # screen is off, forces off
  ACTION="off"
  XAUTHORITY=$XAUTH /usr/bin/xset -display :0.0 dpms force $ACTION
  # script waits for 10 minutes
  sleep 10m
  # checks to make sure screen is still closed
  if grep -q closed /proc/acpi/button/lid/LID/state; then
    # if it is, then it suspends to disk
    s2disk
  else
    # or it turns it back on
    XAUTHORITY=$XAUTH /usr/bin/xset -display :0.0 dpms force on
  fi
fi

The script turns the monitor off or on. But if the screen is left shut for 10 minutes, it will suspend to the disk automatically. man sleep for more info on the sleep command.