# Full Guide to qemu-img convert: Convert, Compress, and Manage Virtual Disk Images

`qemu-img convert` is a powerful utility for converting virtual disk images between different formats, resizing them, compressing, and even copying them efficiently. Whether you work with KVM, QEMU, VirtualBox, or VMware, understanding this tool can save you time and disk space. Here’s a comprehensive guide for beginners and advanced users alike.

* * *

## **What is** `qemu-img convert`?

`qemu-img convert` is part of the `qemu-img` suite. Its main function is to convert one disk image format to another, but it can also compress, sparsify, and resize images in the process.

Common formats supported:

*   **qcow2** (QEMU/KVM native)
    
*   **raw**
    
*   **vmdk** (VMware)
    
*   **vdi** (VirtualBox)
    
*   **vhd/vhdx** (Microsoft Hyper-V)
    
*   **parallels** (Parallels Desktop)
    

* * *

## **Basic Syntax**

```bash
qemu-img convert [options] -O <output_format> <input_image> <output_image>
```

Examples:

*   Convert a raw image to qcow2:
    
    ```bash
    qemu-img convert -O qcow2 disk.raw disk.qcow2
    ```
    
*   Convert a vmdk (VMware) to qcow2:
    
    ```bash
    qemu-img convert -O qcow2 disk.vmdk disk.qcow2
    ```
    

* * *

## **Common Use Cases**

### **1\. Convert Between Formats**

*   **VMware VMDK to QCOW2 (KVM):**
    
    ```bash
    qemu-img convert -O qcow2 source.vmdk dest.qcow2
    ```
    
*   **VirtualBox VDI to RAW:**
    
    ```bash
    qemu-img convert -O raw source.vdi dest.raw
    ```
    
*   **RAW to VHDX (Hyper-V):**
    
    ```bash
    qemu-img convert -O vhdx source.raw dest.vhdx
    ```
    

### **2\. Compress Disk Images**

Use the `-c` flag to compress supported formats (like qcow2):

```bash
qemu-img convert -c -O qcow2 source.qcow2 dest.qcow2
```

### **3\. Create a Sparse Image**

If your input image is thick provisioned (all blocks allocated), you can make the output sparse (only actual data blocks allocated):

```bash
qemu-img convert -O qcow2 thick.qcow2 sparse.qcow2
```

### **4\. Resize During Conversion**

Use the `-S` (sparsify) option to ignore data blocks with only zeros, making the target image smaller:

```bash
qemu-img convert -O qcow2 -S 0 source.qcow2 dest.qcow2
```

### **5\. Convert and Encrypt Disk Images**

You can encrypt the output qcow2 image:

```bash
qemu-img convert -O qcow2 --object secret,id=sec0,data=YOURPASSWORD \
  -o encrypt.format=luks,encrypt.key-secret=sec0 source.raw dest.qcow2
```

*Replace* `YOURPASSWORD` with a strong password or use secret files as recommended by QEMU docs.

* * *

## **Advanced Examples**

### **Convert and Change Size**

You can resize images after conversion with `qemu-img resize`:

```bash
qemu-img convert -O qcow2 source.raw dest.qcow2
qemu-img resize dest.qcow2 100G
```

### **Convert Multiple Images (Snapshots)**

For images with snapshots or backing files, use `--backing-chain` to include the entire chain:

```bash
qemu-img convert -O qcow2 --backing-chain snap.qcow2 full.qcow2
```

* * *

## **Full List of Key Options**

*   `-O <fmt>`: Output format (qcow2, raw, vmdk, vdi, vhdx, etc.)
    
*   `-c`: Compress the output image (for supported formats)
    
*   `-p`: Show progress bar
    
*   `-S <size>`: Sparsify zeros (ignore zeroed blocks above this size)
    
*   `-f <fmt>`: Input format (auto-detected if omitted)
    
*   `--backing-chain`: Convert the entire snapshot/backing chain
    
*   `-o <options>`: Format-specific options (e.g., cluster\_size for qcow2, preallocation, encryption)
    
*   `-n`: Do not create the output file, just test conversion
    

* * *

## **Tips and Best Practices**

*   **Always backup your disk images before converting or overwriting!**
    
*   For best compaction, zero-fill free space inside the guest OS before converting (e.g., with `dd` or SDelete).
    
*   After conversion, use `qemu-img info <image>` to inspect the result.
    
*   When moving VMs between hypervisors, check for driver and hardware compatibility after conversion.
    

* * *

## **Troubleshooting**

*   **Error: “format not supported”**  
    Make sure you have the necessary QEMU modules/libraries for your source/target formats.
    
*   **Image won’t boot after conversion**  
    Check that your VM configuration matches the new format (bus type, drivers, etc.)
    

* * *

## **References**

