Skip to content

Instantly share code, notes, and snippets.

@h3nr1ke
Created July 7, 2018 01:07
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 h3nr1ke/8a23d435bda6e132ef419fd0f97802fa to your computer and use it in GitHub Desktop.
Save h3nr1ke/8a23d435bda6e132ef419fd0f97802fa to your computer and use it in GitHub Desktop.
Add a swap memory partition to your ubuntu 16.04 server
#!/bin/bash
#-- create the swap
sudo fallocate -l 1G /swapfile
#-- change permission
sudo chmod 600 /swapfile
#-- do the swap
sudo mkswap /swapfile
#-- add the swapp to be permanent
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab
#-- add configs to swap
echo 'vm.swappiness=10' | sudo tee -a /etc/sysctl.conf
echo 'vm.vfs_cache_pressure=50' | sudo tee -a /etc/sysctl.conf
echo "Swap created"
#-- show the info
sudo swapon --show
free -h
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment