I installed Natty on my laptop with default options. I guess it created a swap partition equal to the size of my RAM. Every time I try to hibernate I get the "not enough swap" message, which is annoying. I want to hibernate! Why can't you just use some of my 20GB free HD space to hibernate? I only have 1GB RAM on this old geezer.

4 Answers
4

The live CD will detect and use your swap, you should disable it to be able to manipulate it. Open a terminal and type the following command:

sudo swapoff -a

Afterwards, open Gparted, an resize your partition. You will need to shrink some partition that is close to it. It should be quite straightforward.

You will need to boot from some external method, because you can't resize partitions that are in use, and it's quite likely that you will need to shrink your main partition.

Now the other questions:

1) Yes.

2) If you use a swap file then yes, you can get rid of your swap partition. But I believe that using a swap partition is easier. It's also the standard practice in linux, most of the tutorials that you can find on the net will expect it.

3) Messing with swap is something that no newbie should do in any OS. No need to make it easy.

Well, although Ubuntu is supposed to make it big enough it doesn't. Here's what I've tried so far: first I tried resizing the swap partition but neither the Ubuntu install disk or a GParted LiveCD would grow the size of the extended partition that swap was on. So I deleted the swap partition, grew my primary partition, and moved swap to a file using the wiki I referenced. However then I started getting an error about the swap header when I tried to hibernate. So I did part 2 here: ubuntuforums.org/showthread.php?t=1042946 and now hibernate works, but it boots fresh instead of resuming
–
SWrobelJun 16 '11 at 21:47

I finally solved this. Of course, to answer the "Why is this all so difficult?" part of my question, I would just have to respond "This is Linux, you fool, of course everything is difficult!"

Here are the steps:

Boot to Ubuntu install CD (I'm on Natty) and choose the option to run Ubuntu now

Go to system -> GParted Partition Editor

Delete the swap partition and the extended partition that holds it (if by some miracle you're able to resize your swap partition from here, I imagine your life will be a lot easier than mine)

Decrease the size of your primary partition by the amount you want your new swap to be (I made mine 2x RAM + 500MB just to be safe). The easiest way to do this is to fill in the amount of space you want swap to be in the "free space following" field

In the free space that has now been created, choose new, type linux-swap and you can name the partition "swap" if you like

Hit the Apply button (should be a check mark) to write the changes to disk

When done, reboot back into Ubuntu

Now you need to find what partition your swap is on and what its UUID is. UUID?! you say? Well that's the Universally Unique IDentifier for the partition so you can reference it even if it's on a different mount point from boot-to-boot due to adding disks, etc. If this is your primary disk, it's probably not a big deal.

Pull up a terminal and run gksu gparted & and enter your root password. The & lets this process run while still giving you access to the command line.

Right-click on your swap partition and choose Information. You should see the Path and UUID listed there. Keep this open for further reference.

Run gksu gedit /etc/fstab & and look for the line that has swap in it. It should be the third column, separated by spaces or tabs. You can either use the path or the UUID to tell Linux where to find your swap partition. I recommend UUID because it'll stay constant even if you move the partition around or the disk somehow becomes sdb instead of sda or something like that. Make the appropriate edits and save the file. Your line should look something like this if you used UUID (with your UUID instead, of course):

UUID=41e86209-3802-424b-9a9d-d7683142dab7 none swap sw 0 0

or this if you used path: /dev/sda2 none swap sw 0 0

Save and reboot to make sure the new swap gets activated properly at startup

Grab a glass of milk and wait for Ubuntu to come back up... The fun part comes next

Pull up a Terminal again and run cat /proc/swaps and hopefully you see the path to your swap partition listed there. If not chances are something went wrong in the steps above. Here's my output:

Look for the line GRUB_CMDLINE_LINUX="" and make sure it looks like this (using your UUID of course) GRUB_CMDLINE_LINUX="resume=UUID=41e86209-3802-424b-9a9d-d7683142dab7" and save the file

sudo update-grub and wait for it to finish

gksu gedit /etc/initramfs-tools/conf.d/resume & and make sure its contents are resume=UUID=41e86209-3802-424b-9a9d-d7683142dab7 (with your UUID of course in place of mine). Save the file!

sudo update-initramfs -u

Reboot!

Now you should be able to hibernate and resume! I really hope this helps someone else. I can't believe Ubuntu is on version 11 and it still SUCKS THIS HARD to get it to hibernate your laptop. Don't lose faith though, it can be done!

In your first lot of seven steps.... delete number 2 i.e. do 3 first. Now select the swap partition, select swap off, grow partition, select swap on and reboot That's it that is all that's needed.
–
robin0800Jun 17 '11 at 8:01