Removing a physical volume


3 cases for removing the physical volume

 

  1. ¬†If PFree and Psize are equal which means the physical volume don’t have any data in it , so we can directly remove the physical volume from the volume group by vgreduce and then remove the physical volume by pvremove.¬†Example in the below list we can remove /dev/sde and /dev/sdf directly from VG01
  2. If PFree and Psize are different which means the physical volume has data. so first we need to move the data safely to some other physical volume which has space and then follow the case 1. Example in the below list we should move the data in /dev/sdc and /dev/sdd before doing vgremove
  3. If the physical volume is not part of any volume group we can directly remove the phsical volume by pvremove

 

[root@server1 ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/sdb VG01 lvm2 a– 10.00g 0
/dev/sdc VG01 lvm2 a– 10.00g 9.99g
/dev/sdd VG01 lvm2 a– 10.00g 9.96g
/dev/sde VG01 lvm2 a– 10.00g 10.00g
/dev/sdf VG01 lvm2 a– 10.00g 10.00g

I am going to show the case 2 so that we can understand all the steps

Step 1:

Move the data from one phsical volume to another
pvmove is slow if we have more data in the physical volume

[root@server1 ~]# pvmove /dev/sdc /dev/sdd
/dev/sdc: Moved: 100.0%

Now we can see the data in /dev/sdc is moved (PSize = PFree)

[root@server1 ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/sdb VG01 lvm2 a– 10.00g 0
/dev/sdc VG01 lvm2 a– 10.00g 10.00g
/dev/sdd VG01 lvm2 a– 10.00g 9.95g
/dev/sde VG01 lvm2 a– 10.00g 10.00g
/dev/sdf VG01 lvm2 a– 10.00g 10.00g

 

Step 2:

Remove the physical volume from volume group (VG01)

[root@server1 ~]# vgs
VG #PV #LV #SN Attr VSize VFree
VG01 5 2 0 wz–n- 49.98g 39.94g
[root@server1 ~]# vgreduce VG01 /dev/sdc
Removed “/dev/sdc” from volume group “VG01”
[root@server1 ~]# vgs
VG #PV #LV #SN Attr VSize VFree
VG01 4 2 0 wz–n- 39.98g 29.95g

 

Step 3:

Remove the physical volume

List the physical volume

[root@server1 ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/sdb VG01 lvm2 a– 10.00g 0
/dev/sdc lvm2 a– 10.00g 10.00g
/dev/sdd VG01 lvm2 a– 10.00g 9.95g
/dev/sde VG01 lvm2 a– 10.00g 10.00g
/dev/sdf VG01 lvm2 a– 10.00g 10.00g

Remove the physical volume

[root@server1 ~]# pvremove /dev/sdc
Labels on physical volume “/dev/sdc” successfully wiped

Now we can see below the physical volume is removed .

[root@server1 ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/sdb VG01 lvm2 a– 10.00g 0
/dev/sdd VG01 lvm2 a– 10.00g 9.95g
/dev/sde VG01 lvm2 a– 10.00g 10.00g
/dev/sdf VG01 lvm2 a– 10.00g 10.00g