How to Add Swap Space on Debian 13

This guide is applicable only for KVM-based VPSes and dedicated servers. If you wish to increase swap on your OpenVZ-based VPS, please contact us via a Support ticket from the client area.

Check Swap Information

Command to check swap size.

swapon --show

Output:

root@vps:~# swapon --show
NAME      TYPE      SIZE USED PRIO
/dev/vda1 partition 487M   0B   -2

Or you can check using the free command.

free -m

Output:

root@vps:~# free -m
               total        used        free      shared  buff/cache   available
Mem:            1985         310         940           0         880        1692
Swap:            486           0         486

NOTE: If the output is empty, it means that swap space is not enabled yet on your system.

Add Swap to your VPS

Command to create a swap file.

NOTE: We are adding 1GB. If you want to add a different size, replace 1G accordingly.

fallocate -l 1G /swapfile

Or alternatively:

dd if=/dev/zero of=/swapfile bs=1024 count=1048576

Set the correct file permission:

chmod 600 /swapfile

Set up a swap area on the file:

mkswap /swapfile

Output:

root@vps:~# mkswap /swapfile
Setting up swapspace version 1, size = 1024 MiB (1073737728 bytes)
no label, UUID=5c18fa02-9f60-4eb1-8df9-d90ecb4d81b6

Activate the swap file:

swapon /swapfile

To make it permanent, edit the following file:

nano /etc/fstab

Add the following line to the end of the file:

/swapfile swap swap defaults 0 0

Now verify the new swap space:

swapon --show

Or:

free -m

Output:

root@vps:~# swapon --show
NAME       TYPE      SIZE USED PRIO
/dev/vda1  partition 487M   0B   -2
/swapfile  file     1024M   0B   -3
root@vps:~# free -m
               total        used        free      shared  buff/cache   available
Mem:            1985         312         938           0         883        1690
Swap:           1510           0        1510

NOTE: Now the added swap space can be seen.

Remove Swap File

Deactivate the swap space:

swapoff -v /swapfile

Output:

root@vps:~# swapoff -v /swapfile
swapoff /swapfile

Next, remove the following line from the file /etc/fstab:

/swapfile swap swap defaults 0 0

Command to remove the swap file:

rm /swapfile

This concludes our topic of configuring swap in Debian 13.


CrownCloud - Get a SSD powered KVM VPS at $4.5/month!
Use the code WELCOME for 10% off!

1 GB RAM / 25 GB SSD / 1 CPU Core / 1 TB Bandwidth per month

Available Locations: LAX | MIA | ATL | FRA | AMS