Sometimes it is necessary to add more swap space after installation. For example, you may upgrade the amount of RAM in your server from 1GB to 2 GB, but there is only 2GB of swap space. It might be advantageous to increase the amount of swap space to 3GB or 4GB if you perform memory-intense operations or run applications that require a large amount of memory.
We can do it in two ways: 
  1. add a swap partition 
  2. add a swap file.
It is recommended that you add a swap partition, but sometimes that is not easy if you do not have any free space available.
Create a new partition or Logical volume, based on your environment
For example
lvcreate -L 2GB -n swap_lv appvg
Now make that partition or LV as swap space.
mkswap /dev/appvg/swap_lv
 
Now turn on the swap on that LV or partition.
 
swapon /dev/appvg/swap_lv
 
Now this partition is added as swap space.
 
To check,
 
free -m
cat /etc/swaps



To enable it at boot time, edit   /etc/fstab   to include:  


/dev/appvg/swap_lv      swap swap defaults 0 0

Advertisements