Devops. I've never asked for this.

Online resizing LVM guest-partitions on OpenNebula/libvirt guests

Today I found out howto resize guest partitions on OpenNebula (or in general with libvirt, which OpenNebula uses underneath for KVM virtualization).

I’m using a LVM storage for virtual machines. So resizing them is pretty easy.

Note: Replace the XX below with your virtual machines ID, as you can find out with e.g. onevm list or virsh list

host ~ $ sudo lvresize -L 50G /dev/volgrp/lv-one-XX
  Extending logical volume lv-one-XX to 50.00 GiB
  Logical volume lv-one-XX successfully resized

Then, you need to tell libvirt about the new size. This can be done with the following command: Note: The —path argument is the device name of the partition used by the guest. You can find it out by using virsh domblklist one-XX

host ~ $ sudo virsh blockresize one-XX --path vdX --size 50G
Block device 'vdX' is resized

Now simply login your guest machine and adapt the filesystem (no reboot required)

guest ~ $ sudo resize2fs /dev/vdX   # For ext filesystems
guest ~ $ sudo xfs_growfs /dev/vdX  # For xfs filesystems

Unfortunately, the new size will not display in the SIZE attribute of the image in OpenNebula (as seen with oneimage show XX). Apparently this is only set when creating the image.

As far as I know, this only works when using the virtio or scsi block drivers. In OpenNebula you can e.g. set DEV_PREFIX="vd" in your image configuration to use virtio.

Many thanks to Humble Chirammal for pointing out virsh blockresize.