qemu-img Command: Tutorial & Examples

Manage virtual disk images

The qemu-img command is a versatile tool for creating, converting, and manipulating image files for virtual machines. It's part of the QEMU software package, a generic and open-source machine emulator and virtualizer. The command is particularly important in the administration of Linux servers and VMs, allowing administrators to manage disk images with ease. It can handle various formats such as raw, qcow2, VDI (VirtualBox), VMDK (VMware), and more.

Why it is important

Having the ability to work with disk image files is essential when dealing with virtual machines. These files are the virtual equivalent of a physical hard drive for your VM. Being able to create, inspect, and modify these directly gives you a great deal of flexibility and control over your VMs.

How it works

The qemu-img command interacts directly with the image files, allowing you to create new ones, convert between different formats, and even check an image for errors. The command syntax is:

qemu-img [options] command [command options]

Here, command is the specific operation you want to perform (like create, convert, check, etc.), and command options are the specific options related to that command.

How to use it

Here's a simple example of creating a new qcow2 image of 10GB:

qemu-img create -f qcow2 myImage.qcow2 10G

This command creates a new myImage.qcow2 image file in the qcow2 format with a size of 10GB.

To convert an existing raw image to a qcow2 image:

qemu-img convert -f raw -O qcow2 myImage.raw myImage.qcow2

This command converts the myImage.raw file (in raw format) to a new myImage.qcow2 file (in qcow2 format).

Common command parameters

  • -f or --format: Specifies the disk image format.
  • -O or --output-format: Specifies the output format when converting between formats.
  • -c or --compress: This option is used with the convert command to compress the output file.
  • -p or --progress: Display progress bar when applicable.

Potential problems and pitfalls

While qemu-img is a powerful tool, it also has its pitfalls. For instance, when converting between formats, it's important to understand the implications of the different formats. Some formats may have features not supported in others, so converting between them could result in data loss or a non-functional image.

Also, when using the check command, it's worth noting that not all corruption can be detected or fixed. Always have a backup of your important data.


The qemu-img command is a powerful tool for anyone working with virtual machines. It provides a wide range of capabilities for working with disk image files, from creation to conversion, to checking for errors. Understanding how to use this command effectively can make managing your virtual environment much easier.

The text above is licensed under CC BY-SA 4.0 CC BY SA