Only images in the RAW, VHD, and QCOW2 formats can be imported to Elastic Compute Service (ECS). For images in other formats, you must convert the images to the RAW, VHD, or QCOW2 format before you can import the images to ECS. This topic describes how to use the qemu-img tool to convert images from other formats to the VHD or RAW format.
Background information
The qemu-img tool supports the following image format conversions:- Convert images from the RAW, QCOW2, QCOW1, VMDK, VDI, VHD (VPC), VHDX, or QED format to the VHD format.
- Convert images between the RAW and VHD formats.
Procedure
Install the qemu-img tool on your Windows computer and convert the format of an image
On your Windows computer, you can perform the following procedure to install the qemu-img tool and use it to convert the format of an image.
- Download and install qemu-img to a specific path. In this example, C:\Program Files\qemu is used as the installation path of qemu-img.
- Configure environment variables for qemu-img. Important This section describes how to configure environment variables for qemu-img in a Windows Server 2008 R2 operating system. The operations of configuring environment variables for qemu-img may differ if your computer uses other operating system versions.
- Choose , right-click Computer, and then select Properties.
- In the left-side navigation pane, click Advanced system settings.
- In the System Properties dialog box, click the Advanced tab and then click Environment Variables.
- In the Environment Variables dialog box, find the Path variable in the System variables section and click Edit. If the Path variable does not exist, click New to create the variable.
- Create the Path variable or add a value to the available.
- In the Edit System Variable dialog box, add C:\Program Files\qemu in the Variable Value field. Use semicolons (;) to separate different values.
- In the New System Variable dialog box, enter Path in the Variable name field and enter C:\Program Files\qemu in the Variable value field.
- Check whether the environment variable is properly configured.
- Open Command Prompt in Windows.
- Run the
qemu-img --help
command.
If the command output is displayed, it indicates that the environment variable is properly configured. - In Command Prompt, run the cd <Directory of the image whose format you want to convert> command to switch to the directory where the original image is stored. Example:
cd D:\ConvertImage
. - Run the
qemu-img convert -f qcow2 -O raw centos.qcow2 centos.raw
command to convert the format of the original image.- The -f parameter is followed by the original image format.
- The -O parameter (uppercase is required) is followed by the new image format, name of the original image, and name of the new image.
After the conversion is complete, the new image is generated and appears in the directory of the original image.
Install the qemu-img tool on your Linux computer and convert the format of an image
On your Linux computer, you can perform the following procedure to install qemu-img and use it to convert the format of an image.
- Install qemu-img. For example, you can perform the following operations based on operating system types:
- For Ubuntu, run the
apt-get install qemu-utils
command to install qemu-utils.If the error messageUnable to locate package qemu-utils
is returned during the installation process, run the following commands to install the qemu-img tool:apt-get update #Update the package list. apt-get install qemu-utils #Install the qemu-img tool.
- For CentOS, run the
yum install qemu-img
command to install the qemu-img tool.If an error message is returned and does not indicate which dependency libraries are missing, you can run the
pip install -r requirements.txt
command to install all dependency libraries contained in the requirements.txt file of cloud-init.
- For Ubuntu, run the
- Run the
qemu-img convert -f qcow2 -O raw centos.qcow2 centos.raw
command to convert the format of an image.- The -f parameter is followed by the original image format.
- The -O parameter (uppercase is required) is followed by the new image format, name of the original image, and name of the new image.
After the conversion is complete, the new image is generated and appears in the directory of the original image.