Skip to content

Instantly share code, notes, and snippets.

@luizs81
Forked from shovon/increase_swap.sh
Last active July 5, 2016 14:53
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 luizs81/319d936efd300408c1a89d6e70ad68e6 to your computer and use it in GitHub Desktop.
Save luizs81/319d936efd300408c1a89d6e70ad68e6 to your computer and use it in GitHub Desktop.
How to create/increase swap file in Ubuntu
#!/bin/sh
# size of swapfile in megabytes
swapsize=8000
# does the swap file already exist?
grep -q "swapfile" /etc/fstab
# if not then create it
if [ $? -ne 0 ]; then
echo 'swapfile not found. Adding swapfile.'
fallocate -l ${swapsize}M /swapfile
chmod 600 /swapfile
mkswap /swapfile
swapon /swapfile
echo '/swapfile none swap defaults 0 0' >> /etc/fstab
else
echo 'swapfile found. No changes made.'
fi
# output results to terminal
df -h
cat /proc/swaps
cat /proc/meminfo | grep Swap
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment