Docs / Server Management / How to Add a Swap File on Linux

How to Add a Swap File on Linux

By Admin · Feb 25, 2026 · Updated Apr 23, 2026 · 221 views · 1 min read

Swap space extends your available memory by using disk space. This is useful on smaller Breezes.

Create a Swap File

fallocate -l 2G /swapfile
chmod 600 /swapfile
mkswap /swapfile
swapon /swapfile

Make It Permanent

Add this line to /etc/fstab:

/swapfile swap swap defaults 0 0

Recommended Sizes

  • 1GB RAM: 2GB swap
  • 2GB RAM: 2GB swap
  • 4GB+ RAM: 1-2GB swap

Tune Swappiness

Reduce swappiness so the system prefers RAM:

sysctl vm.swappiness=10
echo "vm.swappiness=10" >> /etc/sysctl.conf

Was this article helpful?