Skip to content

Instantly share code, notes, and snippets.

@albertgrala
Forked from peterchester/swap.sh
Last active August 29, 2015 14:17
Show Gist options
  • Save albertgrala/54188aae314f7334b0ec to your computer and use it in GitHub Desktop.
Save albertgrala/54188aae314f7334b0ec to your computer and use it in GitHub Desktop.
#/bin/sh
# Creates a 1gb swap image.
# @see https://www.digitalocean.com/community/tutorials/how-to-configure-virtual-memory-swap-file-on-a-vps
if [ -f /var/swap.img ]; then
echo "Swap file already exists."
else
touch /var/swap.img
chmod 600 /var/swap.img
dd if=/dev/zero of=/var/swap.img bs=1024k count=1000
mkswap /var/swap.img
swapon /var/swap.img
echo "/var/swap.img none swap sw 0 0" >> /etc/fstab
sysctl -w vm.swappiness=30
free
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