# How to Resize KVM Virtual Machine disk size
Only images in raw format can be resized in both directions, whereas qcow2 images can be grown but cannot be shrunk.
- Confirm the original disk information.
~]# virsh dumpxml vm2 | sed -n '/disk type/,/\/disk/p' | |
<disk type='file' device='disk'> | |
<driver name='qemu' type='qcow2'/> | |
<source file='/var/lib/libvirt/images/vm2.qcow2'/> | |
<backingStore/> | |
<target dev='vda' bus='virtio'/> | |
<alias name='virtio-disk0'/> | |
<address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/> | |
</disk> | |
~]# virsh domblklist vm2 | |
Target Source | |
------------------------------------------------ | |
vda /var/lib/libvirt/images/vm2.qcow2 | |
~]# qemu-img info /var/lib/libvirt/images/vm2.qcow2 | |
image: /var/lib/libvirt/images/vm2.qcow2 | |
file format: qcow2 | |
virtual size: 10G (10737418240 bytes) | |
disk size: 1.6G | |
cluster_size: 65536 | |
Format specific information: | |
compat: 1.1 | |
lazy refcounts: true |
- Resize the disk.
a) Method 1: Using virsh blockresize (Recommended)
~]# virsh blockresize vm2 vda 15G | |
Block device 'vda' is resized |
b) Method 2: Using qemu-img
~]# qemu-img resize /var/lib/libvirt/images/vm2.qcow2 +1G | |
ERROR cluster 163874 refcount=0 reference=1 | |
Rebuilding refcount structure | |
Repairing cluster 1 refcount=1 reference=0 | |
Repairing cluster 2 refcount=1 reference=0 | |
Repairing cluster 32776 refcount=1 reference=0 | |
Repairing cluster 65549 refcount=1 reference=0 | |
Repairing cluster 98322 refcount=1 reference=0 | |
Repairing cluster 131095 refcount=1 reference=0 | |
Repairing cluster 163868 refcount=1 reference=0 | |
Image resized. | |
~]# virsh qemu-monitor-command vm2 --hmp "info block" | |
drive-virtio-disk0: removable=0 io-status=ok file=/var/lib/libvirt/images/vm2.qcow2 ro=0 drv=qcow2 encrypted=0 bps=0 bps_rd=0 bps_wr=0 iops=0 iops_rd=0 iops_wr=0 | |
~]# virsh qemu-monitor-command vm2 --hmp "block_resize drive-virtio-disk0 16G" |
- Expand filesystem in guest OS.
・ How to Extend Standard Partition on Linux
・ How to Extend LVM Logical Volume on Linux
# Reference
・ How to resize qcow2 image?
・ Re-sizing the Disk Image