Created
April 22, 2014 04:09
-
-
Save Supermathie/11165081 to your computer and use it in GitHub Desktop.
add a 512MB swapfile
This file contains hidden or 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 -e | |
# This script adds a 512MB swapfile to the system | |
function get_new_swapfile() { | |
for i in `seq 0 99`; do | |
if [ ! -e /swapfile.$i ]; then | |
echo /swapfile.$i | |
return | |
fi | |
done | |
# Seriously? 100 swapfiles already exist? | |
echo "too many swapfiles" | |
exit 1 | |
} | |
SWAPFILE=$(get_new_swapfile) | |
# if we have a race condition in the root directory, we have other problems | |
install -o root -g root -m 0600 /dev/null $SWAPFILE | |
dd if=/dev/zero of=$SWAPFILE bs=1k count=512k | |
mkswap $SWAPFILE | |
swapon $SWAPFILE | |
echo "$SWAPFILE swap swap auto 0 0" >> /etc/fstab |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment