Home Linux Swapfile
Post
Cancel

Linux Swapfile

Creating the swapfile

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

This creates a swapfile and allocates 4GB for it

Set the required permissions

1
sudo chmod 600 /swapfile

Enable the swapfile

1
2
sudo mkswap /swapfile
sudo swapon /swapfile

Ensure swap is enabled at boot

1
sudo bash -c "echo /swapfile none swap defaults 0 0 >> /etc/fstab"

Increasing the size of the swapfile

Turn off all swap processes

1
sudo swapoff -a

Resize swap

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

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

1
sudo dd if=/dev/zero of=/swapfile bs=1G count=10

Make the file usable as swap

1
sudo mkswap /swapfile

Activate the swapfile

1
sudo swapon /swapfile

This should be it!

This post is licensed under CC BY 4.0 by the author.