Adding Swap on Linux – A Quick Checklist

// 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.

9/21/2025

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 --show

2. Create a 16GB swap file

sudo fallocate -l 16G /swapfile

If fallocate isn’t available:

sudo dd if=/dev/zero of=/swapfile bs=1M count=16384

3. Lock down permissions

sudo chmod 600 /swapfile

4. Make it swap-ready

sudo mkswap /swapfile

5. Turn it on

sudo swapon /swapfile

6. Keep it after reboot

Edit your fstab:

sudo nano /etc/fstab

Add this line:

/swapfile none swap sw 0 0

7. Tweak swappiness (RAM first, swap later)

sudo sysctl vm.swappiness=10

Check the current value:

cat /proc/sys/vm/swappiness

To make it permanent:

sudo nano /etc/sysctl.conf

Add:

vm.swappiness=10

Reload:

sudo sysctl -p

8. Verify

free -h
swapon --show

You should now see your 16GB swap file.


❌ Removing Swap (if you change your mind)

Turn it off:

sudo swapoff /swapfile

Remove the fstab entry (if you added it).
Delete the file:

sudo rm /swapfile

Done — back to normal.


👉 That’s it! A dead-simple checklist to add (or remove) swap space whenever you need it.

Back to shorts
© 2025 Nima Janbaz - All Rights Reserved
<_NimaJanbaz />