Search This Blog

Sunday, June 12, 2022

Converting the Image Format Using qemu-img

You can import an image file in VHD, VMDK, QCOW2, RAW, VHDX, QCOW, VDI, QED, ZVHD, or ZVHD2 format to HUAWEI CLOUD. Image files in other formats need to be converted before being imported. The open-source tool qemu-img is provided for you to convert image file formats.

Key points

  • qemu-img supports the mutual conversion of image formats VHD, VMDK, QCOW2, RAW, VHDX, QCOW, VDI, and QED.
  • ZVHD and ZVHD2 are self-developed image file formats and cannot be identified by qemu-img. To convert image files to any of the two formats, use the qemu-img-hw tool. 
  • When you run the command to convert the format of VHD image files, use VPC to replace VHD. Otherwise, qemu-img cannot identify the image format.

I'm using Fedora35 and I've already installed the package

$ sudo dnf provides qemu-img
Last metadata expiration check: 0:53:05 ago on Sun 12 Jun 2022 09:49:21 PM CDT.
qemu-img-2:6.1.0-5.fc35.x86_64 : QEMU command line tool for manipulating disk images
Repo        : fedora
Matched from:
Provide    : qemu-img = 2:6.1.0-5.fc35

qemu-img-2:6.1.0-14.fc35.x86_64 : QEMU command line tool for manipulating disk images
Repo        : @System
Matched from:
Provide    : qemu-img = 2:6.1.0-14.fc35

qemu-img-2:6.1.0-14.fc35.x86_64 : QEMU command line tool for manipulating disk images
Repo        : updates
Matched from:
Provide    : qemu-img = 2:6.1.0-14.fc35

Checking package version.

$ qemu-img -V
qemu-img version 6.1.0 (qemu-6.1.0-14.fc35)
Copyright (c) 2003-2021 Fabrice Bellard and the QEMU Project developers

Converting the image.

$ export VMDK='wiki.vmdk'
$ export QCOW2='wiki.qcow2'
$ qemu-img convert -p -f vmdk -O qcow2 ${VMDK} ${QCOW2}
    (100.00/100%)

Getting the image information.

$ qemu-img info ${QCOW2}
image: wiki.qcow2
file format: qcow2
virtual size: 30 GiB (32212254720 bytes)
disk size: 15.8 GiB
cluster_size: 65536
Format specific information:
    compat: 1.1
    compression type: zlib
    lazy refcounts: false
    refcount bits: 16
    corrupt: false
    extended l2: false

And now enjoy, you can continue customizing the image or directing using it on QEMU.