CentOS / RHEL : How to remove used Physical Volume(PV) from Volume Group (VG) in LVM

We have already seen how to remove an unused PV from the volume group with vgreduce command.

The vgreduce command shrinks the volume group by removing one or more PVs. But in case if the PV is in use by any of the LV, we have to first move the LVs onto some other free PVs using pvmove and then we can use the vgreduce command as usual to remove the PV. We can then either use these free PVS in another VG or remove them from the LVM configuration.

Removing used PV from VG

1. Extend the VG. where vg01 is the VG name and /dev/sdc is the destine device.

# vgextend vg01 /dev/sdc
  Volume group "vg01" successfully extended

If you have more than one disk, repeat this operation for all of them or provide disks in the same command with spaces.

2. Confirm the disk spaces using the pvs command. As you can see below the newly added disk is free with sufficient space to accommodate the data on /dev/sdb PV.

# pvs -o+pv_used
  PV         VG   Fmt  Attr PSize  PFree  Used  
  /dev/sda2  cl   lvm2 a--  19.00g     0  19.00g
  /dev/sdb   vg01 lvm2 a--  20.00g 10.00g 10.00g
  /dev/sdc   vg01 lvm2 a--  20.00g 20.00g     0

3. Run the pvmove command for the original PV that in this example is /dev/sdb. pvmove command will migrate all the LVs present on the device /dev/sdb to the device /dev/sdc. This is done online without any interruption. You could see the status on the command line.

# pvmove /dev/sdb
  /dev/sdb: Moved: 1.48%
  /dev/sdb: Moved: 100.00%

4. Reduce the VG in order to release the /dev/sdb PV.

# vgreduce vg01 /dev/sdb
  Removed "/dev/sdb" from volume group "vg01"

5. Check the /dev/sdb (origin) is completely free now.

# pvs -o+pv_used
  PV         VG   Fmt  Attr PSize  PFree  Used  
  /dev/sda2  cl   lvm2 a--  19.00g     0  19.00g
  /dev/sdb        lvm2 ---  20.00g 20.00g     0 
  /dev/sdc   vg01 lvm2 a--  20.00g 10.00g 10.00g

6. Now you can remove it completely from the LVM configuration if you want or you can use in some other volume group. Below is the example to remove it from LVM configuration.

# pvremove /dev/sdb
  Labels on physical volume "/dev/sdb" successfully wiped.
Related Post