Skip to content

Instantly share code, notes, and snippets.

@czechboy0
Last active September 6, 2016 14:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save czechboy0/ba249dc375dd6335f30f7acd593aa193 to your computer and use it in GitHub Desktop.
Save czechboy0/ba249dc375dd6335f30f7acd593aa193 to your computer and use it in GitHub Desktop.
Add 4 GB swapspace on Ubuntu 14.04
# based on https://www.digitalocean.com/community/tutorials/how-to-add-swap-on-ubuntu-14-04
# run with eval "$(curl -sL https://gist.githubusercontent.com/czechboy0/ba249dc375dd6335f30f7acd593aa193/raw/add_swap.sh)"
echo "Starting with swap table:"
sudo swapon -s
echo "Available space:"
df -h
echo "Creating a 4GB swap file"
sudo fallocate -l 4G /swapfile
ls -lh /swapfile
sudo chmod 600 /swapfile
echo "Enabling swap file"
sudo mkswap /swapfile
sudo swapon /swapfile
echo "Current swap files:"
sudo swapon -s
echo "Enabling swap for after reboot"
echo "/swapfile none swap sw 0 0" >> /etc/fstab
echo "Setting swappiness to 10"
sudo sysctl vm.swappiness=10
echo "vm.swappiness=10" >> /etc/sysctl.conf
echo "Setting cache pressure to 50"
sudo sysctl vm.vfs_cache_pressure=50
echo "vm.vfs_cache_pressure = 50" >> /etc/sysctl.conf
echo "You might want to reboot now just for good measures :)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment