Skip to content

Instantly share code, notes, and snippets.

@Locoxella
Last active February 22, 2018 20:45
Show Gist options
  • Save Locoxella/aca080e32d4bb90cf1f34dac9557e2e5 to your computer and use it in GitHub Desktop.
Save Locoxella/aca080e32d4bb90cf1f34dac9557e2e5 to your computer and use it in GitHub Desktop.
1G permament swapfile
#!/usr/bin/env bash
#
# Always find my self creating 1G swapfile for tiny EC2 machines (I know I should rely only on RAM, but the free ssd is there
# and it had saved my life in the past), and not getting better at recalling each step.
#
# Oneliner:
# sudo fallocate -l 1G /swapfile ; sudo chmod 600 /swapfile ; sudo mkswap /swapfile ; sudo swapon /swapfile ; echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab ; swapon --show
if [ "$EUID" -ne 0 ]
then echo "Please run as root"
exit
fi
fallocate -l 1G /swapfile
chmod 600 /swapfile
mkswap /swapfile
swapon /swapfile
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab
swapon --show
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment