Disable and remove swap in Linux (Ubuntu/Debian)
This guide explains how to completely disable and remove swap space from Ubuntu and other Debian-based Linux systems.
This setup was tested on Ubuntu 22.04 LTS, 24.04 LTS and Debian 12 (bookworm), but it should work on other Debian-based systems.
These instructions cover both swap partitions and swap files.
Before proceeding with swap removal, ensure you have sufficient RAM before disabling swap.
Quick removal commands
For immediate swap deactivation, use one of these commands depending on your swap type:
For swap partition:
sudo swapoff /dev/sdb1
Replace /dev/sdb1
with your swap partition.
For swap file:
sudo swapoff /swapfile
Complete removal process
To remove swap and prevent it from being reactivated on boot, follow these steps:
1. Identify active swap spaces
swapon --show
Example output:
NAME TYPE SIZE USED PRIO
/dev/sdb1 partition 14.9G 3.7M -2
2. Disable active swap
For swap partition:
sudo swapoff /dev/sdb1
Replace /dev/sdb1
with the actual device name of your swap partition.
For swap file:
sudo swapoff /swapfile
sudo rm /swapfile
3. Remove swap entry from /etc/fstab
Edit the fstab file:
sudo nano /etc/fstab
Find and comment out or remove the line with the swap entry:
# UUID=606c8e0e-f961-495b-98a4-1034ad079341 none swap defaults 0 0
or
# /swapfile none swap sw 0 0
4. Verify removal
Check that swap is no longer active:
swapon --show
Resources
- Linux Manual Pages
- Linux Handbook: How to Disable Swap in Linux
- ServerFault: Best way to disable swap in Linux