In this tutorial, we will cover how to increase swap space on a Linux environment.

In this example, we will utilize a VPS server that has a RAM allocation of 1 GB RAM. For a server having RAM of 1GB, the ideal SWAP space should be between 1GB and 2GB according to the application that you use.

[root@ ~]# free -m

total used free shared buff/cache available

Mem: 965 98 759 0 108 743

Swap: 1023 0 1023

[root@ ~]# swapon -s

Filename Type Size Used Priority

/mnt/swapfile file 1048576 0 -2

Here, we can see that the swap space is 1024MB (1GB) and the file is /mnt/swapfile

Now, we are going to increase the swap space to 2GB.

Step 1

Disable the swap file /mnt/swapfile

# swapoff /mnt/swapfile

Step 2

Now, we need to increase the size of swap to 2GB by using command “dd”

# dd if=/dev/zero of=/mnt/swapfile bs=1M count=1024 oflag=append conv=notrunc

Now it will add an additional 1 GB of disk space to the swap.

Step 3

Now setup the file as swapfile using the command mentioned below:

# mkswap /mnt/swapfile

output will be shown below:

mkswap: /mnt/swapfile: warning: wiping old swap signature.

Setting up swapspace version 1, size = 2 GiB (2147479552 bytes)

Step 4

To enable swap space on the file run the command mentioned below:

# swapon /mnt/swapfile

The output:

[root@ ~]# free -mh

total used free shared buff/cache available

Mem: 965M 99M 757M 412K 108M 742M

Swap: 2.0G 0B 2.0G

Now, we can see that the swap space has increased from 1GB to 2GB accordingly.

Server Hosting Solutions by RackNerd:

Shared Hosting
cPanel Web Hosting in US, Europe, and Asia datacenters
Logo
Reseller Hosting
Create your new income stream today with a reseller account
Logo
VPS (Virtual Private Server)
Fast and Affordable VPS services - Instantly Deployed
Logo
Dedicated Servers
Bare-metal servers, ideal for the performance-demanding use case.
Logo

Leave a comment

Your email address will not be published. Required fields are marked *