Enable SWAP on Ubuntu

Login as root:

sudo su


Create a swap file with 4 blocks of 1GB:

dd if=/dev/zero of=/mnt/swap bs=1G count=4


Enable the file for swap usage:

chmod 600 /mnt/swap
mkswap /mnt/swap
swapon /mnt/swap


Persist the swap file:

  • add to /etc/fstab (bottom):
/mnt/swap	none	swap	sw	0	0
  • add to /etc/sysctl.conf (bottom):
vm.swappiness=30


> Detailed procedure here