Skip to content

Instantly share code, notes, and snippets.

@mommi84
Created September 12, 2019 09:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save mommi84/0f659c2ed9c03458a32a75625abcbda8 to your computer and use it in GitHub Desktop.
Save mommi84/0f659c2ed9c03458a32a75625abcbda8 to your computer and use it in GitHub Desktop.
Add swap memory on Ubuntu
#!/usr/bin/env bash
#
# USAGE:
# sudo ./add_swap.sh 4G
#
# SOURCE:
# https://linuxize.com/post/how-to-add-swap-space-on-ubuntu-18-04/
#
fallocate -l $1 /swapfile
chmod 600 /swapfile
mkswap /swapfile
swapon /swapfile
echo "/swapfile swap swap defaults 0 0" >> /etc/fstab
# print info
swapon --show
free -h
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment