Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

As noted in the answer from @aeperezt, you can use swapoff -a to disable swap and swapon -a to enable it again - use swapon -s to see a summary of swap file usage and priority etc.

If you want to permanently remove swap space from your system:

  1. Switch to root using:
    sudo -i
    
    Use your password.
  2. Disable swap:
    swapoff -a
    
  3. Create a backup of the fstab file (we will edit it next):
    cp /etc/fstab{,.orig}
    
  4. Edit the /etc/fstab file to remove the swap file entry (use an editor you are comfortable with, for example vi or nano). It will look something like:
    /dev/mapper/HOST-swap   swap   swap   defaults  0 0
    
    The first entry on the line may point to a device file (/dev/VALUE) or possibly a UUID=some-random-long-string -- just look for the swap entries and delete the entire line.
  5. IMPORTANT: To avoid running into issues when you next reboot, check that the /etc/fstab file is valid by issuing:
    mount -a
    swapon -s   # to verify swap is not active
    
    If it reports a problem, then fix the problem in the fstab file before continuing (remember you have your backup from step 3).
  6. Ideally you would reclaim the disk space by using tools like lvm or btrfs and/or fdisk/gdisk, but the steps needed are very much dependent on whether you are using lvm or btrfs or raw partitions. Too many combinations to list here.