Help Center/ Image Management Service/ Best Practices/ Converting the Image Format/ Converting the Image Format Using qemu-img-hw
Updated on 2024-11-07 GMT+08:00

Converting the Image Format Using qemu-img-hw

Scenarios

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 into any of these formats using the open-source tool qemu-img before being imported. However, the qemu-img tool cannot convert image files to the ZVHD or ZVHD2 format. To convert image files to any of the two formats, use the self-developed tool qemu-img-hw. This section describes how to use qemu-img-hw to convert an image file to ZVHD2.

Tool and Costs

Table 1 Tool and costs

Tool

Description

Costs

qemu-img-hw

qemu-img-hw is developed by Huawei and is used for converting image formats.

You can obtain it from:

https://cn-south-1-cloud-reset-pwd.obs.cn-south-1.myhuaweicloud.com/imageImportTools/qemu-img-hw.zip

Free

Constraints

qemu-img-hw can be used only in Linux. You can run it on a local Linux server or a Linux ECS on the cloud platform. The following procedure uses an EulerOS ECS as an example.

Procedure

  1. Upload the image file to be converted to the ECS.
    • If the local host runs a Linux OS, run the scp command.

      For example, to upload image01.qcow2 to the /usr/ directory of the ECS, run the following command:

      scp /var/image01.qcow2 root@xxx.xxx.xx.xxx:/usr/

      xxx.xxx.xx.xxx indicates the EIP bound to the ECS.

    • If the local host runs a Windows OS, use a file transfer tool, such as WinSCP, to upload the image file to the ECS.
  2. Obtain the qemu-img-hw software package, upload it to the ECS, and then decompress the package.
    Table 2 qemu-img-hw package

    Tool Package

    How to Obtain

    qemu-img-hw.zip

    https://cn-south-1-cloud-reset-pwd.obs.cn-south-1.myhuaweicloud.com/imageImportTools/qemu-img-hw.zip

    This tool can be used only on x86 servers.

  3. Convert the image format.
    1. Go to the directory where qemu-img-hw is stored, for example, /usr/qemu-img-hw.

      cd /usr/qemu-img-hw

    2. Run the following command to change file permissions:

      chmod +x qemu-img-hw

    3. Run the qemu-img-hw command to convert the image file to the ZVHD2 format.

      The command format of qemu-img-hw is as follows:

      ./qemu-img-hw convert -p -O Target_image_format Source_image_file Target_image_file

      For example, run the following command to convert an image01.qcow2 file to an image01.zvhd2 file:

      ./qemu-img-hw convert -p -O zvhd2 image01.qcow2 image01.zvhd2

Appendix 1: Common qemu-img-hw Commands

  • Converting image file formats: qemu-img-hw convert -p -O Target_image_format Source_image__file Target_image_file

    The parameters are described as follows:

    -p: indicates the conversion progress.

    The part following -O (which must be in upper case) consists of the target image format, source image file, and target image file.

    For example, run the following command to convert a QCOW2 image file to a ZVHD2 file:

    qemu-img-hw convert -p -O zvhd2 test.qcow2 test.zvhd2

  • Querying image file information: qemu-img-hw info Image file

    An example command is qemu-img-hw info test.zvhd2.

  • Viewing help information: qemu-img-hw –help

Appendix 2: Common qemu-img-hw Errors

  • Symptom:
    The following information is displayed when you run the qemu-img-hw command:
    ./qemu-img-hw: /lib64/libc.so.6: version `GLIBC_2.14' not found (required by ./qemu-img-hw)

    Solution:

    Run the strings /lib64/libc.so.6 | grep glibc command to check the glibc version. If the version is too early, install the latest version. Run the following commands in sequence:

    wget http://ftp.gnu.org/gnu/glibc/glibc-2.15.tar.gz

    wget http://ftp.gnu.org/gnu/glibc/glibc-ports-2.15.tar.gz

    tar -xvf glibc-2.15.tar.gz

    tar -xvf glibc-ports-2.15.tar.gz

    mv glibc-ports-2.15 glibc-2.15/ports

    mkdir glibc-build-2.15

    cd glibc-build-2.15

    ../glibc-2.15/configure --prefix=/usr --disable-profile --enable-add-ons --with-headers=/usr/include --with-binutils=/usr/bin

    If configure: error: no acceptable C compiler found in $PATH is displayed, run the yum -y install gcc command.

    make

    make install

  • Symptom:

    The following information is displayed when you run the qemu-img-hw command:

    ./qemu-img-hw: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory

    Solution: Run the yum install libaio command.

  • Symptom:

    The following information is displayed when you run the qemu-img-hw command:

    ./qemu-img-hu: error while loading shared libraries: libcrypto.so.10: cannot open shared object file: No such file or directory

    Solution: Run openssl version to check whether the OpenSSL version is later than 1.0. If yes, install OpenSSL 1.0.

    Run the following commands to install OpenSSL 1.0:

    wget https://github.com/openssl/openssl/releases/download/OpenSSL_1_0_2k/openssl-1.0.2k.tar.gz

    tar -xvf openssl-1.0.2k.tar.gz

    cd openssl-1.0.2k

    ./config -d shared --prefix=/tmp/openssl (custom installation directory)

    make

    make install

    cp /tmp/openssl/lib/libcrypto.so.1.0.0 /usr/lib64/libcrypto.so.10

    Delete the /usr/lib64/libcrypto.so.10 file if you do not need it any longer.

Follow-up Procedure

After the image file format is converted, you can use obsutil to upload the image file to an OBS bucket for creating a private image. For details about how to use obsutil to upload an image file, see Uploading an Object.