Increase swap to file

  1. Turn off all swap processes

sudo swapoff -a

  1. Resize the swap to be 8GB for example

sudo dd if=/dev/zero of=/swapfile bs=1M count=8192

For 4GB will have to be 4086

if = input file
of = output file
bs = block size
count = multiplier of blocks

  1. Change permission

sudo chmod 600 /swapfile

  1. Make the file usable as swap

sudo mkswap /swapfile

  1. Activate the swap file

sudo swapon /swapfile

  1. Edit /etc/fstab and add the new swapfile entry if it isn’t already there
/swapfile none swap sw 0 0
  1. Check the amount of swap available:

grep SwapTotal /proc/meminfo

5 Likes