System and processes
The swapoff command
Disables a swap area and moves its contents back into RAM.
Most useful options
-a, --allDisables all known swap, those in /proc/swaps and those in fstab-v, --verboseVerbose mode: explains what it does-h, --helpShows the help and exits-V, --versionShows the version and exitsCopy-ready examples
$ swapon --showcheck which swap is active before turning anything off.$ sudo swapoff /dev/sdb1disables that partition. If free RAM is not enough to take its pages back, it fails.$ sudo swapoff -v /dev/sdb1the same, but with the detail of each step.$ sudo swapoff -a; echo $?disables all swap and prints the exit code: 0 if all were turned off, 32 if all failed and 64 if only some did.You can try them in the browser terminal: it does not touch your computer.
Common errors
| Message | Cause | Fix |
|---|---|---|
| swapoff: Not superuser. | swapoff needs administrator privileges and you ran it without them. | Repeat the command with sudo. |
| swapoff: /dev/sdb1: swapoff failed: Cannot allocate memory | Free RAM is not enough to take back that swap's pages, and the command exits with code 2. | Check memory with free, close programs you do not need and repeat the command. |
Typical mistakes
- If free RAM is not enough, swapoff fails with code 2 and the swap stays active. Do not force it with little memory.
- Turning off a swap does not free disk space: the partition or file stays the same, it just stops being used.
- swapoff does not edit fstab: if the entry is still there, the swap is enabled again at the next boot.
Differences from similar commands
FAQ
When does it make sense to turn off a swap?
Before repairing, reformatting or resizing its partition or file, because while it is active the system uses it.
Does turning off swap free disk space?
No. That area just stops being used: its contents go back to RAM and the partition or file stays where it is.
What does exit code 64 of swapoff -a mean?
That some swap areas were turned off and others were not. With 32 all failed, and with 0 it went well.
Learn to actually use it
The basic Linux course takes you from zero to console fluency with 24 self-grading lessons.
Start the free course