Change swap file size in Virtualmin

Reading Time: < 1 minutes

If you follow to our Virtualmin Installation, the installation script set the Swap file size to 263M by default. If you wish to check your current swap file, run the “free -h”

[[email protected] ~]# free -h
              total        used        free      shared  buff/cache   available
Mem:           992M        369M        426M        500K        195M        470M
Swap:          263M        120M        142M

However, if you have not created your first Virtualmin installation, you may refer to these links article below:

Install Virtualmin on Ubuntu 16.04.
Install Virtualmin on Debian 9

To go about this, let us change the swap file size twice the size of your current RAM. In our situation, we have 1 GB of RAM. In my case, I will change the 2 GB.

Let us get this started!

swapoff -a
dd if=/dev/zero of=/swapfile count=2048 bs=1MiB

2048 is the MB size I wish to apply for my swap file. If you wish to change these to your desired MB size, feel free to do so.

mkswap /swapfile
swapon /swapfile

Let us edit the fstab (known as file systems table) file.

sudo nano /etc/fstab

Then, add this line below:

/swapfile   swap    swap    sw  0   0

To save our changes, press ctrl + x, then enter y. Once saved, run this command below:

sudo sysctl vm.swappiness=10
sudo nano /etc/sysctl.conf

From here, add these lines below:

vm.swappiness = 10
vm.vfs_cache_pressure = 50

To save our changes, press ctrl + x, then enter y. Once completed, you may verify these changes via:

free -h
              total        used        free      shared  buff/cache   available
Mem:           996M        726M        137M         18M        132M        124M
Swap:          2.0G        500M        1.5G

At this point, you should be all set. Great Job.

Was this post helpful?

Leave a Reply