enable swap ubuntu

By December 12, 2017Linux

Easily enable swap on Ubuntu 16.04 with this easy to use one-liner.

sudo fallocate -l 16G /swapfile
#If fallocate is not available, use 
#dd if=/dev/zero of=/swapfile1 bs=1024 count=137438883103
#For 128gb
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab
echo 'vm.swappiness = 10' | sudo tee -a /etc/sysctl.conf
echo 'vm.vfs_cache_pressure=50' | sudo tee -a /etc/sysctl.conf
echo "Swap enabled"

 

 

Leave a Reply