Created
March 27, 2018 19:17
-
-
Save jcharlier/be5512c14d3277ba923267e98efd80ab to your computer and use it in GitHub Desktop.
Create Swapfile in Ubuntu
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 | |
regex='^[0-9]+([.][0-9]+)?$' | |
if [[ ! $2 =~ $regex ]]; then | |
echo "Usage: createSwap.sh fullPathToSwapFile swapFileSizeinGB"; | |
echo "ex: createSwap /tmp/swapfile.swap 8" | |
exit 1 | |
fi | |
if [[ -d $1 ]] || [[ -f $1 ]] || [[ ! $1 = /* ]]; then | |
echo "please supply the full path to a new swapFile" | |
exit 1 | |
fi | |
echo "Allocating file space for $1" | |
sudo fallocate -l $2G $1 | |
echo "done" | |
sudo chmod 600 $1 | |
# sudo dd if=/dev/zero of=/mnt/1GB.swap bs=1024 count=1048576 | |
sudo mkswap $1 | |
sudo swapon $1 | |
echo "$1 none swap sw 0 0" | sudo tee --append /etc/fstab |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment