15

Ubuntu 17.04 introduces a swap file to replace swap partitions. However, I would prefer not to have any disk-based swap space at all, so I would like to know how to turn the swap file off.

Clarification: I need a way to turn the swap file off permanently. AFAIK, the swapoff command only disables it temporarily.

Clarification 2: I do not want swapping disabled completely, as I am using zram as my swap. I only want the swap file disabled.

My question specifically deals with the swap file, while the answers to the other questions deal with either turning off the swap partition, or they deal with turning off all swap. I do not want either, I just want the swap file turned off.

Zanna
  • 72,312

2 Answers2

21

This is how to disable the swap file in Ubuntu 17.04

To turn off the swapfile. Run the following command:

sudo swapoff /swapfile         

Now disable the swap file in /etc/fstab. I'm using Vim.

sudo vim /etc/fstab

Your /etc/fstab file should have a '#' in front of '/swapfile'

enter image description here

After this is done. save your changes and exit.

Now we're going to physically remove the swap file. run the following command:

sudo rm -f /swapfile

and voila! For the changes to take full effect, reboot the system, and use the 'free' command to confirm there is no available space for swap.

Zanna
  • 72,312
1

Any swap file or partition that starts at boot is in the /etc/fstab file. If you remove the line associated with that swap file in the fstab it won't start up again after a reboot.

TopHat
  • 4,321