Skip to content

Instantly share code, notes, and snippets.

@dyladan
Last active August 29, 2015 13:55
Show Gist options
  • Save dyladan/8735297 to your computer and use it in GitHub Desktop.
Save dyladan/8735297 to your computer and use it in GitHub Desktop.
#!/bin/bash
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root" 1>&2
exit 1
fi
FILE="/var/swap-$$.img"
read -p "Size in MB: " SWAPSIZE
echo "Creating file $FILE"
touch $FILE
echo "Allocate $SWAPSIZE MB space for swap on $FILE"
dd if=/dev/zero of=$FILE bs=1024k count=$SWAPSIZE
echo "Make swap space on $FILE"
mkswap $FILE
echo "Use $FILE for swap"
swapon $FILE
echo "Add swap to /etc/fstab"
echo "$FILE 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