Skip to content

Linux Swapfile

Terminal window
sudo dd if=/dev/zero of=/swapfile bs=1M count=4096 status=progress

This creates a swapfile and allocates 4GB for it

Terminal window
sudo chmod 600 /swapfile
Terminal window
sudo mkswap /swapfile
sudo swapon /swapfile
Terminal window
sudo bash -c "echo /swapfile none swap defaults 0 0 >> /etc/fstab"
Terminal window
sudo swapoff -a

Normaly you want your swap to be RAM(GB) + 2GB

So if you have 8GB of ram your swap should be 10GB

Terminal window
sudo dd if=/dev/zero of=/swapfile bs=1G count=10
Terminal window
sudo mkswap /swapfile
Terminal window
sudo swapon /swapfile

This should be it!