Skip to content

Instantly share code, notes, and snippets.

@tonioriol
Last active May 20, 2016 12:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tonioriol/de59331ff2732a54c73fa1bb02bd0e5e to your computer and use it in GitHub Desktop.
Save tonioriol/de59331ff2732a54c73fa1bb02bd0e5e to your computer and use it in GitHub Desktop.
if [ -f /swapfile ]; then
echo "The Swap file already exists."
else
sudo fallocate -l 4G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
sudo sh -c 'echo "/swapfile none swap sw 0 0" >> /etc/fstab'
sudo sh -c 'echo "vm.swappiness = 10" >> /etc/sysctl.conf' # 60 for desktops, closer to 0 for VPS (10?)
sudo sh -c 'echo "vm.vfs_cache_pressure = 50" >> /etc/sysctl.conf'
echo "The Swap file is created and added to '/etc/fstab' to make the changes permanent."
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment