Created
June 30, 2016 16:59
-
-
Save nearbycoder/8566b6b941c9017f2988df4fbaf33f61 to your computer and use it in GitHub Desktop.
Add Swap to Digital Ocean VM
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/sh | |
# size of swapfile in megabytes | |
swapsize=2048 | |
# does the swap file already exist? | |
grep -q "swapfile" /etc/fstab | |
# if not then create it | |
if [ $? -ne 0 ]; then | |
echo 'swapfile not found. Adding swapfile.' | |
fallocate -l ${swapsize}M /swapfile | |
chmod 600 /swapfile | |
mkswap /swapfile | |
swapon /swapfile | |
echo '/swapfile none swap defaults 0 0' >> /etc/fstab | |
else | |
echo 'swapfile found. No changes made.' | |
fi | |
# output results to terminal | |
cat /proc/swaps | |
cat /proc/meminfo | grep Swap |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment