When using VMs, we often run into situations that requires expanding the disk size. This post summarizes steps to resize a disk attached to
libvirt managed VM.
On Host Machine:
- Shutdown virtual machine
virsh shutdown guest-vm
- Resize virtual disk
sudo qemu-img resize /site/vm/guest-disk.qcow2 +10G
- Restart VM and update
virsh start guest-vm
Inside Virtual Machine:
In some cases, within the VM, filesystem needs to be updated to take advantage of the expanded disk space. For disk type=’volume’, VM filesystem seems to grow automatically.
Btrfs based filesystem, follow the following commands:
sudo fdisk /dev/vda # remove old partition, add new partition.
sudo btrfs filesystem resize +10g /
On LVM managed filesystem,
sudo growpart /dev/vda3
sudo pvresize /dev/vda3
sudo lvextend -r -l +100%FREE /dev/ubuntu-vg/ubuntu-lv
To validate the filesystem is successfully resized: