Skip to content

Instantly share code, notes, and snippets.

@wvdschel
Created June 4, 2012 07:45
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 wvdschel/2867031 to your computer and use it in GitHub Desktop.
Save wvdschel/2867031 to your computer and use it in GitHub Desktop.
Swap image creator
#!/bin/bash
SIZE=`expr $1 \* 1024`
if [[ x$SIZE == x ]]
then
MEM=`free | grep Mem | sed -e "s/[^0-9]*\([0-9]\+\).*/\1/"`
SIZE=`expr $MEM + $MEM / 4`
echo "No size provided, using 125% of memory size (${SIZE}KB)"
fi
COUNT=`expr $SIZE / 4`
dd if=/dev/zero of=swap.img bs=4096 count=$COUNT
mkswap swap.img
swapon swap.img
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment