Skip to content

Instantly share code, notes, and snippets.

@antonioribeiro
Last active August 29, 2015 14:01
Show Gist options
  • Select an option

  • Save antonioribeiro/fd98803ab9004e9daeef to your computer and use it in GitHub Desktop.

Select an option

Save antonioribeiro/fd98803ab9004e9daeef to your computer and use it in GitHub Desktop.
Swap

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