Grow a guest block device live
There’s nothing surprising about the following, except that it works very well.
Suppose a Windows guest on a KVM/libvirt hypervisor runs low on disk space. Assuming the guest has the VirtIO storage drivers installed, we can grow its partition without a reboot.
- Find the VM. In this case, “postiffice”.
- Find its too-small block device —
vgb
. - Make sure the hypervisor’s storage pool has enough room, then grow the storage.
In this configuration, we extend the LVM volume underlying
vgb
. - Ask libvirth to notify the guest about the change with
virsh blockresize
. - In the Windows guest, claim the new space with Disk Manager.
🐚 hypervisor ~ $ sudo virsh list
Id Name State
----------------------------------------------------
2 brak running
3 postoffice running
🐚 hypervisor ~ $ sudo virsh domblklist --details postoffice
Type Device Target Source
------------------------------------------------
block disk vda /dev/vg0/postoffice-os
block disk vdb /dev/vg0/postoffice-data
block disk vdc /dev/vg0/antarctica-mail
file cdrom hdc -
🐚 hypervisor ~ $ sudo virsh domblkinfo postoffice vdb
Capacity: 289910292480
Allocation: 0
Physical: 289910292480
🐚 hypervisor ~ $ sudo vgdisplay vg0 | grep -e Total -e Alloc -e Free
Total PE 714947
Alloc PE / Size 462855 / 1.77 TiB
Free PE / Size 252092 / 984.73 GiB
🐚 hypervisor ~ $ sudo lvextend -L+30G /dev/vg0/postoffice-data
Size of logical volume vg0/postoffice-data changed from 270.00 GiB (69120 extents) to 300.00 GiB (76800 extents).
Logical volume vg0/postoffice-data successfully resized.
🐚 hypervisor ~ $ sudo virsh domblkinfo postoffice vdb
Capacity: 289910292480
Allocation: 0
Physical: 322122547200
🐚 hypervisor ~ $ sudo virsh blockresize postoffice /dev/vg0/postoffice-data 322122547200B
Block device '/dev/vg0/postoffice-data' is resized
🐚 hypervisor ~ $ sudo virsh domblkinfo postoffice vdb
Capacity: 322122547200
Allocation: 0
Physical: 322122547200
Then, in Windows, tell Device Manager to “Scan for hardware changes”. After refreshing its view, Disk Manager shows 30 GB of unallocated space. Have Disk Manager grow the partition.
Note that virsh blockresize
take KiB as its default unit, so be sure to specify B
if using a size from virsh domblkinfo
.
#libvirt #linux #windows