9

This question already has an answer here:

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.

marked as duplicate by George Udosen, psusi, WinEunuuchs2Unix, heemayl, Takkat May 7 '17 at 6:42

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • That question's answer only shows how to disable a swap partition temporarily. Editing my question. – Zauber Paracelsus May 7 '17 at 1:08
  • @Alban Yeah, I double-checked through that file. All of the answers deal with either temporarily disabling swapping, or disabling the swap partition. Nothing about swap files. – Zauber Paracelsus May 7 '17 at 1:44
  • 1
    @ZauberParacelsus There's an answer about disabling it in /etc/fstab by Sohail xIN3N – userDepth May 7 '17 at 2:17
  • Also worth reading: askubuntu.com/questions/103242/… and askubuntu.com/questions/49109/… – Takkat May 7 '17 at 6:43
  • 1
    I'm voting to keep this question closed. Both questions have answers that explain how to remove swap entries from /etc/fstab which is what you need to do to disable a particular swap space permanently. – David Foerster May 7 '17 at 13:36
13

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.

  • Apparently, my system never had the swap file enabled in the first place. Probably because I installed 17.04 by upgrading from 16.10, rather than installing it fresh. – Zauber Paracelsus May 7 '17 at 12:32
  • WRONG. 1) I already ran swapoff -a (but it still was remounted at boot) 2) there is no entry in fstab see my answer for the solution – Zibri Dec 9 '17 at 19:53
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.

  • 3
    perhaps it would be wiser to comment out the line than to remove it entirely – Zanna May 7 '17 at 6:23

Not the answer you're looking for? Browse other questions tagged or ask your own question.