Step By Step How to get Hibernate Working for Linux (Ubuntu 11.04, Mint 11)

What Hibernation Is and Does

Hibernation takes all the data in your ram and stores it on your hard drive and then powers down the computer. The data is stored in a special type of partition called a swap partition (you can also have a swap file). When you power the computer on again the data stored from your old session is reloaded.

In the following article I am going to lead you through a systematic approach to diagnosing why Linux’s hibernation feature isn’t working on your computer and hopefully fix it. Here’s a Brief overview.

1. Not Enough Swap
2. Your Computer Isn’t Saving Your Session
3. You Computer Isn’t Reading your Saved Session on Boot
4. Your Computer Says “resuming from /dev/sdX” but freezes

1. Not Enough Swap

You should have as much swap as you have RAM plus some margin. If you try to hibernate and you are using more ram than you have swap the process will fail and sometimes hangs. Sometimes there is an error message that says “not enough swap” This is an easy problem to check for. Run the command in red.

chris@Starace ~ $ free -m
             total       used       free     shared    buffers     cached
Mem:         10005       9922         82          0       1647       5844
-/+ buffers/cache:       2430       7574
Swap:         8100          0       8100

The output shows the amount of swap and ram on my computer. As you can see I have 8005 Mb of RAM and I have 8100 Mb of swap. For a hibernate to work you have to have more swap than used RAM not counting cached), Also if you run out of RAM during your session your swap is used. To hibernate you must have free swap greater than the sum of your RAM and your used swap. As a general rule you should have a swap partition slightly bigger than your RAM (hopefully you aren’t using swap during your session, if you are it’s time for a RAM upgrade.)

If you don’t have enough swap or if you don’t have any swap, roll up your sleeves you need to repartition your hard drive.

Repartitioning to add more SWAP

Remember to be careful with your repartitioning, you can destroy your OS easily.

  1. Pull out your bootable CD/Jump Drive and boot It (we can’t repartition the drive we we are using it.)
  2. Run the “gparted” disk utility.
  3. If you have swap, right click -> Delete
  4. Right click on your linux partition -> Resize/Move
  5. Decrease the size of the partition by the amount of space you want to increase your swap. Click Okay
  6. Right click on the free space -> New
  7. Change the File System Type to “linux-swap,” click okay.
  8. Click the apply check mark in the top menu of gparted to apply the changes
  9. Right Click On the new swap partition -> Information
  10. Copy down the UUID value and /dev/sdXN value for later.
Linux Create Parition

Make Sure the File System is linux-swap

uuid info linux

Copy down the UUID and path values. We will use them later.

Note:Remember to be careful with your repartitioning, you can destroy your OS easily. After repartitioning you will need to edit your Linux Hard Drive file. Open up terminal and run the command.

chris@Starace ~ $ sudo gedit /media/NAME_OF_YOUR_COMPUTER/etc/fstab

If you had a swap partition before, look for the line that has the word swap and change the /dev/sdXN to the new /dev/sdXN value. You can also use the UUID instead of the path as shown in red. If never had a swap partition to begin with add the following line to the bottom of the “/media/NAME_OF_YOUR_COMPUTER/etc/fstab” file.


UUID=a453-Your-UUID-Number-ea33 none swap sw

The path variable can change depending on how you have your hard drive plugged in (ex /dev/sda1 -> /dev/sdb1). This usually isn’t a problem if you don’t move your hard drives around in your computer. However, Using a UUID is more reliable. The /dev/sdXN designator can change, but the UUID is unique to the storage device and doesn’t change even if you move to another computer.

After you’ve made the changes to the fstab file, shut down and boot your computer normally. To make sure this all worked run the following command in red. You should see your swap partition listed.

chris@Starace ~ $ cat /proc/swaps
Filename				Type		Size	Used	Priority
/dev/sdNX                         partition	8295420	0	-1

If you see this take you have successfully created/expanded your swap to accommodate hibernation.

2. Your Computer Isn’t Saving Your Session

If you’ve tried to get your computer to hibernate and it didn’t work it’s helpful to look at the hibernation log.

tail /var/log/pm-suspend.log

chris@Starace ~ $ tail  /var/log/pm-suspend.log
Running hook /usr/lib/pm-utils/sleep.d/00powersave thaw hibernate:

/usr/lib/pm-utils/sleep.d/00powersave thaw hibernate: success.
Running hook /usr/lib/pm-utils/sleep.d/00logging thaw hibernate:

/usr/lib/pm-utils/sleep.d/00logging thaw hibernate: success.
Running hook /usr/lib/pm-utils/sleep.d/000kernel-change thaw hibernate:

/usr/lib/pm-utils/sleep.d/000kernel-change thaw hibernate: success.
Sun Jul 24 13:15:14 HST 2011: Finished.

If you see something that has a date and says “Finished” like the what is shown in blue, that means that your computer successfully saved the session. If you see a bunch of errors then get ready to roll up your sleeves again. Unfortunately this is the hardest error to fix. There could be dozens of reasons for this to happen, but in my case it had something to do with binding and unbinding peripheral devices. The following article explains what I did to fix the problem.

