Let see an example of increasing existing swap space by adding new LVM based swap. The example here uses the disk /dev/sdc for creating a new volume group and swap volume under it. Since we are going to use this disk, any data, if exists on it, will be lost.
As root user perform the following tasks:
1. Add the disk /dev/sdc as the physical volume.
# pvcreate /dev/sdc
2. Create volume group named ‘swap_vg’ ( You may add the disk in an existing volume group if you have one. In the example here, I am creating a new volume group.)
# vgcreate swap_vg /dev/sdc
3. To create logical volume of size 20Gb, use below command.
# lvcreate -L 20G -n lvswap swap_vg
4. Formatting the device with the SWAP format.
# mkswap /dev/swap_vg/lvswap
5. Enable the extended logical volume swap.
# swapon -v /dev/swap_vg/lvswap
6. Add the following entry to the /etc/fstab file.
/dev/swap_vg/lvswap swap swap defaults 0 0
7. Verify the Swap space by ‘free’ command or ‘cat /proc/swaps’ command :
# free
# cat /proc/swaps