Add a swap file
Gain headroom when RAM is tight.
- Check what exists:
swapon --show free -h
- Create a 2 GB file and secure it:
sudo fallocate -l 2G /swapfile sudo chmod 600 /swapfile
- Format it then enable it:
sudo mkswap /swapfile sudo swapon /swapfile
- Make it permanent:
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab
- On a Btrfs file system, creating a swap file needs special steps: see your distribution's documentation.