qemu-img Command
Advanced Virtualization man(1)Create and manage virtual machine disk images
š
Updated: Mar 16, 2026
SYNTAX
qemu-img COMMAND [OPTIONS]
What Does qemu-img Do?
The qemu-img command creates, converts, and modifies virtual machine disk images. It supports numerous image formats including qcow2 (QEMU native, with snapshots and compression), raw (maximum performance), VMDK (VMware), VHD/VHDX (Hyper-V), and VDI (VirtualBox).
qemu-img is essential for KVM/QEMU virtualization workflows. It creates new disk images for VMs, converts between hypervisor formats (migrating VMs between KVM, VMware, and Hyper-V), resizes disk images, creates backing files for thin provisioning, and inspects image metadata.
The qcow2 format is the recommended format for KVM, offering thin provisioning (disk grows as data is written), built-in snapshot support, optional compression (zlib/zstd), encryption (LUKS), and backing file chains for efficient cloning. qemu-img manages all these qcow2 features.
qemu-img is essential for KVM/QEMU virtualization workflows. It creates new disk images for VMs, converts between hypervisor formats (migrating VMs between KVM, VMware, and Hyper-V), resizes disk images, creates backing files for thin provisioning, and inspects image metadata.
The qcow2 format is the recommended format for KVM, offering thin provisioning (disk grows as data is written), built-in snapshot support, optional compression (zlib/zstd), encryption (LUKS), and backing file chains for efficient cloning. qemu-img manages all these qcow2 features.
Options & Flags
| Option | Description | Example |
|---|---|---|
| create | Create a new disk image | qemu-img create -f qcow2 disk.qcow2 50G |
| convert | Convert between image formats | qemu-img convert -f vmdk -O qcow2 disk.vmdk disk.qcow2 |
| resize | Resize a disk image | qemu-img resize disk.qcow2 +20G |
| info | Show image metadata and size info | qemu-img info disk.qcow2 |
| snapshot | Manage internal snapshots | qemu-img snapshot -c snap1 disk.qcow2 |
| check | Check image for errors | qemu-img check disk.qcow2 |
| compare | Compare two disk images | qemu-img compare disk1.qcow2 disk2.qcow2 |
| -f FORMAT | Source image format (raw, qcow2, vmdk, vhd) | qemu-img info -f qcow2 disk.qcow2 |
| -O FORMAT | Output format for conversion | qemu-img convert -O raw disk.qcow2 disk.raw |
| -o OPTIONS | Format-specific options | qemu-img create -f qcow2 -o compression_type=zstd disk.qcow2 100G |
Practical Examples
#1 Create a qcow2 disk image
Create a 50GB qcow2 image. Thin-provisioned ā actual file size starts near zero and grows with usage.
$ qemu-img create -f qcow2 /var/lib/libvirt/images/vm-disk.qcow2 50G
Output:
Formatting 'vm-disk.qcow2', fmt=qcow2 cluster_size=65536 extended_l2=off compression_type=zlib size=53687091200
#2 Check image info
Show format, virtual size, actual disk usage, cluster size, and snapshot info.
$ qemu-img info /var/lib/libvirt/images/vm-disk.qcow2
Output:
image: vm-disk.qcow2\nfile format: qcow2\nvirtual size: 50 GiB\ndisk size: 2.1 GiB
#3 Convert VMware to KVM
Convert a VMware VMDK image to qcow2 for KVM. -p shows progress during conversion.
$ qemu-img convert -f vmdk -O qcow2 -p vmware-disk.vmdk kvm-disk.qcow2#4 Convert KVM to Hyper-V
Convert a qcow2 image to VHDX format for Microsoft Hyper-V.
$ qemu-img convert -f qcow2 -O vhdx kvm-disk.qcow2 hyperv-disk.vhdx#5 Resize a disk image
Add 20GB to the virtual disk. Guest OS needs to extend the partition: growpart + resize2fs (or xfs_growfs).
$ qemu-img resize /var/lib/libvirt/images/vm-disk.qcow2 +20G
Output:
Image resized.
#6 Create with backing file (COW clone)
Create a copy-on-write clone using a backing file. Only differences are stored ā instant cloning, minimal disk usage.
$ qemu-img create -f qcow2 -b /var/lib/libvirt/images/base-ubuntu.qcow2 -F qcow2 clone.qcow2#7 Check image for errors
Check and repair image consistency. -r all attempts to repair any found errors.
$ qemu-img check -r all /var/lib/libvirt/images/vm-disk.qcow2#8 Compress an image
Rewrite and compress a qcow2 image. Reduces file size for archival or transfer.
$ qemu-img convert -f qcow2 -O qcow2 -c disk.qcow2 disk-compressed.qcow2Tips & Best Practices
Always use qcow2 for KVM: qcow2 supports thin provisioning, snapshots, compression, and encryption. Use raw only when maximum I/O performance is critical and you do not need these features.
Stop VM before resize: Always shut down the VM before resizing its disk image. Online resize is possible but riskier. After resizing, boot the VM and extend the guest filesystem.
Thin provisioning: qcow2 images are thin-provisioned: a 50GB image may only use 2GB on disk. Use qemu-img info to see actual vs virtual size.
Backing files for dev environments: Create one base image, then use backing files for clones. Each VM only stores its differences ā perfect for creating many test VMs from a single template.
Frequently Asked Questions
How do I create a virtual disk for KVM?
qemu-img create -f qcow2 /var/lib/libvirt/images/disk.qcow2 50G. Then attach it to a VM with virsh attach-disk or in the VM XML definition.
How do I convert a VMDK to qcow2?
qemu-img convert -f vmdk -O qcow2 -p input.vmdk output.qcow2. The -p flag shows conversion progress. Works for any format combination.
What is the difference between qcow2 and raw formats?
qcow2: thin provisioning, snapshots, compression, encryption, smaller files. raw: maximum performance, no features, full allocated size. Use qcow2 unless you need raw performance.
How do I shrink a qcow2 image?
Inside the VM: fstrim -a (for TRIM support) or dd zeros. Then: qemu-img convert -O qcow2 old.qcow2 new.qcow2. The new file will be smaller as zeroed blocks are omitted.
Related Commands
More Virtualization Commands
Master Linux with Professional eBooks
Curated IT eBooks covering Linux, DevOps, Cloud, and more
Browse Books ā