Skip to content

Instantly share code, notes, and snippets.

@sadovnik
Created December 6, 2016 11:34
Show Gist options
  • Save sadovnik/10f9eaf8c74e94abd888284a22758f91 to your computer and use it in GitHub Desktop.
Save sadovnik/10f9eaf8c74e94abd888284a22758f91 to your computer and use it in GitHub Desktop.
Set swap (useful for Vagrant machines)
#!/bin/sh
# size of swapfile in megabytes
swapsize=2048
# 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
@sadovnik
Copy link
Author

sadovnik commented Dec 6, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment