Skip to content

Instantly share code, notes, and snippets.

@cristianbica
Last active August 29, 2015 13:57
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 cristianbica/9594944 to your computer and use it in GitHub Desktop.
Save cristianbica/9594944 to your computer and use it in GitHub Desktop.
Adds swap to a linux system
# for 1G of swap run
# curl https://gist.githubusercontent.com/cristianbica/9594944/raw/add_swap.sh | bash -v -s 128M 8
# it will build a swapfile of 1G (8 blocks of 128M) and make it swap
BLOCK_SIZE=$1
BLOCKS_COUNT=$2
dd if=/dev/zero of=/swapfile bs=$BLOCK_SIZE count=$BLOCKS_COUNT
sudo chown root:root /swapfile
sudo chmod 0600 /swapfile
mkswap /swapfile
swapon /swapfile
echo '/swapfile none swap sw 0 0' >> /etc/fstab
echo 10 | sudo tee /proc/sys/vm/swappiness
echo vm.swappiness = 10 | sudo tee -a /etc/sysctl.conf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment