4

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?

3 Answers3

4

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!

3

Did you extend any filesystem in logical volume ?

if yes

reduce size of Filesystem (If this can be achieved) ... (remove file, use fsck -B).

if no

lvreduce --size 100M /dev/myvg/lvtest
vgreduce myvg /dev/rdsk/myusb

with obvious meaning for myvg and myusb.

Archemar
  • 31,554
2

In addition to not losing data.

The USB could be unmounted with data in its volume group/logical volumes.

The data and storage space in the USB will be available when mounted on a server.

I would say LVM formatted USB

enter image description here

U. Kris
  • 21
  • 2