Created
November 16, 2015 07:06
-
-
Save xiaohanyu/b66aca52070670acf6a3 to your computer and use it in GitHub Desktop.
Turn on swap memory for vps with small memory
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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