Ubuntu Linux: How to Enable or Disable Swap Partition

In this post we shall discuss how to enable or disable swap partition in Ubuntu Linux. Ubuntu Linux or any Linux operating system can use a swap partition for paging in case if it runs out of physical memory. The swap partition is not a mandatory requirement for using Linux but it is advisable that you have a swap partition setup to avoid memory bottleneck in case you run out of your physical memory.

The aim of this post is explorer the ways in which we can enable or disable swap partitions it is assumed that you have already swap partition created during the Ubuntu Linux installation.

Method 1:

Source: addictivetips.com

We can use Gparted partition manager to enable or disable a swap partition. If Gparted is not installed in your Ubuntu Linux then use the following command below to install it.

1: sudo apt-get install gparted

This will install the Gparted partition editor which you can access from System>>Administration>>Partition Editor

The Gparted will now display all the available partitions in the hard disk that is selected. In this case we have a 14.99GB hard disk that has got a swap partition of 682.42MB.

To enable the Swap partition:

To enable the swap partitions right click on the swap partition and then select the Swapon’ option to enable the swap partition.

To disable the Swap partition:

To disable the swap partitions right click on the swap partition and then select the Swapoff’ option to disable the swap partition.

Method 2:

Source: haydenjames.io

In this method we shall discuss the enabling and disabling swap partition from terminal.

To enable the Swap partition:

To enable all the swap partitions on your computer you can use the following command.

1: sudo swapon a

If you would like to enable the swap partition for a particular partition then you can use the following command:

1: sudo swapon U <uuid>

To find the UUID of all the partitions use this command:

1: sudo blkid

In our example the UUID of our swap partition is 39be8652-da3d-4ad0-b11a-adb6c2ba3586 so the command will look like:

1: sudo swapon U 39be8652-da3d-4ad0-b11a-adb6c2ba3586

To disable the Swap partition:

To disable all the swap partitions on your computer you can use the following command.

1: sudo swapoff

If you would like to disable the swap partition for a particular partition then you can use the following command:

1: sudo swapoff U <uuid&gt

In our example the UUID of our swap partition is 39be8652-da3d-4ad0-b11a-adb6c2ba3586 so the command will look like:

1: sudo swapoff U 39be8652-da3d-4ad0-b11a-adb6c2ba3586

That’s it you can enable or disable swap partition either using the Gparted GUI or using the command line.