Created
January 26, 2018 00:11
-
-
Save adonley/4eeaf5310c16ed5ab81544c18d298a94 to your computer and use it in GitHub Desktop.
Make swap partition on amazon EC2 instance.
This file contains 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 | |
# './make_swap -s 1024' will create a 1024 MB swap | |
OPTIND=1; | |
# Size in MB | |
s="1024"; | |
while getopts "s:" opt; do | |
case "$opt" in | |
s) s=$OPTARG | |
;; | |
esac | |
done | |
shift $((OPTIND-1)) | |
[ "$1" = "--" ] && shift | |
if grep -Fq "/var/swap" /etc/fstab | |
then | |
echo "Swap already enabled for this machine."; | |
else | |
# 1 GB | |
sudo /bin/dd if=/dev/zero of=/var/swap.1 bs=1M count=$s | |
sudo /sbin/mkswap /var/swap.1 | |
sudo chmod 600 /var/swap.1 | |
sudo /sbin/swapon /var/swap.1 | |
echo "/var/swap.1 swap swap defaults 0 0" | sudo tee -a /etc/fstab | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment