Ubuntu – How to add swap after system installation


I did not create a swap partition during Ubuntu installation. Later, I freed up some space and made a swap partition. Now after each boot up, I am manually opening gparted to right-click the swap partition to turn on the 'swapon' option.

How can I automatically enable the swap partition at boot?

Also, if I had not created the swap partition, what are my other options?

Best Answer

You need to edit /etc/fstab and add the new swap partition.

sudo nano /etc/fstab

You need to add a line that looks like

UUID=735b3be3-779c-4d21-a944-b033225f3ab4 none   swap    sw      0       0

and you get the UUID using the command

sudo blkid /dev/sda3

(substitute /dev/sda3 with the appropriate device name; in order to see the appropriate device name, we can use lsblk - as said here).


Related Question