Recovering swap partition on Ubuntu

While trying to increase the space on my primary Ubuntu partition, I had to delete and recreate the swap partition to make the Ubuntu partition contiguous with the available free space. After this, when I rebooted and logged on, I felt a slight sluggishness when I ran multiple applications. I ran free -mt to check on memory usage, and found that the swap showed up as 0. As listed in several forums, I first checked /etc/fstab to see the device name of the swap partition (/dev/sda6) and then tried the following commands :

$ sudo mkswap /dev/sda6

$ sudo swapon -a

But the swapon -a threw up the following error :

swapon: cannot canonicalize /dev/disk/by-uuid/734bd422-231c-68c4-jc61-be0a6214ac18: No such file or directory
swapon: cannot stat /dev/disk/by-uuid/734bd422-231c-68c4-jc61-be0a6214ac18: No such file or directory

After some more investigation, I found out that the UUID for the swap partition on /etc/fstab was old and did not reflect the new one which got created when I recreated the swap partition. I then used this command :

$ blkid

This showed the correct value for the UUID of the swap partition, which I then updated on /etc/fstab.

Now used the same method as earlier :

$ sudo mkswap /dev/sda6

$ sudo swapon -a

And it worked like a charm, with free -mt showing up the swap space as non-zero.

Leave a Reply