How to increase RAM memory – II (LVM)

We cab increase the RAM SWAP memory by using the following commands but make sure that you have logged in as a root user.

1st) First open the /etc/fstab file and check the volume group used for the swap.

~~~~~~~~~~~~
/dev/mapper/vg_test-lv_swap swap swap defaults 0 0
~~~~~~~~~~~~

In above example the VG is /dev/mapper/vg_test-lv_swap

2nd) Now set the swap off for the VG /dev/mapper/vg_test-lv_swap
swapoff -v /dev/mapper/vg_test-lv_swap

3rd) Create the filesystem for new swap partition
~~~~~~~~~~~~~~
mkfs.ext3 -b 4568 /dev/sda4
~~~~~~~~~~~~~~

In above example, we have used /dev/sda4

4th) Create the phyiscal volume

pvcreate /dev/sda4

5th) Check the status for the new free disk space

vgdisplay
6th) Now extend the volume group

vgextend vg_test /dev/sda4

7th) Now extend the size of a logical volume :

~~~~~~~~~~~~~~
lvresize /dev/mapper/vg_test-lv_swap -L +4G
~~~~~~~~~~~~~~

As per above command the new RAM swap memory value will be 4GB

8TH) Now format the new swap space:

mkswap /dev/mapper//vg_test-lv_swap

9th) Enable the extended logical volume:

swapon -va
Check the new swap value by using the following command

free -m

If you want to decrease the swap FROM 4G TO 3G  then run the following command

lvreduce -L 3G /dev/mapper/vg_test-lv_swap

About Anant 386 Articles
Senior technical writer