Skip to content

Instantly share code, notes, and snippets.

@xiaohanyu
Created November 16, 2015 07:06
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 xiaohanyu/b66aca52070670acf6a3 to your computer and use it in GitHub Desktop.
Save xiaohanyu/b66aca52070670acf6a3 to your computer and use it in GitHub Desktop.
Turn on swap memory for vps with small memory
#!/bin/bash
# run it with sudo
# https://www.digitalocean.com/community/tutorials/how-to-add-swap-on-ubuntu-14-04
SWAPFILE=/swapfile
SWAPSIZE=$1
ls $SWAPFILE && swapoff $SWAPFILE && rm $SWAPFILE
fallocate -l $SWAPSIZE $SWAPFILE
chmod 600 $SWAPFILE
mkswap $SWAPFILE
swapon $SWAPFILE
grep "swapfile" /etc/fstab || echo "$SWAPFILE none swap sw 0 0" >> /etc/fstab
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment