This tutorial will teach you how to expand an existing Swap File on an Ubuntu or Debian VPS. This has been specifically tested on a low-spec AWS Lightsail VPS although this method should work with any generic VPS running Debian or Ubuntu with enough storage space available.
Expanding your Swap file can help relieve pressure on your low-spec VPS’ RAM, which on some hosting providers can cause your system to crash or hang (such as AWS Lightsail’s “burst capacity” being exceeded).
Swap files are a type of virtual memory in Debian & Ubuntu which allow you to offload RAM usage into a flat file on the disk. This frees up physical RAM space which is particularly useful for low-spec Virtual Private Servers.
Validate that we have an existing Swap File.
sudo swapon -show
Expected result (size, used, priority may be different!):
Filename Type Size Used Priority
/swapfile file 2097148 169728 -2
Disable current Swap File in order to make edits.
sudo swapoff -a
Allocate the amount of disk space you desire for the Swap file: (Replace X with the amount of GB you want to allocate)
sudo fallocate -l XG /swapfile
You will need to ensure the Swap file has the correct permissions. You can do this with the CHMOD command:
sudo chmod 600 /swapfile
Re-enable the Swap file with the following command:
sudo swapon /swapfile
Verify that the changes to the Swap file have taken effect by re-running the same command in Step 1:
sudo swapon -show
You have expanded the size of the Swap file on your Ubuntu or Debian VPS. This will relieve your RAM when it becomes overloaded and prevent burst capacity exceeding it’s limit on AWS Lightsail.
<< Back