Skip to content

Instantly share code, notes, and snippets.

@nguyentienlong
Forked from mommi84/add_swap.sh
Created September 6, 2020 06:12
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 nguyentienlong/71c5dd98a762f50ae1d97328a34cc09f to your computer and use it in GitHub Desktop.
Save nguyentienlong/71c5dd98a762f50ae1d97328a34cc09f 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