How to increase Swap size on Ubuntu

Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"

Hello, friends. Today, you will learn how to increase Swap on Ubuntu. The process is easier than you think. Let’s go.

Swap or swap memory space, or also known as virtual memory, is the one that uses the space on the HDD instead of a memory module.

This swap space can take the form of a disk partition or a file, depending on the needs of the user who installs the system. These users can create a swap space during installation or at any later time as they wish.

Swap space can be used for two purposes, to expand virtual memory beyond the installed physical memory (RAM) and also for suspend to disk support.

Increasing Swap on Ubuntu

Note: This post assumes that the Swap is not on a disk partition but in a swap file. Otherwise, it does not work.

First, try to do these instructions with the least number of applications open. So, you can be sure that Swap is not being used.

Then, open a terminal and identify the swap file

swapon --show

You will get an output like this

 NAME TYPE SIZE USED PRIO
 /swapfile file 1G 0B -2

You can’t operate on this file if it is running, so disable it and then delete it

sudo swapoff /swapfile
sudo rm /swapfile

Now comes the decision, moment. And this refers to the size of the Swap file. Usually, swap files are made to 16Gb. But this is not a rule but rather a scheme.

sudo dd if=/dev/zero of=/swapfile bs=1M count=16384

The value of count is the 16Gb that you will have to replace with the amount of Swap you want.

Then, assign appropriate permissions to the file. To achieve this, run.

sudo chmod 600 /swapfile

Format the file with the Swap format so that you can use it with the proper usage.

sudo mkswap /swapfile

Turn on the Swap

sudo swapon /swapfile

Finally, reboot the system to apply the changes.

Conclusion

Swap is one of the best things on Linux that can be manipulated to have more and more opportunities to expand its size.

Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"
Angelo
Angelo
I am Angelo. A systems engineer passionate about Linux and all open-source software. Although here I'm just another member of the family.

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest articles

Join us on Facebook