Skip to content

Instantly share code, notes, and snippets.

@matoken
Created May 13, 2015 01:55
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 matoken/ad55c297f62b2789eb97 to your computer and use it in GitHub Desktop.
Save matoken/ad55c297f62b2789eb97 to your computer and use it in GitHub Desktop.
#!/bin/bash
swapfile='/var/swap'
backupfile="$swapfile-`/bin/date +%Y%m%d-%H%M%S-$$`"
blocksize='1G'
count='1024'
if [ $UID -ne "0" ] ; then
echo "please re-run as root via sudo."
exit 1
fi
if [ -e $swapfile ]
then
echo "File exist( $swapfile )."
exit 1
fi
echo "creating a swap file."
echo "Please wait requires some time..."
umask 077
dd if=/dev/zero of=$swapfile bs=1M count=1024
echo "mkswap"
mkswap -c /var/swap
echo "backup $swapfile $backupfile"
cp -p $swapfile $backupfile
echo "$swapfile swap swap 0 0" >> /etc/fstab
echo "swapon"
swapon -a
swapon -s
echo "Done."
exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment