How to Add Swap Space on Ubuntu 25.10

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.

Swap space, also known as "swap," is a reserved area on a server’s storage device that the operating system uses as virtual memory when physical memory (RAM) is fully utilized. When your server’s memory is exhausted, the OS moves less frequently used data to swap space to free up RAM and prevent performance degradation or crashes.

Here’s how to add swap space on an Ubuntu 25.10 server:

Check Swap Information

Command to check swap size.

swapon --show

Output:

root@server:~# swapon --show
NAME      TYPE SIZE USED PRIO
/swap.img file   2G   0B   -2
root@server:~# 

Or check using the free command.

free -m

Output:

root@server:~# free -m
               total        used        free      shared  buff/cache   available
Mem:            3936         412        3365           1         159        3457
Swap:           2047           0        2047
root@server:~# 

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

Add Swap

Command to create a swap file.

NOTE: We are adding 1GB. You can replace 1G with your preferred size.

fallocate -l 1G /swapfile

or

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

Set the correct permissions to restrict access:

chmod 600 /swapfile

Set up a swap area on the file.

mkswap /swapfile

Output:

root@server:~# mkswap /swapfile
Setting up swapspace version 1, size = 1024 MiB (1073737728 bytes)
no label, UUID=8e6f65b1-b1f4-48cf-bb0a-47b2cb087a0b
root@server:~# 

Activate the swap file.

swapon /swapfile

Open the following file and add the given content to make the swap persistent.

nano /etc/fstab

Add this line at the end of the file:

/swapfile swap swap defaults 0 0

Now verify the swap space.

swapon --show

or

free -m

Output:

root@server:~# swapon --show
NAME      TYPE  SIZE USED PRIO
/swap.img file    2G   0B   -2
/swapfile file 1024M   0B   -3
root@server:~# 

Or

root@server:~# free -m
               total        used        free      shared  buff/cache   available
Mem:            3936         411        3364           1         160        3458
Swap:           3071           0        3071
root@server:~# 

NOTE: The added swap space is now active and visible.

Remove Swap

To deactivate the swap space:

swapoff -v /swapfile

Output:

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

Next, remove the corresponding line from /etc/fstab.

nano /etc/fstab

Remove this line:

/swapfile swap swap defaults 0 0

Delete the swap file.

rm /swapfile

This concludes our topic of configuring swap on Ubuntu 25.10.

If you face any technical difficulties, kindly reach out to us via Support Ticket.


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