Cloud Platform – Add Swap File on CentOS 7

I will start with adding 4GB of swapfile

sudo fallocate -l 4G /swap.engineer.org.pk

to check 4GB equivalent to KB I will use below site:

https://www.gbmb.org/gb-to-kb

4GB = 4194304 KB (in binary)

So run below command now:

sudo dd if=/dev/zero of=/swap.engineer.org.pk bs=1024 count=4194304

wait for a while so that system creates a 4 GB file.

See correct permissions:

sudo chmod 600 /swap.engineer.org.pk

and

sudo mkswap /swap.engineer.org.pk
sudo swapon /swap.engineer.org.pk

you will need to add the swap file permanently, otherwise when the system will reboot this will be removed.

sudo nano /etc/fstab

you might need to install nano utility to install nano:

sudo yum install nano

after the nano is installed now run the same command to edit fstab file:

sudo nano /etc/fstab

move the cursor to the end of the file and paste:

/swap.engineer.org.pk swap swap defaults 0 0

to check if your swap file is added:

sudo swapon --show

you will need to setup how frequently the swap file should be used, to do that you can use below commands:

sudo nano /etc/sysctl.conf

Add below lines:

vm.swappiness = 20
vm.vfs_cache_pressure = 50
Cloud Platform - Add Swap File on CentOS 7

In case you want to remove the swap file for some reason you can remove by using this command:

sudo swapoff -v /swap.engineer.org.pk
sudo rm /swap.engineer.org.pk

and at the end reboot the system:

reboot

you will see the system performance will boost.

 

Learn more about Cloud Platform follow below links:

Cloud Platform – How to Create Account on Oracle Cloud – Part 1

https://engineer.org.pk/blog/2019/10/04/how-to-create-account-oracle-cloud/

Cloud Platform – Launch VM Instance on Oracle Cloud – Part 2

https://engineer.org.pk/blog/2019/10/07/cloud-platform-launch-vm-instance-part-2/

Leave a Reply

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