Remove a Physical Volume from VG with no free PE

lvmlvm2

I have LVM2 setup containing 2 Physical Volumes sda5 and sda6. Both Physical volumes are included in a single Volume Group VG, which inturn contains only one LV. The LV uses all the memory of the Physical Volumes, which means I cannot create another LV in the same
VG.

So, in short my entire lvm setup contains 2pv, 1vg, 1lv. The lv contains the linux os.

Now, I want to remove a pv from the volume group safely so i can use it for anything other than lvm. But pvdisplay shows all physical extents on both physical volumes are allocated and there are no free Physical Extents in any of them. But the actual data on the Logical Volume is only 10percent of the size of the LV.

If i use pvmove command, it shows the error "No Free Physical Extents available".

So, How can I safely Remove the physical disk from the volume group without loosing data?

Best Answer

It is possible to first shrink a volume and then do pvmove and then remove a physical disk.

Say 5GB of space is used.

first check filesystem.

e2fsck /dev/vg/lv

Resize filesystem to little above used space (say 6GB).

resize2fs -p /dev/vg/lv 6G

shrink lv to little > or = filesystem size.

lvreduce -L 6G /dev/vg/lv

align the end of filesystem with end of volume.

resize2fs -p /dev/vg/lv

then pvmove from source partition to target partition.

pvmove /dev/sda5 /dev/sda6

then verify if PhysicalExtents are allocated.

pvdisplay

If no PE are allocated then it is safe to remove a partition from lvm.

pvremove /part/to/be/removed
Related Question