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
  • 70,465
  • That question's answer only shows how to disable a swap partition temporarily. Editing my question. – Zauberin Stardreamer May 07 '17 at 01: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. – Zauberin Stardreamer May 07 '17 at 01:44
  • 1
    @ZauberParacelsus There's an answer about disabling it in /etc/fstab by Sohail xIN3N – userDepth May 07 '17 at 02:17
  • Also worth reading: https://askubuntu.com/questions/103242/is-it-safe-to-turn-swap-off-permanently and https://askubuntu.com/questions/49109/i-have-16gb-ram-do-i-need-32gb-swap – Takkat May 07 '17 at 06: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 07 '17 at 13:36

2 Answers2

20

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
  • 70,465
  • 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. – Zauberin Stardreamer May 07 '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 09 '17 at 19:53
  • I also had removed the entry from sysctl.conf, which nobody has in their answer here, dont forget that.. (both swappiness and cache_pressure).

    I should stress, if you dont want to cause your self a nightmare, dont forget to remove (or comment) the fstab entry.

    @Zibri i'm not seeing your answer either.

    – Brian Thomas Sep 17 '22 at 00:17
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
  • 3,971