*   [QEMU Documentation: qemu-img](https://wiki.qemu.org/Documentation/Tools/qemu-img)
    
*   [libvirt Disk Images](https://libvirt.org/formatdomain.html#elementsDisks)
    

* * *

## **Conclusion**

`qemu-img convert` is your Swiss Army knife for virtual disk image management—whether you’re migrating between platforms, reclaiming space, or compressing images for backups. Experiment in a safe environment and take regular backups to make the most of this essential tool!

### CONTACT:

I’m Kumar Bishojit Paul, the Founder and CEO of [BIKIRAN](https://www.bikiran.com/). If you need further assistance, please leave a comment. I’m interested in helping you.


---

## 🏢 About Bikiran

**[Bikiran](https://bikiran.com/)** is a software development and cloud infrastructure company founded in 2012, headquartered in Khulna, Bangladesh. With 15,000+ clients and over a decade of experience, Bikiran builds and operates a suite of products spanning domain services, cloud hosting, app deployment, workflow automation, and developer tools.

| SL  | Topic        | Product                                                              | Description                                             |
| --- | ------------ | -------------------------------------------------------------------- | ------------------------------------------------------- |
| 1   | Website      | [Bikiran](https://bikiran.com/)                                      | Main platform — Domain, hosting & cloud services        |
| 2   | Website      | [Edusoft](https://www.edusoft.com.bd/)                               | Education management software for institutions          |
| 3   | Website      | [n8n Clouds](https://n8nclouds.com/)                                 | Managed n8n workflow automation hosting                 |
| 4   | Website      | [Timestamp Zone](https://www.timestamp.zone/)                        | Unix timestamp converter & timezone tool                |
| 5   | Website      | [PDFpi](https://pdfpi.bikiran.com/)                                  | Online PDF processing & manipulation tool               |
| 6   | Website      | [Blog](https://blog.bikiran.com/)                                    | Technical articles, guides & tutorials                  |
| 7   | Website      | [Support](https://support.bikiran.com/)                              | 24/7 customer support portal                            |
| 8   | Website      | [Probackup](https://probackup.bikiran.com/)                          | Automated database backup for SQL, PostgreSQL & MongoDB |
| 9   | Service      | [Domain](https://www.bikiran.com/domain)                             | Domain registration, transfer & DNS management          |
| 10  | Service      | [Hosting](https://www.bikiran.com/services/hosting/web)              | Web, app & email hosting on NVMe SSD                    |
| 11  | Service      | Email & SMS                                                          | Bulk email & SMS notification service                   |
| 12  | npm          | [Chronopick](https://www.npmjs.com/package/@bikiran/chronopick)      | Date & time picker React component                      |
| 13  | npm          | [Rich Editor](https://www.npmjs.com/package/@bikiran/editor)         | WYSIWYG rich text editor for React                      |
| 14  | npm          | [Button](https://www.npmjs.com/package/@bikiran/button)              | Reusable React button component library                 |
| 15  | npm          | [Electron Boilerplate](https://www.npmjs.com/package/create-edx-app) | CLI to scaffold Electron.js project templates           |
| 16  | NuGet        | [Bkash](https://www.nuget.org/packages/Bikiran.Payment.Bkash)        | bKash payment gateway integration for .NET              |
| 17  | NuGet        | [Bikiran Engine](https://www.nuget.org/packages/Bikiran.Engine)      | Core .NET engine library for Bikiran services           |
| 18  | Open Source  | [PDFpi](https://github.com/bikirandev/pdfpi)                         | PDF processing tool — open source                       |
| 19  | Open Source  | [Bikiran Engine](https://github.com/bikirandev/Bikiran.Engine)       | Core .NET engine — open source                          |
| 20  | Open Source  | [Drive CLI](https://github.com/bikirandev/DriveCLI)                  | CLI tool to manage Google Drive from terminal           |
| 21  | Docker       | [Pgsql](https://github.com/bikirandev/docker-pgsql)                  | Docker setup for PostgreSQL                             |
| 22  | Docker       | [n8n](https://github.com/bikirandev/docker-n8n)                      | Docker setup for n8n automation                         |
| 23  | Docker       | [Pgadmin](https://github.com/bikirandev/docker-pgadmin)              | Docker setup for pgAdmin                                |
| 24  | Social Media | [LinkedIn](https://www.linkedin.com/company/bikiran12)               | Bikiran on LinkedIn                                     |
| 25  | Social Media | [Facebook](https://www.facebook.com/bikiran12)                       | Bikiran on Facebook                                     |
| 26  | Social Media | [YouTube](https://www.youtube.com/@bikiranofficial)                  | Bikiran on YouTube                                      |
| 27  | Social Media | [FB n8nClouds](https://www.facebook.com/n8nclouds)                   | n8n Clouds on Facebook                                  |
