Skip to content

Instantly share code, notes, and snippets.

@proshanto
Forked from noeldiaz/gist:d92e861095be80c2be6a
Last active August 29, 2015 14:08
Show Gist options
  • Select an option

  • Save proshanto/d7c76436c6fe49ab79ac to your computer and use it in GitHub Desktop.

Select an option

Save proshanto/d7c76436c6fe49ab79ac to your computer and use it in GitHub Desktop.

How to create Swap on Linux / Ubuntu

Enable swap

sudo swapon -s

Create a 2GB file

 sudo dd if=/dev/zero of=/swapfile bs=1024 count=2048k

Create the swap

sudo mkswap /swapfile

You should get something like this in return

Setting up swapspace version 1, size = 2097148 KiB
no label, UUID=b6f6f8ba-d8c7-4c12-9c1d-fa96826d9075

Turn the swap on

sudo swapon /swapfile

Edit your /etc/fstab and add to it:

/swapfile       none    swap    sw      0       0

Set swapiness to 10 so you don't get a poor performance

echo 10 | sudo tee /proc/sys/vm/swappiness
echo vm.swappiness = 10 | sudo tee -a /etc/sysctl.conf

Protect the swap file

sudo chown root:root /swapfile 
sudo chmod 0600 /swapfile
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment