转自: http://chriseiffel.com/everything-linux/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.

Pull out your bootable CD/Jump Drive and boot It (we can’t repartition the drive we we are using it.) Run the “gparted” disk utility. If you have swap, right click -> Delete Right click on your linux partition -> Resize/Move Decrease the size of the partition by the amount of space you want to increase your swap. Click Okay Right click on the free space -> New Change the File System Type to “linux-swap,” click okay. Click the apply check mark in the top menu of gparted to apply the changes Right Click On the new swap partition -> Information 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.

  1. 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, Uncategorized. Bookmark the permalink.

标签: none

添加新评论