How to resize logical volume in CentOS 7?

This article talks about how to resize the logical volume on CentOS 7. If your logical volume is nearly filled or for other reasons, you would like to expand the existing logical volume, you might be wondering if there is an easy way to resize logical volume!

Assumptions: This article also assumes that you have a Volume marked as Physical Volume. Furthermore, Volume Group(s) and Logical Volume Group(s) reside on this Volume Group. Physical disk is not partitioned into any sub partitions.

Resize logical Volume in CentOS 7

Prior to resizing the logical volume, make sure that there is free space available in Physical Volume (Volume marked as pvs). If not, expand the physical disk at VM hardware level. We will add 10G to our existing disk.

Once the disk has been extended, issue the following command to resize the physical volume.

[root@masterlocal ~]# pvresize /dev/sdb

  Physical volume "/dev/sdb" changed

  1 physical volume(s) resized or updated / 0 physical volume(s) not resized

[root@masterlocal ~]# pvs

  PV         VG      Fmt  Attr PSize   PFree

  /dev/sdb   vg_vol1 lvm2 a--  <50.00g 10.00g

Above command will resize the physical volume and Volume Groups (associated to this physical volume) will show the free space as well.

[root@masterlocal ~]# vgs

  VG      #PV #LV #SN Attr   VSize   VFree

  vg_vol1   1   1   0 wz--n- <50.00g 10.00g

Since the Volume groups, now, have space to borrow, it is very easy to resize the logical volume or volumes. Say, we have logical volume called  log_vol1 vg_vol1 which we want to extend to 8G above its current size. Issue the following command then:

[root@masterlocal ~]# lvextend -L+8G -r /dev/vg_vol1/log_vol1

  Size of logical volume vg_vol1/log_vol1 changed from <40.00 GiB (10239 extents) to <48.00 GiB (12287 extents).

  Logical volume vg_vol1/log_vol1 successfully resized.

resize2fs 1.42.9 (28-Dec-2013)

Filesystem at /dev/mapper/vg_vol1-log_vol1 is mounted on /log_vol; on-line resizing required

old_desc_blocks = 5, new_desc_blocks = 6

The filesystem on /dev/mapper/vg_vol1-log_vol1 is now 12581888 blocks long.




[root@masterlocal ~]# lvs

  LV       VG      Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert

  log_vol1 vg_vol1 -wi-ao---- <48.00g

In the above command:

  • lvextend is used to extend the existing logical volume
  • -L+8G flag tells the system to extend the logical volume by adding 8G to its original size.
  • -r option resizes the file system when the logical volume has been extended. This could be done separately, by using resize2fs command (depending upon the file system configured on logical volume).

 

In this article, we have seen how to resize logical volume in CentOS 7.

Share your thoughts

*