12 August 2022

Making Ubuntu recognize and use the swap partition instead of using the swap file it created

This happened when I deleted my old Ubuntu partition and re-installed a newer version of Ubuntu. Even though there was a logical swap partition present, Ubuntu simply ignored it and created its own swap file. A glance through the Swap FAQ showed me how to fix it.

First, you need to have a look at what the UUID of your swap partition is. Do that by running:

blkid

Search for the line containing TYPE="swap", and note the UUID at the start of the line. This is the UUID of the swap partition. For example, the UUID may be fdb91fbe-e580-467f-8819-b672d89261eb.

Now open up fstab.

sudo gedit /etc/fstab

If there's a line starting with "/swapfile", comment out that line using a hash at the start of the line "#/swapfile". This is the swapfile that Ubuntu used instead of using the swap partition you had created.

Now add a new line to the file, where you mention the UUID that Ubuntu can use to recognize the swap partition:

UUID=fdb91fbe-e580-467f-8819-b672d89261eb none   swap    sw      0       0

Save and exit. Reboot.

Voila! The swap partition will now be recognized.


No comments: