Increase swap space in Redhat 7 | Centos 7

By | February 23, 2019

This post may contain affiliate links. Please read my disclosure for more info.

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 | Centos 7

How to Increase Swap Space in Redhat 7 or Centos 7

4 Step on extending the logical volume

  1. Check if enough space to extend the swap file
  2. Turn off the swap file
  3. Extend the swap file and format
  4. 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:

mkswap /dev/mapper/centos-swap

4. Enable the extended logical volume:

swapon -va

5. Test that the logical volume has been extended properly:

cat /proc/swaps free

Summary

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.