So you would like to add more swap space in Redhat 7 or Centos 7 after installation.
Sometimes it is necessary to add more swap space after installation. For example, you may upgrade the amount of RAM in your system from 512 MB to 1026 MB, but there is only 512 MB of swap space. It might be advantageous to increase the amount of swap space to 1026 MB if you perform memory-intense operations or run applications that require a large amount of memory. It is recommended that you extend an existing logical volume.
How to Increase Swap Space in Redhat 7 or Centos 7
4 Step on extending the logical volume
- Check if enough space to extend the swap file
- Turn off the swap file
- Extend the swap file and format
- Turn back on the swap file and check if swap file has increased
Extend swap on an existing LVM2 logical volume
First make sure nothing is using the swap volume and also ensure you have enough space in your volume group.
Commands to Check enough Space
cat /etc/fstab # check name of swap volume group e.g /dev/mapper/centos-swap swap
lvdisplay /dev/mapper/centos-swap # show volume group info for VG Name
vgdisplay centos # show how much space is free in VG e.g. centos
How to Extend the Swap Volume
1. Disable swapping for the associated logical volume:
swapoff -v /dev/mapper/centos-swap
2. Resize the LVM2 logical volume by 256 MB:
lvm lvresize /dev/mapper/centos-swap -L +256M
3. Format the new swap space:
4. Enable the extended logical volume:
5. Test that the logical volume has been extended properly:
cat /proc/swaps free
I hope this guide is some help on how to add more swap space in Redhat 7 or Centos 7 after installation, it can be very useful when increasing the physical ram on your Redhat 7 or Centos 7 box.
For other Redhat related tutorials on my website please click here.
To Check our More Tips Please have a look at my YouTube Channel and subscribe for video tutorials as they are released, and if you have any requests please leave a comment below.