Linux – How to reduce and remove Physical Volume from active Logical Volume

linuxlvmpartition

For testing purposes I've tried to extend my logical volume by attaching one more Physical Volume (USB drive). Making the USB drive part from the logical volume with the following steps:

  • Created partition from the device
  • Created Physical Volume from the new partition
  • Attached the Physical Volume to the already configured Volume Group
  • And finally extending the Logical Volume

My question is how to unmount and remove the USB drive without losing any data on the already existing Logical Volume?

Best Answer

for the resize2fs bit, it's like this:

e2fsck -f /dev/myvg/lvtest
resize2fs /dev/myvg/lvtest 96M #always a bit smaller than the LV

### then the rest as above
lvresize -l 100M /dev/myvg/lvtest
vgreduce myvg /dev/sdX

###then regrow that to fit the volume perfectly 
lvresize -l 100% /dev/myvg/lvtest
resize2fs /dev/myvg/lvtest 

I hope you're on ext2/3/4 . If on XFS, you may need to be creative!

Related Question