Resizing LVM Volumes

Just a quick note to remind myself outhow to resize logical and physical LVM volumes

  • Activate the Volume group:

lvm vgchange -ay

  • Resize the logical volume (sizing down by 100G in this example)

lvm lvresize --size -100G /dev/vg/root -r --verbose

  • Resize the physical volume:

pvresize --setphysicalvolumesize {size of pv minus {size toreduce}}G /dev/path/to/pv

  • If you get an error about “later extents”, it’s due to the swap being added to the partition (which does not get moved automatically), so you will need to move the data

lvm pvs -v --segments /dev/sda5 to get position ids:

/dev/sda5 ubuntu lvm2 a-- 698.04g 150g 0 xxx root 0 linear /dev/sda:0-xxx
/dev/sda5 ubuntu lvm2 a-- 698.04g 150g xxx nnn 0 free                          
/dev/sda5 ubuntu lvm2 a-- 698.04g 150g yyy zzz swap 0 linear /dev/sda5:yyy-zzz
  • Move the data:

lvm pvmove --alloc anywhere /dev/sda5:yyy-zzz

  • Check the positioning again

pvs -v --segments /dev/sda5

/dev/sda5 ubuntu lvm2 a-- 698.04g 150g 0 xxx root 0 linear /dev/sda:0-xxx
/dev/sda5 ubuntu lvm2 a-- 698.04g 150g xxx nnn swap 0 linear /dev/sda5:xxx-yyy(-1)
/dev/sda5 ubuntu lvm2 a-- 698.04g 150g yyy zzz 0 free
  • Then retry the resize

pvresize --setphysicalvolumesize {size of pv minus {size toreduce}}G /dev/path/to/pv

%d bloggers like this: