// A simple, no-nonsense checklist for adding a 16GB swap file on Linux, tuning swappiness, and making it persistent. Plus, how to remove it later.
Sometimes your Linux box just needs a little breathing room. That’s where swap comes in. Instead of digging through long docs, here’s my personal quick-and-dirty checklist for setting up a 16GB swap file and making sure it sticks around after reboot.
1. Check if you already have swap
free -h
swapon --show2. Create a 16GB swap file
sudo fallocate -l 16G /swapfileIf fallocate isn’t available:
sudo dd if=/dev/zero of=/swapfile bs=1M count=163843. Lock down permissions
sudo chmod 600 /swapfile4. Make it swap-ready
sudo mkswap /swapfile5. Turn it on
sudo swapon /swapfile6. Keep it after reboot
Edit your fstab:
sudo nano /etc/fstabAdd this line:
/swapfile none swap sw 0 07. Tweak swappiness (RAM first, swap later)
sudo sysctl vm.swappiness=10Check the current value:
cat /proc/sys/vm/swappinessTo make it permanent:
sudo nano /etc/sysctl.confAdd:
vm.swappiness=10Reload:
sudo sysctl -p8. Verify
free -h
swapon --showYou should now see your 16GB swap file.
❌ Removing Swap (if you change your mind)
Turn it off:
sudo swapoff /swapfileRemove the fstab entry (if you added it).
Delete the file:
sudo rm /swapfileDone — back to normal.
👉 That’s it! A dead-simple checklist to add (or remove) swap space whenever you need it.