Comment 2 for bug 1799953

Revision history for this message
Scott Moser (smoser) wrote :

It seems all we have to actually do is call 'pvresize' to make this all work.

That would mean after resize, we'd just have to do something like:

  # part_path here assumed to be full path to partition
  if command -v pvs && pvs -o pvname | grep -q "${part_path}$"
    debug "$part_path was a lvm physical volume, using pvresize"
    pvresize $part_path
  fi

For reference, see below. I just did a quick test with loop device (as root):

$ truncate --size 2G /tmp/my.img
$ losetup --find --show /tmp/my.img
/dev/loop5

# add partition 1 to be 1G of the 2G available .. manually
$ fdisk /dev/loop5

# this is necessary because fdisk doesn't do the addpart.
$ partprobe /dev/loop5

$ grep loop5 /proc/partitions
   7 5 2097152 loop5
 259 6 1048576 loop5p1

$ pvcreate /dev/loop5p1
  Physical volume "/dev/loop5p1" successfully created.
$ vgcreate testvg0 /dev/loop5p1
  Volume group "testvg0" successfully created
$ pvdisplay /dev/loop5p1
  --- Physical volume ---
  PV Name /dev/loop5p1
  VG Name testvg0
  PV Size 1.00 GiB / not usable 4.00 MiB
  Allocatable yes
  PE Size 4.00 MiB
  Total PE 255
  Free PE 255
  Allocated PE 0
  PV UUID o3d9dK-x7iA-8jws-Sl99-YFio-NQUs-CMCPuS

$ vgdisplay testvg0
  --- Volume group ---
  VG Name testvg0
  System ID
  Format lvm2
  ...
  Metadata Areas 1
  Metadata Sequence No 1
  VG Access read/write
  VG Status resizable
  MAX LV 0
  Cur LV 0
  Open LV 0
  Max PV 0
  Cur PV 1
  Act PV 1
  VG Size 1020.00 MiB
  PE Size 4.00 MiB
  Total PE 255
  Alloc PE / Size 0 / 0
  Free PE / Size 255 / 1020.00 MiB
  VG UUID N7I14w-i0Tr-7Sqs-8wOQ-7fDZ-l2oL-LdnoS2

$ growpart /dev/loop5 1
CHANGED: partition=1 start=2048 old: size=2097152 end=2099200 new: size=4192223 end=4194271

$ grep loop5 /proc/partitions
   7 5 2097152 loop5
 259 7 2096111 loop5p1

# it didn't grow by itself.
$ pvdisplay /dev/loop5p1 | grep PV.Size
  --- Physical volume ---
  PV Size 1.00 GiB / not usable 4.00 MiB

$ pvresize /dev/loop5p1
  /dev/sda: open failed: No medium found
  Physical volume "/dev/loop5p1" changed
  1 physical volume(s) resized or updated / 0 physical volume(s) not resized

# grow it
$ pvresize /dev/loop5p1
  Physical volume "/dev/loop5p1" changed
  1 physical volume(s) resized or updated / 0 physical volume(s) not resized

$ pvdisplay /dev/loop5p1
  --- Physical volume ---
  PV Name /dev/loop5p1
  VG Name testvg0
  PV Size <2.00 GiB / not usable 1.98 MiB
  Allocatable yes
  PE Size 4.00 MiB
  Total PE 511
  Free PE 511
  Allocated PE 0
  PV UUID o3d9dK-x7iA-8jws-Sl99-YFio-NQUs-CMCPuS

# and it seems to have taken on the vg
$ sudo vgdisplay testvg0
  --- Volume group ---
  VG Name testvg0
  System ID
  Format lvm2
  Metadata Areas 1
  Metadata Sequence No 2
  VG Access read/write
  VG Status resizable
  MAX LV 0
  Cur LV 0
  Open LV 0
  Max PV 0
  Cur PV 1
  Act PV 1
  VG Size <2.00 GiB
  PE Size 4.00 MiB
  Total PE 511
  Alloc PE / Size 0 / 0
  Free PE / Size 511 / <2.00 GiB
  VG UUID N7I14w-i0Tr-7Sqs-8wOQ-7fDZ-l2oL-LdnoS2