Last active
August 29, 2015 13:55
-
-
Save dyladan/8735297 to your computer and use it in GitHub Desktop.
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 | |
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