Skip to content

Instantly share code, notes, and snippets.

@nozzlegear
Forked from rickyhewitt/createswap.sh
Created December 19, 2016 16:00
Show Gist options
  • Save nozzlegear/03a297084885a043e9e93afb83cd6e62 to your computer and use it in GitHub Desktop.
Save nozzlegear/03a297084885a043e9e93afb83cd6e62 to your computer and use it in GitHub Desktop.
Quick and easy script to setup swap
#!/bin/sh
# createswap.sh
# creates swap file.
# Optionally specify size (e.g. 1024M)
#
# <ricky@rickyhewitt.me>
if [ $1 ]; then
SWAP_SIZE=$1
else
echo "No swap size specified."
exit 1; # fail
fi
echo "Creating swap file with size of $SWAP_SIZE"
fallocate -l $SWAP_SIZE /swap
mkswap /swap
chmod 600 /swap
swapon /swap
sed -i -e '$a/swap none swap sw 0 0' /etc/fstab
sysctl vm.swappiness=10
sed -i -e '$avm.swappiness=10' /etc/sysctl.conf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment