qemu-img is the command-line utility shipped with QEMU for creating, converting, inspecting, resizing, checking and snapshotting virtual disk images while they are offline. In Linux virtualization, it is the standard tool for preparing the storage that KVM guests use, whether those guests are started directly with QEMU, managed through libvirt and virsh, or run on platforms such as Proxmox VE and oVirt.
The tool understands the block layer of QEMU, so it reads and writes every image format that QEMU itself supports. That makes qemu-img the common translator between hypervisors: it can turn a VMware VMDK or a Hyper-V VHDX into qcow2 or raw in a single command, and it exposes format features such as backing chains, compression and encryption that ordinary file tools cannot see.
How qemu-img works with disk image formats
qemu-img works by opening an image through QEMU block drivers, which translate a guest-visible sequence of sectors into the layout of a specific file format. A raw image stores sectors one-to-one, while qcow2 keeps a two-level lookup table that maps guest clusters to host file offsets and allocates space only when data is written.
Because the same drivers serve running virtual machines, qemu-img commands interpret metadata exactly as QEMU will. The utility also honors image locking: by default it refuses to open an image for writing while a running guest holds it, which prevents the metadata corruption that concurrent writers cause. The table below compares the formats administrators encounter most often.
| Format | Origin | Main features | Typical use |
|---|---|---|---|
| raw | Generic | No metadata, sparse if the filesystem allows | Maximum speed, LVM or Ceph volumes |
| qcow2 | QEMU | Thin provisioning, snapshots, backing files, compression | Default for KVM and libvirt |
| vmdk | VMware | Monolithic or split extents | Import from or export to VMware |
| vhdx | Microsoft Hyper-V | Large disks, log-protected metadata | Exchange with Hyper-V and Azure |
| vpc | Microsoft Virtual PC | Legacy VHD layout | Older Azure and Virtual PC images |
| vdi | VirtualBox | Dynamic or fixed allocation | Migration from VirtualBox |
| luks | Linux disk encryption | LUKS header around raw data | Encrypted standalone images |
Core qemu-img subcommands
qemu-img is organized around subcommands, each of which performs one operation on one or more images. The first argument names the subcommand, followed by options such as -f for the input format and -O for the output format.
| Subcommand | Purpose | Example |
|---|---|---|
| create | Makes a new empty or overlay image | qemu-img create -f qcow2 vm.qcow2 40G |
| info | Shows format, virtual size, disk usage and backing chain | qemu-img info --backing-chain vm.qcow2 |
| convert | Copies an image into another format or file | qemu-img convert -p -O qcow2 in.vmdk out.qcow2 |
| check | Verifies qcow2 metadata and can repair leaks | qemu-img check -r leaks vm.qcow2 |
| resize | Changes the virtual disk size | qemu-img resize vm.qcow2 +20G |
| snapshot | Lists, creates, applies or deletes internal snapshots | qemu-img snapshot -l vm.qcow2 |
| commit | Merges an overlay into its backing file | qemu-img commit overlay.qcow2 |
| rebase | Changes the backing file of an overlay | qemu-img rebase -b new.qcow2 -F qcow2 top.qcow2 |
| measure | Calculates the space a conversion will need | qemu-img measure -O qcow2 in.raw |
| compare | Checks whether two images have identical content | qemu-img compare a.qcow2 b.raw |
Two lesser-known subcommands help with diagnosis. qemu-img map prints which guest ranges are allocated, zero or backed by a lower layer, and qemu-img bench measures raw I/O throughput of an image to separate storage problems from guest problems.
Backing files, overlays and snapshots
A backing file lets one qcow2 image record only the differences from a read-only base image, which is the foundation of copy-on-write cloning. Creating an overlay with qemu-img create -f qcow2 -b base.qcow2 -F qcow2 vm1.qcow2 produces a nearly empty file that reads unchanged clusters from the base and stores new writes locally.
Recent QEMU releases require the backing format through -F, because probing an unknown backing file is a security risk: a malicious raw image could contain a qcow2 header that points at arbitrary host files. Internal snapshots, by contrast, live inside a single qcow2 file and are managed with qemu-img snapshot, which is convenient for quick rollback but makes the file grow and cannot be used safely while the guest runs.
| Approach | Where data lives | Strength | Weakness |
|---|---|---|---|
| Internal snapshot | Inside one qcow2 file | Single file to manage | Offline only with qemu-img, slower to delete |
| External overlay | Separate qcow2 per layer | Fast creation, shareable base | Chains must be tracked and merged |
| Storage-level snapshot | LVM, ZFS or Ceph | Independent of image format | Requires a capable storage backend |
Performance and allocation options
The -o creation options control how qcow2 allocates space, and they have a measurable effect on guest I/O. The default cluster size of 64 KiB balances metadata size against allocation granularity; larger clusters reduce lookup overhead for big sequential workloads, while smaller clusters waste less space with many small writes.
| Setting | Values | Effect |
|---|---|---|
| preallocation | off, metadata, falloc, full | Trades initial disk usage for fewer allocation stalls |
| cluster_size | 512 B to 2 MiB | Changes metadata overhead and space granularity |
| lazy_refcounts | on or off | Faster writes, but requires repair after a crash |
| compression_type | zlib or zstd | Applies to clusters written with convert -c |
| extended_l2 | on or off | Enables subclusters to reduce copy-on-write cost |
For conversions, -p shows progress, -m sets the number of parallel coroutines and -W allows out-of-order writes, which can shorten large copies considerably on fast storage. By default convert also detects zeroed regions and leaves them unallocated in the target, so a 100 GB guest with 15 GB of data usually produces a file close to 15 GB.
Common mistakes and safe practice
The most damaging qemu-img mistake is modifying an image that a running guest is using. Image locking blocks most such attempts, but forcing access or working on copies outside QEMU can still corrupt qcow2 metadata beyond repair.
- Shrinking without care:
resize --shrinkcuts data at the end of the disk, so the guest filesystem and partition must be reduced first. - Growing without guest steps: enlarging the image does not enlarge the partition or filesystem inside it; tools such as growpart and resize2fs are still needed.
- Committing into a shared base:
commitwrites changes into the backing file and silently alters every other overlay that depends on it. - Reading a live image without `-U`:
qemu-img infoon an attached disk needs--force-share, and the reported values may be slightly out of date. - Skipping `check` after a host crash: qcow2 images with lazy refcounts or interrupted writes should be verified before the guest starts again.
A non-technical view
A virtual machine keeps its whole hard drive inside one big file. qemu-img is the toolbox for those drive files. It can make a new empty drive, tell you how large a drive is and how much space it really uses, copy it into a format another program understands, or make it bigger.
It works a bit like a converter for document formats, except the documents are entire computers. The key point is simple: use it while the virtual machine is switched off, and the drive files stay healthy.
A concrete example
A small company is moving twelve virtual servers from VMware to a Linux host running KVM and libvirt. For each server, the administrator exports the VMDK disk, runs qemu-img measure to confirm the target volume has enough room, and then converts it with qemu-img convert -p -m 8 -O qcow2 server.vmdk server.qcow2.
The largest server has a 200 GB virtual disk with about 38 GB of real data. Because empty regions stay unallocated, the resulting qcow2 file occupies roughly 39 GB, and the conversion finishes in under ten minutes on solid-state storage. After qemu-img check reports no errors, the administrator defines the guest with virt-install, switches its disk bus to Virtio and boots it. All twelve servers are migrated over one weekend without buying conversion software.