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 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.
Background
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
- 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 on 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.
- If the local host runs a Linux OS, run the scp command.
- Obtain the qemu-img-hw software package, upload it to the ECS, and then decompress the package.
Table 1 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
- Convert the image format.
- Go to the directory where qemu-img-hw is stored, for example, /usr/qemu-img-hw.
cd /usr/qemu-img-hw
- Run the following command to change file permissions:
- 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
- Go to the directory where qemu-img-hw is stored, for example, /usr/qemu-img-hw.
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 Errors During qemu-img-hw Running
- 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.
Last Article: Converting the Image Format Using qemu-img
Next Article: Creating a Private Image Using Packer
Did this article solve your problem?
Thank you for your score!Your feedback would help us improve the website.