http://chriseiffel.com/everything-linux/how-i-got-suspend-and-hibernate-working-in-linux-ubuntu-11-04-mint-11/

One solution that I found that worked for a lot of people, but not me is this simple fix

http://www.ubuntugeek.com/fix-for-suspend-and-hibernation-problem-for-laptops.html/comment-page-2#comment-53547

Don’t lose hope if you get stuck in this step. Instead google everything you can on the problem. Google the errors you see in the log. Someone has solved the problem you just need to find the solution.

3. You Computer Isn’t Reading your Saved Session on Boot

So your computer successfully saves a session, but doesn’t resume the session upon power up? It acts as if it was rebooted rather than hibernated? Well the good news is that this is a fairly easy thing to fix. This is most likely because GRUB the bootloader doesn’t know to resume from your swap. Take a look at the GRUB profile.

chis@Starace ~ $ sudo gedit /etc/default/grub

Look for the line that starts with.

GRUB_CMDLINE_LINUX

Add the following option in red.

GRUB_CMDLINE_LINUX=”resume=UUID=a353e-Your-SWAP-UUID-34eda other-option=value”

Or

GRUB_CMDLINE_LINUX=”resume=/dev/sdXN other-option=value”

You may or may nor have other options. Be careful that you type in the correct path or UUID for the drive here. If you don’t then when you try to resume you will have to boot in safe mode to fix the drive name and re-run the update-grub script. Save the file and then update grub with the following command.

chris@Starace ~ $ sudo update-grub

In addition to grub we need to update/create one more file. Edit the following file.

chris@Starace ~ $ sudo gedit /etc/initramfs-tools/conf.d/resume

Add this line to the file.

resume=UUID=41e86209-3802-424b-9a9d-d7683142dab7

Then run this command to update.

chris@Starace ~ $ sudo update-initramfs -u

Now hibernate your computer and cross your fingers! It just might work.

4. Your Computer Says “resuming from /dev/sdX” but freezes

Linux is so close to hibernating and resuming successfully that it even says it is resuming. Fortunately this is another easy fix. The problem with this comes from two programs that are redundant. Removing them should fix the problem.

chris@Starace: sudo apt-get remove hibernate uswsusp

I know that the command may seem counterintuitive. but it worked for me so hopefully it will work for you.

All Done

Remember to check to make sure your USB ports work after the suspend/hibernate.

If you tried the steps above, please leave a comment below with your system setup (OS, Computer Hardware) so that we can create a reference that others can use.

Also I got a lot of my resources from the Ubuntu page on swap partitions. If you want to learn more about this subject read this article

https://help.ubuntu.com/community/SwapFaq

Happy Linuxing!

This entry was posted in ASUS G53SW Setup, Everything Penguin Related. Bookmark the permalink.

12 Responses to Step By Step How to get Hibernate Working for Linux (Ubuntu 11.04, Mint 11)

  1. zka says:

    The last step did not work for me, I had it to the point where the image was created onscreen: the percents progressed visually. then the same for restoring, hanging after 100% and a few more lines of text.

    after number 4, i can see my hard drive light running hard on hibernate, but no percents or anything on the screen. on resume, it never attemot to restore because of file system errors obvious the snapshot is broken now.

  2. abarocio80 says:

    Thanks. Works perfectly (with some extra suggested tweaks) on a HP Pavilion dv4-2013la with Ubuntu 11.04v. How ever it required some reboots to work fine; I just don’t know why.

  3. Juan says:

    Gracias…luego de muchos días por fin pude solucionar los problemas.

  4. Pascal says:

    Hi! Just wanted to say thanks! I fixed my swap/hibernating issue on an old X300 using Lubuntu 11.x ! Merci!!

  5. Dimos says:

    Thanks it worked like a charm!

  6. Tim says:

    This worked wonders for me. I have an asus K53sv running kubuntu 12.x (precise) and I’ve been poking around this problem for a while. I had to install a custom ACPI hardware unbind script, which i would recommend anyway, as it is pretty generic.
    http://thecodecentral.com/2011/01/18/fix-ubuntu-10-10-suspendhibernate-not-working-bug

    But, I managed to get it halfway working with a few different methods, but the actual key for me was removing the confusion of extra packages with:
    “sudo apt-get remove hibernate uswsusp”

    Also FYI, in ubuntu 12, sleep/suspend functionality has been disabled by default because of all the trouble ACPI causes. You will need to re-enable (don’t have a link to hand)

  7. Florian says:

    This is the most comprehensive and well-explained article I could find on the topic, and Step 3 got my hibernation back! [Ubuntu 12.04 x64, Acer TravelMate 8372G]

    Thank you, chris!

  8. You are saying that `free -m’ shows that you have “8005 Mb of RAM”. Where does that number come from? Did you mean “_10005_ _MiB_ of RAM” as per “Mem: total 10005″? TIA.

    Regards,

    PointedEars

  9. Anupam Das says:

    Excellent!! You made my day sir.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>