Linux – Shrink Volume Group in LVM on linux with just one disk

linuxlvm

I'm using LVM on a single disk and now I need to resize the partition (sda2) I'm using.

I've already resized the Logical Volume but I can't manage to shrink the Volume Group. I know that vgreduce can remove Physical Volumes entirely but I have only one and I need too shrink that one.

Is it possible?

Best Answer

Assuming Linux LVM.

Reducing the size of a PV, and keeping the same PV partition, is a multiple step process. A little bit dangerous, data corruption is possible if the volumes are reduced too small for the file system.

  1. Backup data.
  2. Reduce the size of the file system. This is not possible for XFS, in which case you will need an alternative solution like restore backups to a smaller volume.
  3. lvreduce --resizefs --size the LV. --resizefs does step #2 at the same time, ensuring the sizes match.
  4. pvresize --setphysicalvolumesize the PV.
  5. Re-partition the PV. Tricky on the PV that contains the root file system. May be necessary to reboot into a rescue enviornment with root not mounted and VG not activated.

vgreduce removes entire PVs from the VG, and is not useful in this example.


As an alternative, if you move to using entire disks and not partitions, this process can be simpler.

  1. Backup data.
  2. lvreduce --resizefs --size if necessary to fit in the new disk
  3. Create disk, say it is named /dev/sdb
  4. vgextend /dev/sdb
  5. pvmove /dev/sda1
  6. vgreduce /dev/sda1

End result, VG moved to new disk, old partition empty and can be deleted.