https://wiki.archlinux.org/api.php?action=feedcontributions&user=MohammadRRR&feedformat=atomArchWiki - User contributions [en]2024-03-28T10:54:54ZUser contributionsMediaWiki 1.41.0https://wiki.archlinux.org/index.php?title=Suspending_to_RAM_with_hibernate-script&diff=110082Suspending to RAM with hibernate-script2010-06-30T11:17:10Z<p>MohammadRRR: /* s2ram */</p>
<hr />
<div>[[Category:Power management (English)]] [[Category:Laptops (English)]] [[Category:HOWTOs (English)]]<br />
{{Article summary start| Summary }}<br />
{{Article summary text|Instructions on suspending to RAM, primarily focused on hibernate-script}}<br />
{{Article summary heading|Language}}<br />
{{i18n_entry|English|Suspending to RAM with hibernate-script}}<br />
{{Article summary heading|Related}}<br />
{{Article summary wiki|Suspending to Disk with hibernate-script}}<br />
{{Article summary wiki|pm-utils}}<br />
{{Article summary wiki|Laptop}}<br />
{{Article summary end}}<br />
In this article we will explain how to accomplish a successful suspension to RAM using hibernate-script: all the processes are stopped and the current state of your machine is saved to RAM. All the devices enter a low-consumption state and it will be very fast to resume the machine.<br />
Suspension to RAM is an acpi state, but the operation is almost never as simple as telling the machine to enter that state. The vast majority of laptops require additional operations and tricks. However, since this is quite an important feature for laptop users, it is worth spending some hours in finding the working combinations of tricks for your machine.<br />
<br />
====Different methods of suspending to RAM====<br />
There is an application, called s2ram, which contains a "whitelist" of known laptop models and, according to what has been reported by other owners of these laptops, tries to do the right things for that specific laptop. The whitelisted laptops can therefore use s2ram to suspend to RAM "out of the box". Non-whitelisted laptops need to try different command line options of s2ram in order to determine - by trial and error - the appropriate "tricks" needed to make suspend and resume work. Your experience, if reported to the s2ram developers, will contribute to whitelist your machine in the next release of s2ram.<br />
<br />
However, s2ram is not the only resource: the hibernate-script, which is commonly used to accomplish [[Suspend to Disk]] , supports also suspension to RAM and proposes some further tricks which could convince your machine to suspend to RAM and resume properly. Moreover, the hibernate-script can automatize other useful operations which you could want/need to do before suspension or after resuming from suspension to RAM.<br />
<br />
Thus, the first part of this article will be devoted to s2ram. The second will discuss the use of the hibernate-script in suspension to RAM. In particular, we will see how the hibernate-script can be used to suspend to RAM your system just with the s2ram, but providing some additional tweakings. Finally, we will mention the possibility to suspend the machine both to RAM and to disk.<br />
<br />
===s2ram===<br />
The s2ram utility is part of the uswsusp collection, which includes also some goodies relative to [[Suspend to Disk]] . You can find uswsusp in the community repositories. <br />
# pacman -S uswsusp<br />
<br />
Read the notes provided by pacman during the ''uswsusp'' package installation. In essence, you will need to:<br />
* edit /etc/suspend.conf to specify the resume device, i.e. your swap partition.<br />
resume device = /dev/sd''XY''<br />
* update /etc/mkinitcpio.conf to include the ''resume'' hook<br />
HOOKS="base udev autodetect pata scsi sata ''resume'' filesystems"<br />
* rebuild the ramdisk<br />
mkinitcpio -p kernel26<br />
<br />
====Testing====<br />
After installing the uswsusp package, check to see whether s2ram recognizes your machine: <br />
# s2ram -n<br />
<br />
If you see a line that says "Machine matched entry #", then your machine is already whitelisted. You SHOULD be able to suspend and resume properly by simply running s2ram:<br />
# s2ram<br />
<br />
Please note that the way to trigger resume from a suspended to RAM machine depends from your BIOS settings and is not predictable in general (sometimes it is enough to press a key whatsoever). If s2ram seems to work, but something goes wrong in the suspension cycle, then some driver or some process is causing problems and you should look at the hibernate section to see how the hibernate-script can help you. In the worst case, your machine has been erroneously whitelisted due to an inadequate report from another owner of the same machine. You should then report your case to the suspend-devel@lists.sourceforge.net, so that the previous mistaken report can stand corrected. In this case, you should quote the identification strings provided by s2ram -i.<br />
<br />
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 will have to force s2ram to suspend your machine by using s2ram -f.<br />
<br />
<br />
If '''s2ram -f''' doesn't work, try the different workarounds offered by s2ram. Run s2ram -h to get a list of the possible options:<br />
# s2ram -h<br />
Usage: s2ram [-nhi] [-fspmrav]<br />
<br />
Options:<br />
-h, --help: this text.<br />
-n, --test: test if the machine is in the database.<br />
returns 0 if known and supported<br />
-i, --identify: prints a string that identifies the machine.<br />
-f, --force: force suspending, even on unknown machines.<br />
<br />
The following options are only available with -f/--force:<br />
-s, --vbe_save: save VBE state before suspending and restore after resume.<br />
-p, --vbe_post: VBE POST the graphics card after resume<br />
-m, --vbe_mode: get VBE mode before suspend and set it after resume<br />
-r, --radeontool: turn off the backlight on radeons before suspending.<br />
-a, --acpi_sleep: set the acpi_sleep parameter before suspend<br />
1=s3_bios, 2=s3_mode, 3=both<br />
-v, --pci_save: save the PCI config space for the VGA card.<br />
<br />
Try the following variations:<br />
s2ram -f -a 1<br />
s2ram -f -a 2<br />
s2ram -f -a 3<br />
s2ram -f -p -m<br />
s2ram -f -p -s<br />
s2ram -f -m<br />
s2ram -f -s<br />
s2ram -f -p<br />
s2ram -f -a 1 -m<br />
s2ram -f -a 1 -s<br />
<br />
If none of those combinations work, start again but add the "-v" switch.<br />
<br />
Note that mixing the "-a" options and the vbetool options ("-p", "-m", "-s")<br />
is normally only a measure of last resort, it usually does not make much<br />
sense.<br />
<br />
<br />
If you find several combinations that work (e.g. "s2ram -f -a 3" and "s2ram -f -p -m" both work on your machine),<br />
the in-kernel method ("-a") should be preferred over the userspace methods ("-p", "-m" and "-s").<br />
<br />
Verify all combinations in both cases when reporting success to the s2ram developers:<br />
* when issuing s2ram from console<br />
* when issuing s2ram from X<br />
<br />
You should really try ANY combination of these options (the only exception is the radeontool one, which can be useuful only if you have a radeon card), until you find a working combination. When you find a working combination, try to reduce it (that is try to see if any of the options are redundant). With any working combination of options, it is crucial to verify that suspension and resuming work fine both if you suspend from X and if you suspend from the plain console. Actually, in many setups the most tricky thing is to suspend and resume properly from the console. In the best case, s2ram -f is enough: this means that your machine does not require any trick to properly suspend and resume.<br />
<br />
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 to disable the framebuffer. In order to do this, you need to edit your grub configuration /boot/grub/menu.lst (or the corresponding lilo file), remove the vga=<foo> value from the kernel line and reboot. This at least if you use the VESAFB framebufeer (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. <br />
<br />
After you have identified the shortest working combination of options, you should do two things. First, you will want to modify the whitelist for your local copy of s2ram to allow your machine to suspend and resume without any special options. Second, you will want to let the developers of s2ram know what options are needed for your machine so it can be added to the whitelist for future releases s2ram.<br />
<br />
Finally, it may happen that no trick makes s2ram work. In this case - before giving up - you can use some last-resort tricks provided by the hibernation-script discussed later in this article.<br />
<br />
====Whitelisting====<br />
To add your machine to the local whitelist for s2ram, you need to customize the package from [[ABS]]. Copy the /var/abs/community/uswsusp folder somewhere then run makepkg -o to download the sources. After this, edit the file src/suspend-0.8/whitelist.c<br />
<br />
You will see something like this: <br />
struct machine_entry whitelist[] = {<br />
{ "IBM", "", "ThinkPad X32", "", RADEON_OFF|S3_BIOS|S3_MODE },<br />
/* Michael Wagner <michael-wagner@gmx.de> */<br />
{ "4MBOL&S", "7521 *", "REV. A0", "", 0 },<br />
/* Alexander Wirt */<br />
...<br />
}<br />
<br />
Add a new entry using the same format as the others. The first four fields identify your machine and are provided by:<br />
# s2ram -i<br />
<br />
E.g.:<br />
sys_vendor = "Acer, inc."<br />
sys_product = "Aspire 1640 "<br />
sys_version = "Not Applicable"<br />
bios_version = "3A05"<br />
<br />
Copy these values between the first four sets of quotes. The fifth field identifies which tricks are needed for your machine, seperate each of the tricks with a | character, like the other lines in the file. If no tricks were required, set it to 0.<br />
<br />
Now force a recompilation and reinstallation of uswsusp with makepkg -efi (The -e prevents makepkg from overwriting your customized whitelist.c). Your machine should now suspend properly with a plain:<br />
# s2ram<br />
<br />
You can now report your identification strings and any tricks required to the suspend-devel@lists.sourceforge.net mailing list. Please specify always that everything works both from X and from the plain console.<br />
<br />
=The hibernate-script and suspension to RAM=<br />
The hibernate-script, developed in the field of the tuxonice project for [[Suspend to Disk]], can be used also to suspend your machine to RAM. Actually, you can also try to do this directly, performing the required operations before calling the ACPI S3 state. However, the s2ram seems to be the leading method nowadays and, through the named whitelist, should assure in the future that virtually any laptop can suspend to RAM without too much hassle. So, the actually best way to use the power of the hibernate-script for suspension to RAM is to use it to call s2ram.<br />
<br />
You can edit /etc/hibernate/hibernate.conf to select ususpend-ram.conf as the default action called by:<br />
# hibernate<br />
<br />
Just put the following as the first uncommented line:<br />
TryMethod ususpend-ram.conf<br />
<br />
However, may be that you want to use the hibernate-script primarily to suspend to disk. In that case you should resort to the ram-specific configuration file from the command line:<br />
# hibernate -F /etc/hibernate/ususpend-ram.conf<br />
<br />
Now you should configure the script. Please note that the options that you put in /etc/hibernate/common.conf will be used anytime you call hibernate (that is also for suspension to disk). On the contrary, the options in /etc/hibernate/ususpend-ram.conf will be used only when you suspend to RAM with the s2ram method.<br />
<br />
The hibernate-script options are exhaustively described in the man page hibernate.conf.<br />
<br />
First of all, may be that some module is preventing you from accomplishing a proper suspension cycle. In this case, list it in the UnloadModules: it will be unloaded before suspension and reloaded after resuming. Note that the hibernation script already does this for some blacklisted modules, whose list is /etc/hibernate/blacklisted-modules.<br />
<br />
If you discover that a module is guilty, you should report this to the suspend-devel@lists.sourceforge.net, so that the bad behaviour of the module can be fixed.<br />
<br />
May be also that your display is the guilty and that the tricks provided by s2ram are not enough. The hibernate-script has some further tricks:<br />
<br />
The relevant block of options is the following:<br />
### vbetool<br />
#EnableVbetool yes<br />
#RestoreVbeStateFrom /var/lib/vbetool/vbestate<br />
#VbetoolPost yes<br />
# RestoreVCSAData yes<br />
<br />
### xhacks<br />
#SwitchToTextMode yes<br />
#UseDummyXServer yes<br />
#DummyXServerConfig xorg-dummy.conf<br />
<br />
However, most of these tricks are already attempted by s2ram and you should not duplicate the effort. Only three tricks in this section are specific to the script. The first is to uncomment both the following two lines:<br />
EnableVbetool yes<br />
RestoreVbeStateFrom /var/lib/vbetool/vbestate<br />
<br />
Please note that, while s2ram uses an internal vbetool component, the hibernate-script relies on the vbetool package in the extra repo, so you should install it. Basically, this combination of options do something similar to the --vbe_save s2ram option, but, instead of restoring the state saved immediately before suspension, it restores a state manually saved by the user in the file /var/lib/vbetool/vbestate (or any other file you have chosen). You can try to save the state in a peculiar safe situation, like immediately after booting, or before any switching from X to console and back. You can save the state with the following command:<br />
# vbetool vbestate save > /var/lib/vbetool/vbestate<br />
<br />
The second peculiar trick (very often required!) is to uncomment the following line:<br />
SwitchToTextMode yes<br />
<br />
The script will switch from X to console before suspension and back to X after a successful resuming.<br />
<br />
Finally, the UseDummyXServer trick uses a second XServer, with a minimal safe configuration only during the suspension cycle, restoring the full fledged X server only after a complete resume. This can be useful with cards with problematic proprietary drivers: the dummy xserver will use the standard vesa driver instead. Anyway, this last trick should be seldom useful nowadays, because also proprietary drivers seem to support suspension without too many problems.<br />
<br />
The hibernate-script gives you many other useful possibilities (such as restarting services, unmounting partitions, ejecting pccards, and so on). Read about them in the man pages.<br />
<br />
=s2both=<br />
You can also suspend your machine both to disk and to RAM. This is documented in [[Suspend to Disk#Combining suspend to disk with suspend to RAM|a specific section of the wiki page about suspension to disk]].<br />
<br />
=Automatic suspend and wakeup=<br />
Once you have suspend to RAM working, you will probably want it to happend automatically e.g., when you close the laptop lid.<br />
<br />
There are several ways to do this. The easiest is to use a high-level power management tool such as KDE's PowerDevil. Another is to create your own ACPI event handler scripts.<br />
<br />
==Automatic suspend, the hard way==<br />
ACPI events are managed by configuration files in /etc/acpi/events/. (The laptop-mode-tools package contains some examples). A default configuration file called 'anything' is provided by the acpid package, which runs /etc/acpi/handler.sh on every event.<br />
<br />
An simple event configuration file to manage the opening and closing of a laptop lid (that could be called /etc/acpi/events/lid) looks like this:<br />
event=button[ /]lid<br />
action=/etc/acpi/actions/lid_handler.sh %e<br />
<br />
The first line specifies the names of the events applicable to this file with a regexp. You can get the names of events by enabling event logging in acpid and looking at /var/log/acpid. <br />
<br />
The second line specifies an executable to be run when an applicable event occurs. The '%e' is a variable containing arguments that the event provides. It's a good idea to provide them to the program.<br />
<br />
It's customary to put handling programs in /etc/acpi/actions/. A possible implementation of lid_handler.sh in the previous example could be:<br />
#!/bin/sh<br />
# check if the lid is open or closed, using the /proc file<br />
if grep closed /proc/acpi/button/lid/LID/state >/dev/null ; then<br />
# if the lid is now closed, save the network state and suspend to RAM<br />
netcfg all-suspend<br />
pm-suspend<br />
else<br />
# if the lid is now open, restore the network state.<br />
# (if we are running, a wakeup has already occured!)<br />
netcfg all-resume<br />
fi<br />
<br />
The same example, adapted for wicd instead of netcfg:<br />
#!/bin/sh<br />
# check if the lid is open or closed, using the /proc file<br />
if grep closed /proc/acpi/button/lid/LID/state >/dev/null ; then<br />
# if the lid is now closed, save the network state and suspend to RAM<br />
/usr/lib/wicd/suspend.py<br />
pm-suspend<br />
else<br />
# if the lid is now open, restore the network state.<br />
# (if we are running, a wakeup has already occured!)<br />
/usr/lib/wicd/autoconnect.py<br />
fi<br />
<br />
Remember to make it executable. With some basic knowledge of shell scripting, you have a lot of possibilities.<br />
<br />
==Controlling wakeup ==<br />
The ACPI events that trigger wakeup are controlled through the procfile /proc/acpi/wakeup. An example output is:<br />
root@hex in /proc/acpi $ cat wakeup<br />
Device S-state Status Sysfs node<br />
LID S3 *enabled<br />
PBTN S4 *enabled<br />
MBTN S5 enabled<br />
PCI0 S3 disabled no-bus:pci0000:00<br />
USB0 S0 disabled pci:0000:00:1d.0<br />
USB1 S0 disabled pci:0000:00:1d.1<br />
USB2 S0 disabled pci:0000:00:1d.2<br />
USB3 S0 disabled pci:0000:00:1d.3<br />
EHCI S0 disabled pci:0000:00:1d.7<br />
AZAL S3 disabled pci:0000:00:1b.0<br />
PCIE S4 disabled pci:0000:00:1e.0<br />
RP01 S4 disabled pci:0000:00:1c.0<br />
RP02 S3 disabled<br />
RP03 S3 disabled<br />
RP04 S3 disabled pci:0000:00:1c.3<br />
RP05 S3 disabled<br />
RP06 S3 disabled<br />
<br />
To toggle whether an event will trigger a wakeup, pipe its name into the /proc/acpi/wakeup. (Note that every name in the file must have 4 letters, so if it is shorter e.g. LID, it needs be prepended with spaces). So to prevent opening the laptop lid from triggering a wakeup, you could do:<br />
root@hex in /proc/acpi $ echo " LID" > wakeup<br />
root@hex in /proc/acpi $ cat wakeup<br />
Device S-state Status Sysfs node<br />
LID S3 *disabled<br />
PBTN S4 *disabled<br />
MBTN S5 disabled<br />
PCI0 S3 disabled no-bus:pci0000:00<br />
...<br />
<br />
Another thing to note is that the PBTN and MBTN events were also toggle with the LID event. Sometimes events are linked, so that all of them will be enable and disabled in unison. Checking the 'dmesg' command can confirm this:<br />
root@hex in /proc/acpi $ dmesg<br />
...<br />
ACPI: 'PBTN' and 'LID' have the same GPE, can't disable/enable one separately<br />
ACPI: 'MBTN' and 'LID' have the same GPE, can't disable/enable one separately<br />
<br />
This may not actually affect the other events. On a Dell Inspiron 6400, for example, the power button always triggers a wake up. Your mileage may vary.<br />
<br />
None of this will persist between boots, so you might want to add the echo command to /etc/rc.local so it is executed on every boot:<br />
# disable the laptop lid switch<br />
echo " LID" > /proc/acpi/wakeup</div>MohammadRRR