How to resize a virtual disk of KVM

Posted on In QA

I test it for qcow2 format. Other formats are TBA.

qemu-img resize kvm1.qcow2 +20G
cp kvm1.qcow2 kvm1-orig.qcow2
virt-resize --expand /dev/sda1 kvm1-orig.qcow2 kvm1.qcow2

Reference: https://fatmin.com/2016/12/20/how-to-resize-a-qcow2-image-and-filesystem-with-virt-resize/

I test it for qcow2 format. Other formats are TBA.

qemu-img resize kvm1.qcow2 +20G
cp kvm1.qcow2 kvm1-orig.qcow2
virt-resize --expand /dev/sda1 kvm1-orig.qcow2 kvm1.qcow2

Reference: https://fatmin.com/2016/12/20/how-to-resize-a-qcow2-image-and-filesystem-with-virt-resize/

2 comments

  1. The right answer is:

    cp kvm1.qcow2 kvm1-orig.qcow2
    qemu-img resize kvm1.qcow2 +20G
    virt-resize –expand /dev/sda1 kvm1-orig.qcow2 kvm1.qcow2

    First copy, second resize the new image, third resize partition.

  2. How to expand a kvm .img with only one reboot:

    qemu-img resize {/smnt/virt/images/name.img} +size (k, M, G or T)
    virsh qemu-monitor-command {VM-name} info block –hmp (Capture the drive-virtio-disk number, usually 0)
    virsh qemu-monitor-command {VM-name} block_resize drive-virtio-disk# [new size k, M, G or T] –hmp
    lsblk should show the updated size of /dev/vda
    dmesg {system picks up updated size}
    delete and recreate vda3 using fdisk /dev/vda (c, u, d, 3, w) (c, u, n, p, 3, {default}, {default}, w)
    reboot VM, need to reboot the KVM to update the kernel of the new partition size. Parted will not update the kernel because the volumes are mounted, remounting without reboot will not update the kernel.
    lsblk should show updated size of partition
    resize2fs /dev/vda3

Leave a Reply

Your email address will not be published. Required fields are marked *