Resize a KVM VM disk¶
Part of the KVM overview. Grow a disk from the host, then grow the partition, LVM and filesystem inside the guest.
Growing is safe; shrinking is not (do not, unless you have shrunk the filesystem and partitions first and have a backup).
Step 1: grow the image (host)¶
Offline (+ grows by an amount):
virsh shutdown vm01
qemu-img resize /var/lib/libvirt/images/vm01.qcow2 +30G
virsh start vm01
Online (a running VM). This sets the new total size, it does not add to the old size:
virsh domblklist vm01
virsh blockresize vm01 vda 50G
Confirm the guest saw it: dmesg -T | grep -E 'virtio_blk|capacity change' and lsblk.
Step 2: grow the partition (guest)¶
lsblk
sudo growpart /dev/vda 1 # package: cloud-guest-utils (Debian) / cloud-utils-growpart (RHEL)
Step 3a: no LVM, grow the filesystem¶
sudo resize2fs /dev/vda1 # ext4
sudo xfs_growfs / # xfs (takes the mount point)
Step 3b: LVM¶
The physical volume lives on a partition, so the partition must be grown first (step 2, on the partition that holds the PV, e.g. growpart /dev/vda 3). Rebooting alone will not make LVM see new disk space. Then:
sudo pvresize /dev/vda3
sudo lvextend -r -l +100%FREE /dev/mapper/ubuntu--vg-ubuntu--lv # -r also grows the filesystem
Without -r, run resize2fs / xfs_growfs on the logical volume afterwards.
References: How-To Geek, sandilands.info (LVM)
Windows guests¶
Shut down, qemu-img resize disk.qcow2 +10G, start, then Disk Management → right-click the volume → Extend Volume.