Skip to content

Instantly share code, notes, and snippets.

@Supermathie
Created April 22, 2014 04:09
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 Supermathie/11165081 to your computer and use it in GitHub Desktop.
Save Supermathie/11165081 to your computer and use it in GitHub Desktop.
add a 512MB swapfile
#!/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