How to Extend and Reduce a Volume Group in LVM

Extending and Reducing a Volume Group

You can add more disk space to a volume group by adding additional physical volumes. This is called extending the volume group. Then, you can assign the new physical extents from the additional physical volumes to logical volumes.

You can remove unused physical volumes from a volume group. This is called reducing the volume group. First, use the pvmovecommand to move data from extents on one physical volume to extents on other physical volumes in the volume group. In this way, a new disk can be added to an existing volume group, data can be moved from an older or slower disk to a new disk, and the old disk removed from the volume group. You can perform these actions while the logical volumes in the volume group are in use.

Extending a Volume Group

To extend a volume group, perform the following steps:

1. Prepare the physical device and create the physical volume

As with creating a new volume group, you must create and prepare a new partition for use as a physical volume if there are none prepared already.

[root@host ~]# parted -s /dev/vdb mkpart primary 1027MiB 1539MiB
[root@host ~]# parted -s /dev/vdb set 3 lvm on
[root@host ~]# pvcreate /dev/vdb3

A PV only needs to be created if there are no PVs free to extend the VG.

2. Extend the volume group

Use vgextend to add the new physical volume to the volume group. Use the VG name and PV device name as arguments to vgextend.

[root@host ~]# vgextend vg01 /dev/vdb3

This extends the vg01 VG by the size of the /dev/vdb3 PV.

3. Verify that the new space is available

Use vgdisplay to confirm the additional physical extents are available. Inspect the Free PE / Size in the output. It should not be zero.

[root@host ~]# vgdisplay vg01
  --- Volume group --
  VG Name               vg01
...output omitted...
  Free  PE / Size       178 / 712.00 MiB
...output omitted...

Reducing a Volume Group

To reduce a volume group, perform the following steps:

1. Move the physical extents

Use pvmove PV_DEVICE_NAME to relocate any physical extents from the physical volume you want to remove to other physical volumes in the volume group. The other physical volumes must have a sufficient number of free extents to accommodate this move. This is only possible if there are enough free extents in the VG and if all of those come from other PVs.

[root@host ~]# pvmove /dev/vdb3

This command moves the PEs from /dev/vdb3 to other PVs with free PEs in the same VG.

WARNING: Before using pvmove, back up data stored on all logical volumes in the volume group. An unexpected power loss during the operation may leave the volume group in an inconsistent state. This could cause loss of data on logical volumes in the volume group.

2. Reduce the volume group

Use vgreduce VG_NAME PV_DEVICE_NAME to remove a physical volume from a volume group.

[root@host ~]# vgreduce vg01 /dev/vdb3

This removes the /dev/vdb3 PV from the vg01 VG and it can now be added to another VG. Alternatively, pvremove can be used to permanently stop using the device as a PV.