Swap partition doesn't mount after partition resize

Asked by Mauricio A

I'm fairly new to Ubuntu. I installed it alongside with Windows in a 10GB partition and a 1.4 GB swap partition.
Everything worked fine until I ran short of space and decided to take space from the NTFS Windows partition and add it to my linux partition.
I used GParted live CD to do this. I think I also moved the position of the swap partition a little, I can't remember.
After GParted finished repartitioning I restarted the computer and everything seemed to work fine. However in the next days I noticed that the computer kept crashing and freezing a lot whenever I opened too many programs. Later I realized why this happened: there was no swap mounted anymore. If I open the System Monitor it says 0 bytes of 0 bytes and it's always in 0, no matter how much RAM is in use.

If I open Gparted from Ubuntu I can select the swap partition (sdb5) and click "swapon". After doing this the swap mounts and starts working normally.

However I have to do this every time I boot my computer. So my question is, how can this be done automatically?
I checked for people with similar problems before asking, but it didn't help.
If I put "sudo swapon -a" on a terminal I get the following line:

swapon: cannot find the device for UUID=59a9b836-2434-45d3-a512-2126a0c0ae67

Thanks in advance

Question information

Language:
English Edit question
Status:
Solved
For:
Ubuntu util-linux Edit question
Assignee:
No assignee Edit question
Solved by:
bcbc
Solved:
Last query:
Last reply:
Revision history for this message
Best bcbc (bcbc) said :
#1

The swap partition is referenced by uuid in /etc/fstab. Whenever you move resize a partition the uuid changes. All you have to do is:
1. get the new uuid: sudo blkid
2. backup fstab: sudo cp /etc/fstab /etc/fstab_backup
3. edit fstab: gksudo gedit /etc/fstab
4. Replace the uuid in the line for swap with the new one
5. sudo swapon -a

And after that it should work everytime at bootup

if you hibernate you need to make some additional changes as well.

Revision history for this message
bcbc (bcbc) said :
#2

For hibernate also update the uuid in /etc/initramfs-tools/conf.d/resume and afterwards run:
sudo update-initramfs -u

ps hibernate only works if your swap is large enough (at least as big as ram, probably 1.5 x RAM is sufficient). Even if you don't hibernate, I've heard it said that there's a delay in normal booting if the uuid in the resume file does not match your swap partition, so it's a good idea to update this anyway.

Revision history for this message
Mauricio A (mauricio-alfonso-88) said :
#3

Thanks a million!
Did both things and works like a charm.

Revision history for this message
Mauricio A (mauricio-alfonso-88) said :
#4

Thanks bcbc, that solved my question.

Revision history for this message
marcus aurelius (adbiz) said :
#5

IMHO, problems like this could have been avoided if the old method of using /dev/?d?? were kept instead of moving to the UUID method.

Revision history for this message
marcus aurelius (adbiz) said :
#6

IMHO, problems like this could have been avoided if the old method of using /dev/?d?? were kept instead of moving to the UUID method.