Skip to content

Instantly share code, notes, and snippets.

@smj10j
Created December 7, 2014 07:07
Show Gist options
  • Save smj10j/494aa68458af16de676d to your computer and use it in GitHub Desktop.
Save smj10j/494aa68458af16de676d to your computer and use it in GitHub Desktop.
Create a 2GB swap file on Ubuntu
#!/bin/bash
#
# https://meta.discourse.org/t/create-a-swapfile-for-your-linux-server/13880
#
install -o root -g root -m 0600 /dev/null /swapfile
dd if=/dev/zero of=/swapfile bs=1k count=2048k
mkswap /swapfile
swapon /swapfile
echo "/swapfile swap swap auto 0 0" | sudo tee -a /etc/fstab
sudo sysctl -w vm.swappiness=10
echo vm.swappiness = 10 > /etc/sysctl.d/60-swappiness.conf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment