Skip to content

Instantly share code, notes, and snippets.

@mrhyde
Last active August 29, 2015 14:07
Show Gist options
  • Save mrhyde/41902a8f43ebb1bbee68 to your computer and use it in GitHub Desktop.
Save mrhyde/41902a8f43ebb1bbee68 to your computer and use it in GitHub Desktop.
Create swap file on digitalocean ubuntu droplets
#/bin/sh
# Creates a 4Gb swap image on your Droplet
# @see https://www.digitalocean.com/community/tutorials/how-to-add-swap-on-ubuntu-14-04
if [ -f /swapfile ]; then
echo "Swap file already exists."
else
sudo fallocate -l 4G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
echo "/swapfile none swap sw 0 0" >> /etc/fstab
echo "vm.swappiness=30" >> /etc/sysctl.conf
echo "vm.vfs_cache_pressure=50" >> /etc/sysctl.conf
echo "Swap created and added to /etc/fstab for boot up."
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment