Skip to content

swapon Command Cheat Sheet

swapon enables devices and files for paging and swapping.


Synopsis

swapon [options] [specialfile...]

Basic Usage

Enable a Swap File

sudo swapon /swapfile

Enable a Swap Partition

sudo swapon /dev/sda2

View Active Swap (-s)

Summary of used swap devices.

swapon -s
# OR
cat /proc/swaps

Enable All from fstab (-a)

sudo swapon -a

Advanced Options

Set Priority (-p)

Priority is a number between -1 and 32767. Higher priority swap is used first.

sudo swapon -p 10 /dev/zram0
sudo swapon -p 0 /swapfile

Notes

  • fstab: To make swap permanent, add it to /etc/fstab.
  • Permissions: Swap files must be readable only by root (chmod 600).