Skip to content

Instantly share code, notes, and snippets.

@alokraj68
Forked from mommi84/add_swap.sh
Last active December 21, 2024 17:17
Show Gist options
  • Select an option

  • Save alokraj68/c62b3eeaaf7b1be51c582494f5a18dd1 to your computer and use it in GitHub Desktop.

Select an option

Save alokraj68/c62b3eeaaf7b1be51c582494f5a18dd1 to your computer and use it in GitHub Desktop.
Add swap memory on Ubuntu
#!/usr/bin/env bash
#
# USAGE:
# sudo ./add_swap.sh 8G
#
# 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
sysctl vm.swappiness=10
sysctl vm.vfs_cache_pressure=50
# print info
swapon --show
free -h
# to run in linux
## With curl:
#bash <(curl -sL https://gist.githubusercontent.com/alokraj68/c62b3eeaaf7b1be51c582494f5a18dd1/raw/d02785a02a7e7c74c46b22a4814061e63b754727/add_swap.sh) 8G
# With wget:
#bash <(wget -nv -O - https://gist.githubusercontent.com/alokraj68/c62b3eeaaf7b1be51c582494f5a18dd1/raw/d02785a02a7e7c74c46b22a4814061e63b754727/add_swap.sh) 8G
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment