How To Create Swap On Debian | Ubuntu
Sometimes there isn't much RAM on the server and we have no choice but to add swapfile.
Execute following commands:
sudo fallocate -l 2G /swapfilesudo chmod 600 /swapfilesudo mkswap /swapfilesudo swapon /swapfileMake swap persistent after reboot. It's a good practice to save fstab in case we need original later or if we mess it up :)
sudo cp /etc/fstab /etc/fstab.saveecho '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstabWe can further tweak swap:
sudo sysctl vm.swappiness=10sudo sysctl vm.vfs_cache_pressure=50Add two more lines at the end of the file /etc/sysctl.conf
sudo nano /etc/sysctl.confvm.swappiness=10
vm.vfs_cache_pressure=50Check swap with:
sudo swapon --showRemove swap:
swapoff /swapfilesudo rm -rf /swapfileAnd remove it from /etc/fstab.