Online resizing of lvm partition for libvirtd guests

This use case just reappeared the third time and I had to lookup the commands again. So I am documenting them here, to easier find them the next time.

Assume the follwoing:

  • we have a guest VM running in libvirtd called guest01
  • besides its root device it has a data partition backed in an LVM
  • the volume group is called vg01 and the logical volume data01
  • we want to grow the data partition to 100G
  • the resizing should be done online, so without a downtime of the VM

First we need to resize the logical volume:

lvresize -L 100G /dev/vg01/data01

Next we need to find out the path name of this device in the libvirt VM. The list of all devices can be printed with:

virsh domblklist guest01

Take the path value and use it in the next command (I will use vdX here). The blockresize command will inform libvirtd about the new size of the LVM volume.

virsh blockrezise guest01 --path vdX --size 100

Now the logical volume is bigger and libvirtd propagated the change into the VM. So you can see the new partition size inside the VM. But the file system was not changed yet.

The last step, resizing the file system, has to be done inside the VM:

resize2fs /dev/vdX   # for ext[2,3,4]
xfs_growfs /dev/vdX  # for xfs