Enable Suspend2 Hibernation support on VectorLinux 5.8 StandardIntroduction:
This HowTo will guide you through the necessary steps to take in order to achieve full hibernation/suspend support on VectorLinux 5.8 Standard.
You may probably use this info for older or newer versions of VectorLinux, but then make sure you change relevant details as you go along (version numbers, etc...). Also don't hesitate to ask in the main forum if you have any doubts.
VectorLinux 5.8 SOHO and above will most likely have Suspend2 hibernation support patched in already.
It may be a good idea to read through this HowTo before doing anything. That way, you can have an idea of what you will need to do and plan ahead.
Get all your tools lined up before starting any job!
Some trivial information:
For most Windows users, using the "suspend" or "hibernate" with laptops (when closing the laptop lid or when the battery reaches a critically low charge) is very natural and taken for granted to a large extent.
Suspending a running session so that your computer can power off in a way that will enable you to resume that session seamlessly later on is not exactly child's play, considering that the risks involved are possible data loss and severe filesystem corruption.
So one could assume Microsoft has an army of engineers working on Windows' hibernation/suspend support to make sure that it works generically on most laptops.
The Linux kernel also has its own hibernate/suspend support called Software Suspend
. But it is not very up-to-date when compared to the hibernate/suspend support provided by the Software Suspend 2
fork project (Suspend2
So we will be working with Suspend2 1 - What you need:
- A fresh install of VectorLinux 5.8 Standard (preferably).
- A working Internet connection (128kbps or above, since you will need to download about 40MB of data).2 - Before getting started:
Although Suspend2 provides a very stable and reliable way to hibernate your computer, it goes without saying that things can still go wrong!
And when dealing with things like machine hibernating, there is a risk that you may lose data (especially when running the initial tests), so MAKE SURE YOU BACKUP ALL YOUR DATA FIRST!
It may even be a good idea to run your first tests on an "expendable" installation of VectorLinux done on a separate partition.3 - Get all the necessary source code
You will need to recompile your kernel (nothing extra-ordinary so don't run away yet!
), you will have to get the source code from the Linux Kernel project archives.
If you don't want to go to too much trouble then I suggest that you stick to 2.6.19.x at the most, since 2.6.20 doesn't seem to play nicely with VectorLinux 5.8 Standard's firewall.
You may compile a 2.6.20 kernel or above, but it might require a bit more tinkering with the iptables modules, which is not covered here.
At the time this HowTo was written, the newest 2.6.19 kernel was revision 7 (220.127.116.11).
So open a terminal and logon as root. Then navigate to /usr/src:
Download the kernel source tarball with wget:
Extract the tarball:
tar xvfj linux-18.104.22.168.tar.bz2
That will probably take some time to extract. When its done, then enter the newly created source directory:
Next thing to do is to download the Suspend2 kernel source patch, which after applied will give the kernel Suspend2 support.
Decompress the patch:
Apply the patch with the following command:
patch -Np1 -i ./suspend2-2.2.9-for-2.6.19.patch
The patching should occur without ANY errors or warnings. You should see something like this in your terminal when its done (the list here is cut short because its very long):
vector://usr/src/linux-22.214.171.124 - Configuring, building and installing your Suspend2 enabled kernel:
root:# patch -Np1 -i ./suspend2-2.2.9-for-2.6.19.patch
patching file Documentation/kernel-parameters.txt
patching file Documentation/power/Suspend2-Changelog.txt
patching file Documentation/power/suspend2-internals.txt
patching file Documentation/power/suspend2.txt
patching file MAINTAINERS
patching file arch/arm/kernel/signal.c
patching file arch/avr32/kernel/signal.c
patching file arch/frv/kernel/signal.c
patching file arch/h8300/kernel/signal.c
patching file arch/i386/kernel/io_apic.c
patching file arch/i386/mm/init.c
patching file arch/i386/power/Makefile
patching file arch/m32r/kernel/signal.c
patching file arch/powerpc/kernel/Makefile
patching file arch/powerpc/kernel/signal_32.c
patching file arch/sh/kernel/signal.c
patching file arch/sh64/kernel/signal.c
patching file arch/x86_64/kernel/Makefile
patching file arch/x86_64/kernel/suspend.c
patching file arch/x86_64/kernel/time.c
patching file mm/pdflush.c
patching file mm/vmscan.c
patching file net/rxrpc/krxiod.c
patching file net/rxrpc/krxsecd.c
patching file net/rxrpc/krxtimod.c
patching file net/sunrpc/svcsock.c
Configuring the kernel's sources can be tricky if you have to do it from scratch, but to get around that you can also simply use the kernel configuration that was provided by default with VectorLinux kernel.
This will save you lots of time, and is much easier if you are not familiar with the ins-and-outs of Linux kernel.
Still as root and in the kernel source directory(/usr/src/linux-126.96.36.199/), copy the default VL kernel configuration file:
cp /boot/config-188.8.131.52 ./.config
Now run this command to get the configuration editor:
You will see some stuff going on in you terminal. Shortly after a window will appear that looks like this: http://vectorlinux.osuosl.org/easuter/xconfig_main_window.png
Locate the option called "Suspend2" and mark the checkbox. A submenu will unfold on the right side of the window with more options. Mark the "Swap Allocator" option and make sure that "Replace swsusp by default" is also checked, as demonstrated in this screenshot:http://vectorlinux.osuosl.org/easuter/xconfig_suspen2.png
Now scroll down the left side of the screen and click on "Cryptographic options". On the right side of the window, click on the "LZF compression algorithm" option box until you get a check-mark. Make sure you mark it with a check-mark and not a dot!
Here is another example screenshot:http://vectorlinux.osuosl.org/easuter/xconfig_LZF.png
If you know what you are doing, you can also add some extra customizations.
Otherwise, click on the Save
button and then exit.
You should be returned to the command prompt.
Next issue this command:
make bzImage && make modules
This can take quite a while depending on how fast your computer is (but it will take at least an hour).
When it is finished, then do the following (still in the kernel source directory):
Copy the new kernel boot image to /boot:
cp ./arch/i386/boot/bzImage /boot/vmlinuz-184.108.40.206_suspend2
Copy the configure file you used and the new system map to /boot:
cp ./.config /boot/config-220.127.116.11_suspend2
cp ./System.map /boot/System.map-18.104.22.168_suspend2
Install the modules that you built:
Now we must enter the /boot directory and do update a few symbolic links:
rm vmlinuz config System.map
ln -sf vmlinuz-22.214.171.124_suspend2 vmlinuz
ln -sf config-126.96.36.199_suspend2 config
ln -sf System.map-188.8.131.52_suspend2 System.map
Those new symbolic links will make the new kernel you built the default one.
Next, make some necessary changes to lilo (adding the swap drive to be used by Suspend2 and making a backup boot entry).
(with any editor you want, doesn't have to be mcedit):
Add append = "resume2=swap:/dev/hdXY"
to each lilo entry, where XY are the drive labels for your swap partition.
My swap partition is located on /dev/hda1, so the line will look like this:append = "resume2=swap:/dev/hda1"
Here is my lilo.conf as an example:
# LILO configuration file
# generated by 'liloconfig'
# Start LILO global section
boot = /dev/hda2
default = linux
timeout = 1200
# Override dangerous defaults that rewrite the partition table:
bitmap = /boot/bitmap/boot.bmp
# Normal VGA console
#vga = normal
# VESA framebuffer console @ 1024x768x64k
# VESA framebuffer console @ 1024x768x32k
# VESA framebuffer console @ 1024x768x256
# VESA framebuffer console @ 800x600x64k
# VESA framebuffer console @ 800x600x32k
# VESA framebuffer console @ 800x600x256
# VESA framebuffer console @ 640x480x64k
# VESA framebuffer console @ 640x480x32k
# VESA framebuffer console @ 640x480x256
# End LILO global section
# Partition 1: Linux GUI mode
image = /boot/vmlinuz
root = /dev/hda2
label = linux
append = "resume2=swap:/dev/hda1"
# Partition 2: Linux TUI mode
image = /boot/vmlinuz
root = /dev/hda2
label = linux-tui
append = "2 resume2=swap:/dev/hda1"
# Partition 4: Linux
image = /boot/vmlinuz-184.108.40.206
root = /dev/hda2
label = 220.127.116.11
append = " "
As you can see, I added a backup entry called "18.104.22.168", so that I can still boot the vmlinuz-22.214.171.124 kernel image if things go sour.
Save the file, and run:
If everything runs ok and lilo doesn't abort, then reboot your computer.
When the lilo splash comes up, then select the "linux" option, if you have the same settings as my lilo.conf (or whatever other label is associated to the new kernel you built).
Your computer should boot as usual. Once you have loged in, then open a terminal and type:
You should see this:126.96.36.199 GNU/Linux
That means your new kernel has booted and it up-and-running!5 - Installing the hibernation/suspend scripts, configuration files and manual pages:
The next thing to do is to get the scripts that will provide the suspend/hibernate commands.
In your terminal, logon as root and then enter the /tmp directory:
Download the Suspend2 hibernation scripts tarball:
There is a newer version, 1.94, but it seems to be either lacking a configuration file or a patch that then makes the install script fail.
Version 1.93 will work just fine though.
Decompress the tarball:
tar xvfz hibernate-script-1.93.tar.gz
Enter the newly created decompressed directory:
Before running the installation script (install.sh), you must modify it so that it fits Vector's installation prefixes:
Change this line:[ -z "$PREFIX" ] && PREFIX=/usr/local
To this:[ -z "$PREFIX" ] && PREFIX=/usr
Save the file, and then run it:
After the files have been installed, then go into /etc/hibernate so we can make some changes:
cp common.conf.dist common.conf
Thats pretty much it as far as installing the scripts goes.6 - Testing the hibernation support
After installing those scripts, a new executable file will appear in /usr/sbin called hibernate
That is the file you will be calling at the command line to hibernate or suspend your machine.
Note that all the configuration options that are set now are the default ones, so you will have to adjust settings as you go along.
The Suspend2 FAQ page lists several issues you might run into, depending on your hardware:http://www.suspend2.net/FAQ-4.html#ss4.1
And you won't know if you have those problems until you test everything...
In your terminal emulator (still as root), run:
hibernate -v 3
The -v 3
switch will enable high verbosity, so if you encounter problems then they will show up in your terminal in great detail.
The hibernate process should start by blanking out the screen and reporting its progress until the computer powers down.
Now turn it on again and boot your new kernel as before.
If all goes well, then you should see the kernel booting as usual for the first few seconds, and then after scanning for devices it should saw something like "Suspend2 2.2.9: resume enabled" and it should resume to where you left off.
One of the first things that may not function properly is num-lock, but I found that pressing the num-lock key 3 times gets it going again
For those with video acceleration drivers, you may (or may not) find that hardware acceleration is gone after resuming.
If that does happen, then append UseDummyXServer
at the end, and save the file.
This option will force Suspend2 to give 3D acceleration modules (like nvidia
) a "wake-up nudge" by momentarily running a fake X server.
If your heatsink fans fail to turn on after waking up from the hibernation, then you will need to add the thermal
modules to the Suspend2 hibernate blacklist:
Add those two to the end of the file, and save it.
The blacklist file (/etc/hibernate/blacklisted-modules) will block potentially problematic modules from being loaded back into memory during the wake-up process. This doesn't mean that you won't be able to use them! It simple doesn't let them load while the un-suspending is taking place, but as soon as that process is completed, the modules will reload when the kernel calls for them.
If you browse through the blacklist you will see that a significant portion of the modules listed there are either network modules or USB modules.
After testing Suspend2 on my PC, the USB modules though blacklisted in Suspend2's blacklist file, are indeed reloaded in the background when I plug in my pendrive, so the blacklist isn't anything scary or to worry about!
For more information on extra blacklisting options, read the commented text at the beginning of /etc/hibernate/blacklisted-modules
7 - Letting all users hibernate
After you have tweaked your settings, its safe to let users access the hibernate function. This is indeed useful, especially for allowing hardware sensors to hibernate your laptop when the battery runs low, or when your PC's UPS reaches a critical charge.
In this section, you will be guided through creating a new sudo group and policy, and adding users to that group.
Firstly, you must change the hibernate script's access rules, so that only root can call it.
In your terminal, as root, type in this command:
chmod 744 /usr/sbin/hibernate
Now, to create a new group called hibernate:
Make a backup of the sudoers file, and create a new sudo policy that will allow users belonging to that group to access /usr/sbin/hibernate
will full root permissions:
cp /etc/sudoers /etc/sudoers.BAK
Add these lines to the end of the file:
#Allow users to access the Suspend2 hibernate script:
%hibernate ALL=(root) NOPASSWD: /usr/sbin/hibernate
Next, you will need to create a file that will run the sudo command (and a few others too), that is accessible to all users:
Enter these lines into the file:
#Add any custom pre-hibernation commands here:
#Call sudo with hibernate script:
sudo /usr/sbin/hibernate $*
Save the file.
Make the file executable to all users:
chmod 755 /usr/bin/user-hibernate
Associate the user-hibernate script to the hibernate group:
chgrp hibernate /usr/bin/user-hibernate
Add your username to the hibernate group:
gpasswd -a xxxxx hibernate
with your username.
Repeat the gpasswd
command for any other users you also wish to allow hibernate access.
Now to test the hibernate support as a regular user, open a terminal as a regular user and run:
If all goes well, your computer will hibernate properly, as though the command were run as root.
Note that once a hibernation has been resumed, the next time you reboot or shut down your computer will work as it usually does. Suspend2 won't interfere with anything unless you run the hibernation script.8 - Making your laptop hibernate when the battery runs low:
If you are using VectorLinux 5.8 Standard and Xfce as your graphical environment, then you can use the Battery Monitor
applet to call the user-hibernate script when your battery runs low on power.
You may already have the Battery Monitor applet active on your taskbar if you are using a laptop, but if you don't then right click on the Xfce panel, and select Add New item
From the window that appears, select Battery Monitor
and press Add
A new applet will appear on your taskbar with a percentage bar indicating your battery's current status.
Right-click on the applet and select Properties
A window will pop up with the Battery Monitor applet's options.
Depending on how well you know your battery, you may change the low
and critical percentage
values in the Battery Monitor window; however, since the hibernation process consumes lots of processing power and also generates a considerable amount of hard-drive activity, and thus consumes lots of precious battery power too, you don't want the battery to die on you while the suspend is taking place. So the safe zone for the critical percentage for a battle-worn battery is probably about 5 to 6%, and a new battery 2 to 3%.
In the Low battery action
field, select Display a warning message
from the drop-down menu. You don't necessarily have to set it to this value, but it is nice to be warned when your battery is on its last breath.
In the Critical battery action
field, select Run command
. Right beneath that, there is a text-box where you can enter the desired command when the battery reaches critical condition. So in the Command
text-box, enter the user-hibernate script's full path, as follows: /usr/bin/user-hibernate
Here is also a complementary screenshot to help you in case you are having trouble:http://vectorlinux.osuosl.org/easuter/battery_monitor.png
For those not using Xfce (neither KDE), then this Gentoo Wiki section will help you configure ACPI to monitor you battery:http://gentoo-wiki.com/HOWTO_Software_Suspend_v2#Suspend_when_battery_is_low
It is very detailed, so I wont echo it here.9 - Taking protective measures to prevent data loss:
When Suspend2 hibernates your machine, it makes a "carbon copy" of whatever is loaded in your computer's memory, compresses that copy and stores it in your swap partition.
When you resume a hibernated session, Suspend2 will decompress and reload that copy it made.
That means that Suspend2 also expects to find your hard-drive in the exact same state as when it hibernated your computer.
So if Suspend2 reloads its "carbon copy" of your session and things have changed on your hard-drive (or pendrive for that matter), then there will be conflicting information about what data is supposed to exist.
This will lead to filesystem corruption, which means that your ENTIRE partition will get "scrambled". And in a very severe fashion too...
If you are using ext2 or ext3 filesystems, there way be a possibility of trying to recover from that filesystem crash by using the e2fsck command.
If you are using ReiserFS (which already has integrity problems of it own), then recovery of your partition is most likely futile.
So never modify the contents of a suspended drive!
This problem can be circumvented of course.
You may have noticed that the user-hibernate script runs vlh-umount before running the hibernate command.
This way, any hot-plugged devices will be synced and unmounted before the hibernate process takes place.
The same can be done for other mounted devices (a Windows partition for example) by adding the appropriate unmount commands in the user-hibernate
script.10 - Extra reading (troubleshooting, and more information):
Suspend2 FAQ pages:http://www.suspend2.net/FAQ-4.html#ss4.1http://www.suspend2.net/FAQ.html#toc4
Relevant information from the Gentoo Wiki (from ACPI configuration onward):http://gentoo-wiki.com/HOWTO_Software_Suspend_v2#ACPI_configuration_-_use_your_power_button_to_suspend11 - Final notes:This HowTo is not intended as a RTFM "gag"
If you are having problems, then don't hesitate to ask!
Improvements to this HowTo are welcome.12 - Enjoy hibernation support!
Yep, it does feel good, and is addictive too