Created
July 2, 2012 09:02
-
-
Save chuyeow/3032142 to your computer and use it in GitHub Desktop.
Script to add a 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 | |
# Creates a swapfile at SWAPFILE. | |
SWAPFILE=/mnt/swapfile | |
SWAPSIZE_MB=7168 | |
SWAP_ALREADY_ON=`swapon -s | grep $SWAPFILE` | |
if [ -e $SWAPFILE ]; then | |
if [[ -n $SWAP_ALREADY_ON ]]; then | |
echo "$SWAPFILE already exists and activated, skipping." | |
else | |
echo "$SWAPFILE already exists, activating..." | |
swapon $SWAPFILE | |
echo "Swap status:" | |
swapon -s | |
fi | |
else | |
echo "Creating $SWAPSIZE_MB MB swapfile at $SWAPFILE..." | |
dd if=/dev/zero of=$SWAPFILE bs=1M count=$SWAPSIZE_MB | |
mkswap $SWAPFILE | |
swapon $SWAPFILE | |
echo "Swap status:" | |
swapon -s | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment