Difference between revisions of "Uswsusp"

From ArchWiki
Jump to: navigation, search
(Fixes upower-based hibernating (notify upower of resume by running /usr/lib/systemd/system-sleep/notify-upower.sh))
(simplification and beautification of wikilinks, fixing whitespace, capitalization and section fragments (https://github.com/lahwaacz/wiki-scripts/blob/master/link-checker.py (interactive)))
 
(20 intermediate revisions by 11 users not shown)
Line 1: Line 1:
 
[[Category:Power management]]
 
[[Category:Power management]]
{{Article summary start}}
+
[[ja:Uswsusp]]
{{Article summary text|Describes installing, configuring and using uswsusp, a set of userspace tools used for suspending to disk and/or to RAM.}}
+
{{Related articles start}}
{{Article summary heading|Related}}
+
{{Related|hibernate-script}}
{{Article summary wiki|Suspending to RAM with hibernate-script}}
+
{{Related|Pm-utils}}
{{Article summary wiki|Suspending to Disk with hibernate-script}}
+
{{Related|TuxOnIce}}
{{Article summary wiki|Pm-utils}}
+
{{Related articles end}}
{{Article summary wiki|Tuxonice}}
+
{{Article summary end}}
+
  
 
[http://suspend.sourceforge.net/ uswsusp] (userspace software suspend) is a set of user space tools used for hibernation (suspend-to-disk) and suspend (suspend-to-RAM or standby) on Linux systems.
 
[http://suspend.sourceforge.net/ uswsusp] (userspace software suspend) is a set of user space tools used for hibernation (suspend-to-disk) and suspend (suspend-to-RAM or standby) on Linux systems.
Line 19: Line 17:
 
== Installation ==
 
== Installation ==
  
uswsusp is available in the [[AUR]] under the name [https://aur.archlinux.org/packages.php?ID=44473 uswsusp-git].
+
uswsusp is available in the [[AUR]] under the name {{AUR|uswsusp-git}}.
  
 
== Configuration ==
 
== Configuration ==
Line 30: Line 28:
 
where {{ic|/dev/disk/by-label/swap}} must be replaced with the correct block device containing the swap partition.
 
where {{ic|/dev/disk/by-label/swap}} must be replaced with the correct block device containing the swap partition.
  
* If using a [[Swap#swap_file|swap file]]:
+
* If using a [[swap file]]:
  resume device = /dev/sdX # the partition which contains swapfile  
+
  resume device = /dev/sdXN # the partition which contains swapfile  
 
  resume offset = 123456
 
  resume offset = 123456
  
where 123456 is the offset from the beginning of the resume device where the swap file's header is located. To obtain the offset, you can check [[Swap#Swap_file_resuming|Swap file resuming]].
+
where 123456 is the offset from the beginning of the resume device where the swap file's header is located. The resume offset can be obtained by running
The resume offset can be obtained by running
+
  
 
  # swap-offset your-swap-file
 
  # swap-offset your-swap-file
Line 62: Line 59:
 
{{Note|Whenever you modify {{ic|/etc/suspend.conf}}, '''you will need to rebuild''' your initramfs. If you fail to do so, and linux cannot find your image at startup, you will not see an error message indicating this. Your boot process will hang after starting the {{ic|uresume}} hook, typically after the message with the libgcrypt version.}}  
 
{{Note|Whenever you modify {{ic|/etc/suspend.conf}}, '''you will need to rebuild''' your initramfs. If you fail to do so, and linux cannot find your image at startup, you will not see an error message indicating this. Your boot process will hang after starting the {{ic|uresume}} hook, typically after the message with the libgcrypt version.}}  
 
Edit your {{ic|/etc/mkinitcpio.conf}} file and add "uresume" to the HOOKS entry.
 
Edit your {{ic|/etc/mkinitcpio.conf}} file and add "uresume" to the HOOKS entry.
  HOOKS="base udev autodetect pata scsi sata '''uresume''' filesystems"
+
  HOOKS="base udev autodetect block '''uresume''' filesystems"
 
* rebuild the ramdisk
 
* rebuild the ramdisk
 
  # mkinitcpio -p linux
 
  # mkinitcpio -p linux
Line 118: Line 115:
  
 
=== With pm-utils ===
 
=== With pm-utils ===
 +
 +
{{Out of date|1=Since February 2013, the suspend and hibernate functions in UPower have been [http://cgit.freedesktop.org/upower/commit/?id=372c2f8d2922add987683a24b5d69902e05e2f97 deprecated].}}
  
 
[[Pm-utils]] can utilise several [[Pm-utils#Using_another_sleep_backend_.28like_uswsusp.29|sleep back-ends]], including uswsusp. Create or edit {{ic|/etc/pm/config.d/module}}:
 
[[Pm-utils]] can utilise several [[Pm-utils#Using_another_sleep_backend_.28like_uswsusp.29|sleep back-ends]], including uswsusp. Create or edit {{ic|/etc/pm/config.d/module}}:
Line 128: Line 127:
 
   
 
   
 
  $ dbus-send --system --print-reply --dest="org.freedesktop.UPower" /org/freedesktop/UPower org.freedesktop.UPower.Hibernate
 
  $ dbus-send --system --print-reply --dest="org.freedesktop.UPower" /org/freedesktop/UPower org.freedesktop.UPower.Hibernate
{{Note|The user's [[Window Manager|window manager]] or [[Desktop Environment|desktop environment]] needs to be started either with a [[Display Manager|login manager]] like gdm or kdm, or with {{ic|exec ck-launch-session <window-manager>}}. Also, upower needs to be installed.}}
+
 
 +
{{Note|The user's [[window manager]] or [[desktop environment]] needs to be started either with a [[login manager]] like gdm or kdm. Also, upower needs to be installed.}}
  
 
=== With systemd ===
 
=== With systemd ===
Line 151: Line 151:
 
After that, execute {{ic|systemctl hibernate}} to put your system into hibernation. Do similar changes for systemd-hybrid-sleep.service to enable uswsusp-based hybrid sleep too.
 
After that, execute {{ic|systemctl hibernate}} to put your system into hibernation. Do similar changes for systemd-hybrid-sleep.service to enable uswsusp-based hybrid sleep too.
  
== Further reading ==
+
== Troubleshooting ==
 +
 
 +
=== My machine is not whitelisted ===
 +
 
 +
If {{ic|s2ram}} doesn't match your machine to an entry in its whitelist, it will output some general purpose identification strings for your machine (the same as those provided {{ic|s2ram -i}}). In this case, you may try to force {{ic|s2ram}} to suspend your machine by using {{ic|s2ram -f}}.
 +
 
 +
=== {{ic|s2ram -f}} doesn't work ===
 +
 
 +
If {{Ic|s2ram -f}} doesn't work, try the different workarounds offered by {{Ic|s2ram}}. Run {{Ic|s2ram -h}} to get a list of the possible options:
 +
{{hc|# s2ram -h|<nowiki>
 +
Usage: s2ram [-nhi] [-fspmrav]
 +
 
 +
Options:
 +
    -h, --help:      this text.
 +
    -n, --test:      test if the machine is in the database.
 +
                      returns 0 if known and supported
 +
    -i, --identify:  prints a string that identifies the machine.
 +
    -f, --force:      force suspending, even on unknown machines.
 +
 
 +
The following options are only available with -f/--force:
 +
    -s, --vbe_save:  save VBE state before suspending and restore after resume.
 +
    -p, --vbe_post:  VBE POST the graphics card after resume
 +
    -m, --vbe_mode:  get VBE mode before suspend and set it after resume
 +
    -r, --radeontool: turn off the backlight on radeons before suspending.
 +
    -a, --acpi_sleep: set the acpi_sleep parameter before suspend
 +
                      1=s3_bios, 2=s3_mode, 3=both
 +
    -v, --pci_save:  save the PCI config space for the VGA card.
 +
</nowiki>}}
 +
 
 +
Try the following variations:
 +
  s2ram -f -a 1
 +
  s2ram -f -a 2
 +
  s2ram -f -a 3
 +
  s2ram -f -p -m
 +
  s2ram -f -p -s
 +
  s2ram -f -m
 +
  s2ram -f -s
 +
  s2ram -f -p
 +
  s2ram -f -a 1 -m
 +
  s2ram -f -a 1 -s
 +
 
 +
If none of those combinations work, start again but add the {{ic|-v}} switch.
 +
 
 +
Note that mixing the {{ic|-a}} options and the vbetool options ({{ic|-p}}, {{ic|-m}}, {{ic|-s}})
 +
is normally only a measure of last resort, it usually does not make much
 +
sense.
 +
 
 +
If you find several combinations that work (e.g. {{ic|s2ram -f -a 3}} and {{ic|s2ram -f -p -m}} both work on your machine),
 +
the in-kernel method ({{ic|-a}}) should be preferred over the userspace methods ({{ic|-p}}, {{ic|-m}}, {{ic|-s}}).
 +
 
 +
Verify all combinations in both cases when reporting success to the {{ic|s2ram}} developers:
 +
* when issuing {{ic|s2ram}} from console
 +
* when issuing {{ic|s2ram}} from X
 +
 
 +
=== s2ram does not work with any combination of options ===
 +
 
 +
There is a trick which does not correspond to a command line option, because it requires additional operations from you. It is marked with NOFB in the whitelist and used for those laptops which suspend and resume properly only if no framebuffer is used. If you verify that no command line option of {{Ic|s2ram}} works, you can try disabling the framebuffer. To do this, you need to edit your bootloader configuration, remove any possible {{Ic|1=vga=<foo>}} values from the kernel line and reboot. This at least if you use the VESAFB framebuffer (as in the arch default kernel). If you use a different framebuffer driver, refer to the documentation of the driver to see how to disable it.
 +
 
 +
== See also ==
  
Most of this page is adapted/copied from the [http://git.kernel.org/?p=linux/kernel/git/rafael/suspend-utils.git;a=blob;f=HOWTO;h=116cddaa76cbdec69eb8b1e87b7df8931d3a73da;hb=HEAD HOWTO file] included with the source code. <br />
+
* [http://suspend.sourceforge.net/ Uswsusp Home Page]
The introduction is from http://suspend.sourceforge.net/intro.shtml
+
* [http://git.kernel.org/?p=linux/kernel/git/rafael/suspend-utils.git;a=blob;f=HOWTO;h=116cddaa76cbdec69eb8b1e87b7df8931d3a73da;hb=HEAD HOWTO file] included with the source code
 +
* {{ic|/usr/share/doc/suspend/README}} Uswsusp Documentation
 +
* {{ic|/usr/share/doc/suspend/README.s2ram-whitelist}} s2ram-whitelist README

Latest revision as of 12:35, 28 March 2016

uswsusp (userspace software suspend) is a set of user space tools used for hibernation (suspend-to-disk) and suspend (suspend-to-RAM or standby) on Linux systems. It consists of:

  • s2ram - a wrapper around the kernel's suspend-to-RAM mechanism allowing the user to perform some graphics adapter manipulations from the user land before suspending and after resuming that may help to bring the graphics (and the entire system) back to life after the resume. Incorporates the functionality of vbetool and radeontool as well as some tricks of its own. Includes a list of working hardware configurations along with the appropriate sets of operations to be performed to resume them successfully. This is accomplished by a hardware whitelist maintained by HAL - s2ram translates the HAL database options into s2ram parameters.
Note: Since HAL is deprecated and KMS drivers can save the state of the grahic card directly without userspace quirks, s2ram development is discontinued and no further whitelist entries are accepted. If a KMS driver is in use, s2ram will directly suspend the machine.
  • s2disk - the reference implementation of the userspace software suspend (µswsusp); it coordinates the steps necessary to suspend the system (such as freezing the processes, preparing the swap space, etc.) and handles image writing and reading. s2disk already supports compression and encryption of the image and other features (e.g. a nice progress bar, saving the image on a remote disk, playing tetris while resuming, etc.) can be easily added.
  • s2both - combines the funtionalities of s2ram and s2disk and it's very useful when the battery is almost depleted. s2both writes the system snapshot to the swap (just like s2disk) but then puts the machine into STR (just like s2ram). If the battery has enough power left you can quickly resume from STR, otherwise you can still resume from disk without losing your work.

Installation

uswsusp is available in the AUR under the name uswsusp-gitAUR.

Configuration

You must edit /etc/suspend.conf before attempting to suspend to disk.

  • If using a swap partition:
resume device = /dev/disk/by-label/swap

where /dev/disk/by-label/swap must be replaced with the correct block device containing the swap partition.

resume device = /dev/sdXN  # the partition which contains swapfile 
resume offset = 123456

where 123456 is the offset from the beginning of the resume device where the swap file's header is located. The resume offset can be obtained by running

# swap-offset your-swap-file
  • The image size parameter (optional) can be used to limit the size of the system snapshot image created by s2disk. If it's not possible to create an image of the desired size, s2disk will suspend anyway, using a bigger image. If image size is set to 0, the image will be as small as possible.
  • The shutdown method parameter (optional) specifies the operation that will be carried out when the machine is ready to be powered off. If set to "reboot" the machine will be rebooted immediately. If set to "platform" the machine will be shut down using special power management operations available from the kernel that may be necessary for the hardware to be properly reinitialized after the resume, and may cause the system to resume faster.
  • If the compute checksum parameter is set to 'y', the s2disk and resume tools will use the MD5 algorithm to verify the image integrity.
  • If the compress parameter is set to 'y', the s2disk and resume tools will use the LZF compression algorithm to compress/decompress the image.
  • If splash is set to 'y', s2disk and/or resume will use a splash system. Currently splashy and fbsplash are supported.
    Note: This requires additional configure flags for uswsusp (--enable-splashy and --enable-fbsplash, respectively).
  • The resume pause option will introduce a delay after successfully resuming from hibernation, in order to allow the user to read the stats (read and write speed, image size, etc.)
  • If threads is enabled, s2disk will use several threads for compressing, encrypting and writing the image. This is supposed to speed things up. For details, read the comments in suspend.c

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;
encrypt = y
RSA key file = <path_to_keyfile>

Recreate initramfs

Note: Whenever you modify /etc/suspend.conf, you will need to rebuild your initramfs. If you fail to do so, and linux cannot find your image at startup, you will not see an error message indicating this. Your boot process will hang after starting the uresume hook, typically after the message with the libgcrypt version.

Edit your /etc/mkinitcpio.conf file and add "uresume" to the HOOKS entry.

HOOKS="base udev autodetect block uresume filesystems"
  • rebuild the ramdisk
# mkinitcpio -p linux

Sample config

/etc/suspend.conf
snapshot device = /dev/snapshot

resume device = /dev/disk/by-label/swap

# image size is in bytes
image size = 1468006400

#suspend loglevel = 2

compute checksum = y

compress = y

#encrypt = y

#early writeout = y

#splash = y

# up to 60 (seconds)
#resume pause = 30  

threads = y

Usage

Standalone

To suspend to disk, run:

# s2disk

To suspend to ram, first run:

# s2ram --test

to see if your machine is in the database of machines known to work. If it returns something like "Machine matched entry xyz" then go ahead and run:

# s2ram

Otherwise, the --force parameter will be necessary, possibly combined with other parameters (see s2ram --help). It may fail.

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

# s2disk

It is probably necessary to resort to a userspace tool which calls internally s2disk, like Pm-utils or hibernate-script. See Suspending to Disk with hibernate-script about details for defining the ususpend-disk method as default.

With pm-utils

Tango-view-refresh-red.pngThis article or section is out of date.Tango-view-refresh-red.png

Reason: Since February 2013, the suspend and hibernate functions in UPower have been deprecated. (Discuss in Talk:Uswsusp#)
Pm-utils can utilise several sleep back-ends, including uswsusp. Create or edit /etc/pm/config.d/module:
SLEEP_MODULE=uswsusp

This way, pm-suspend and pm-hibernate will use uswsusp. There is an advantage to this: regular users can use these commands to suspend with uswsusp:

$ dbus-send --system --print-reply --dest="org.freedesktop.UPower" /org/freedesktop/UPower org.freedesktop.UPower.Suspend

$ dbus-send --system --print-reply --dest="org.freedesktop.UPower" /org/freedesktop/UPower org.freedesktop.UPower.Hibernate
Note: The user's window manager or desktop environment needs to be started either with a login manager like gdm or kdm. Also, upower needs to be installed.

With systemd

To to put your system into hibernation a.k.a Suspend to Disk with systemctl hibernate, do:

# cp /usr/lib/systemd/system/systemd-hibernate.service /etc/systemd/system/
# cd /etc/systemd/system/

Open systemd-hibernate.service with your preferred text editor and edit the line from this:

/etc/systemd/system/systemd-hibernate.service
...
ExecStart=/usr/lib/systemd/systemd-sleep hibernate

to this:

/etc/systemd/system/systemd-hibernate.service
...
ExecStart=/bin/sh -c 's2disk && run-parts --regex .\* -a post /usr/lib/systemd/system-sleep'

After that, execute systemctl hibernate to put your system into hibernation. Do similar changes for systemd-hybrid-sleep.service to enable uswsusp-based hybrid sleep too.

Troubleshooting

My machine is not whitelisted

If s2ram doesn't match your machine to an entry in its whitelist, it will output some general purpose identification strings for your machine (the same as those provided s2ram -i). In this case, you may try to force s2ram to suspend your machine by using s2ram -f.

s2ram -f doesn't work

If s2ram -f doesn't work, try the different workarounds offered by s2ram. Run s2ram -h to get a list of the possible options:

# s2ram -h
Usage: s2ram [-nhi] [-fspmrav]

Options:
    -h, --help:       this text.
    -n, --test:       test if the machine is in the database.
                      returns 0 if known and supported
    -i, --identify:   prints a string that identifies the machine.
    -f, --force:      force suspending, even on unknown machines.

The following options are only available with -f/--force:
    -s, --vbe_save:   save VBE state before suspending and restore after resume.
    -p, --vbe_post:   VBE POST the graphics card after resume
    -m, --vbe_mode:   get VBE mode before suspend and set it after resume
    -r, --radeontool: turn off the backlight on radeons before suspending.
    -a, --acpi_sleep: set the acpi_sleep parameter before suspend
                      1=s3_bios, 2=s3_mode, 3=both
    -v, --pci_save:   save the PCI config space for the VGA card.

Try the following variations:

  s2ram -f -a 1
  s2ram -f -a 2
  s2ram -f -a 3
  s2ram -f -p -m
  s2ram -f -p -s
  s2ram -f -m
  s2ram -f -s
  s2ram -f -p
  s2ram -f -a 1 -m
  s2ram -f -a 1 -s

If none of those combinations work, start again but add the -v switch.

Note that mixing the -a options and the vbetool options (-p, -m, -s) is normally only a measure of last resort, it usually does not make much sense.

If you find several combinations that work (e.g. s2ram -f -a 3 and s2ram -f -p -m both work on your machine), the in-kernel method (-a) should be preferred over the userspace methods (-p, -m, -s).

Verify all combinations in both cases when reporting success to the s2ram developers:

  • when issuing s2ram from console
  • when issuing s2ram from X

s2ram does not work with any combination of options

There is a trick which does not correspond to a command line option, because it requires additional operations from you. It is marked with NOFB in the whitelist and used for those laptops which suspend and resume properly only if no framebuffer is used. If you verify that no command line option of s2ram works, you can try disabling the framebuffer. To do this, you need to edit your bootloader configuration, remove any possible vga=<foo> values from the kernel line and reboot. This at least if you use the VESAFB framebuffer (as in the arch default kernel). If you use a different framebuffer driver, refer to the documentation of the driver to see how to disable it.

See also

  • Uswsusp Home Page
  • HOWTO file included with the source code
  • /usr/share/doc/suspend/README Uswsusp Documentation
  • /usr/share/doc/suspend/README.s2ram-whitelist s2ram-whitelist README