How to extend Swap Space in Logical Volume on RedHat 7

Extend Swap Space in Logical Volume on RHEL 7/CentOS 7/RHEL 8/CentOS 8

In this lab, we will learn how to increase swap space on RHEL 7/CentOS 7/RHEL 8/CentOS 8 Linux base operating system. The purpose to use swap space is when ram of the operating system fully utilize, swap space allocate from the hard drive of the machine and take inactive pages available in memory. One important point to remember memory is a combination of RAM and SWAP and memory is utilize by the each process of CPU (Central processing unit). If swap is use rather than ram (random access memory), system performance will slow. You can say swap space is a part of virtual memory (disk space and ram) or sub title of physical memory.

Definition of Swap Space:

The definition of swap space is exchange the information means swapping information from real memory to virtual memory by use of disk space that is called swap space.

Advantage of Swap Space:

Sometime swap space require when application or program is creating a malfunction, it is very helpful in this scenario. Swap space also use when you hibernate operating system that save your work on current state.

Disadvantage of Swap Space:

When the RAM (Random Access Memory) is fully utilize swap space is use but swap space slow down the system performance or you can say when swap space is utilize more than RAM (Random Access Memory) its slow down the system performance.

Swap Space Recommendation:

  • ·         If system RAM is less than and equal to 2GB recommended swap space two time the amount of RAM and for hibernation 3 times the amount of RAM.
  • ·         If system RAM is greater than 2GB to 8GB recommended swap space equal to the amount of RAM and for hibernation 2 times the amount of RAM.
  • ·         If system RAM is greater than 8GB to 64GB recommended swap space at least 4GB and for hibernation 1.5 times the amount of RAM.
  • ·         If system RAM is greater than 64GB recommended swap space at least 4GB and for hibernation swap space is not recommended but if you add little swap space it will helpful for malfunction program that consume all of RAM size.

Now start the process how to extend Swap space using Logical Volume Management. First check the size of volume group by type the below mention command.

vgs

how to extend swap space in logical Volume on redhat 7

In the above image you see that not enough space is availaible to extend the SWAP space, here is only 224MB is available in volume group “rhel_redhat7lvm”. For demo purpose we are adding 4GB additional virtual hard disk to increase size of volume group then we will increase the size of logical volume “SWAP”. Before add the additional virtual hard disk first power off the machine for any ambiguity.


how to extend swap space in logical Volume on redhat 7

After add the additional hard disk on virtual machine, power on the virtual machine and type the below mention command to verify the virtual hard disk has added successfully or not.

lsblk
how increase swap space in logical Volume on centos 7

In the above image, you can see the hard disk “sdc” of size 4GB has successfully added. Now create the physical volume of hard disk “sdc” by type the below mention command.

pvcreate /dev/sdc

how to extend swap space in logical Volume on centos 7

To extend the volume group “rhel_redhat7lvm” by use of physical volume “/dev/sdc”, type the below mention command.

vgextend volume-group /dev/sdc
vgextend rhel_redhat7lvm /dev/sdc


how to extend swap space in logical Volume on centos 7

To verify volume group “rhel_redhat7lvm” has successfully extended or not, type the below mention command.

vgs

how to extend swap space in logical Volume on centos 7

In the above image, you see that the volume group “rhel_redhat7lvm” has successfully extended from 224MB to 4.21GB.

To check the details of swap space on RHEL 7/CentOS 7/RHEL 8/CentOS 8, type the below mention command.

free -g
or
free -m

extend swap space in logical Volume on redhat 8

In the above image, you can see swap space currently is in active state. To extend the logical volume “swap” first disable the swapping by type the below mention command.

swapoff -a

extend swap space in logical Volume on redhat 8

To verify swap space has disabled on device and files (/proc/swaps or /etc/fstab), type the below mention command.

free -g


extend swap space in logical Volume on redhat 8

In the above image, it has been verify swap space has disabled.

Extend the swap space logical volume “swap”, use 100% remaining size of volume group “rhel_redhat7lvm”.

lvextend -l +100%FREE /dev/Volume-Group/Logical-Volume
lvextend -l +100%FREE /dev/rhel_redhat7lvm/swap


extend swap space in logical Volume on centos 8

After extend the swap space, you need to reformat the logical volume “swap” by type the below mention command.

mkswap /dev/rhel_redhat7lvm/swap


how increase swap space in logical Volume on redhat 7

After reformat the logical volume ”swap”, enable the swap space by type the below mention command.

swapon -a

how increase swap space in logical Volume on redhat 7

To Verify swap space has enabled successfully, type the below mention command.

free -g

how increase swap space in logical Volume on centos 7

To verify swap space has been successfully extended from 4GB to 8GB type the below mention command.

lsblk

how increase swap space in logical Volume on centos 7

Thanks for Read this Article

Comments