LVM: How to Remove a Physical Volume (PV)

To remove a Physical Volume (PV) from a Volume Group (VG) in LVM (Logical Volume Manager), follow these steps:

1. Check the Current Setup

First, identify the Volume Group (VG) and Physical Volumes (PVs) available:

vgs
pvs

To check which Logical Volumes (LVs) are using the PV:

pvdisplay -m /dev/sdX

2. Move Data Off the PV (If Necessary)

If the PV contains data, you must move it to another PV in the same VG before removal.

pvmove /dev/sdX

This command migrates data from /dev/sdX to other PVs in the VG.

3. Remove the PV from the Volume Group

Once the PV is empty, remove it from the Volume Group:

vgreduce my_vg /dev/sdX

4. Remove the PV from LVM Completely (Optional)

If you no longer want the disk to be part of LVM, you can remove the LVM metadata:

pvremove /dev/sdX

5. Verify the Changes

Ensure that the PV is no longer part of the VG:

vgs
pvs

Now, /dev/sdX is free to be repurposed or used elsewhere.