How to Create and Convert Disks with qemu-img in Linux

The qemu-img command-line utility is a foundational component of the Linux virtualization stack, primarily used to create, convert, inspect, and modify virtual machine disk images offline. Supporting an extensive variety of formats—such as QCOW2, RAW, VMDK, VDI, and VHDX—it bridges the gap between different hypervisors and storage architectures. This utility enables administrators to provision new storage, adapt foreign disks for native Linux KVM/QEMU environments, resize virtual storage, and inspect image metadata without running a virtual machine.

What is qemu-img?

qemu-img is a standalone storage management tool distributed as part of the QEMU package. In modern Linux hypervisors like KVM, Proxmox VE, and OpenStack, it handles the underlying storage primitives. Because it operates directly on disk files without mounting or booting them, it provides a safe, scriptable, and resource-efficient method for managing storage backends.

Creating Virtual Disk Images

One of the primary roles of qemu-img is provisioning clean, unformatted virtual drives for new virtual machines. The utility supports several formats, most notably:

To create an empty 20 GB disk image using the QCOW2 format, run:

qemu-img create -f qcow2 /var/lib/libvirt/images/disk.qcow2 20G

Preallocation policies can also be defined during creation (such as metadata or falloc) to balance allocation speed and runtime performance.

Converting Between Disk Formats

The conversion capability of qemu-img is vital for multi-hypervisor environments and cloud migrations. It allows administrators to import VMware (VMDK), VirtualBox (VDI), or Hyper-V (VHD/VHDX) disks into a KVM environment, or export KVM disks to other platforms.

The basic syntax defines the source format (-f), output format (-O), source file, and destination file:

qemu-img convert -f vmdk -O qcow2 source.vmdk target.qcow2

During conversion, qemu-img can also compress the output image to reduce network transfer times and storage consumption using the -c flag:

qemu-img convert -c -O qcow2 source.raw compressed_target.qcow2

The tool automatically strips out contiguous blocks of zeroes, functioning as an offline disk defragmenter and sparsifier during the conversion process.

Inspecting and Modifying Images

Beyond creation and conversion, qemu-img provides crucial maintenance capabilities:

Through these combined roles, qemu-img functions as the standard storage engine for virtual machine lifecycle management across enterprise Linux infrastructures.