All Products
Search
Document Center

Elastic Compute Service:Step 3: (Optional) Convert the format of an image

Last Updated:Jan 30, 2024

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.
Note The qemu-img tool cannot convert images from the ISO format to the VHD or RAW format. To convert an image from the ISO format to the VHD or RAW format, install the image to VHD or RAW media and then create an image in the VHD or RAW format. For more information, see Create a Linux virtual machine and install an operating system or Create a Windows virtual machine and install an operating system.

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.

  1. 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.
  2. 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.
    1. Choose Start > Computer, right-click Computer, and then select Properties.
    2. In the left-side navigation pane, click Advanced system settings.
    3. In the System Properties dialog box, click the Advanced tab and then click Environment Variables.
    4. 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.
    5. 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.
  3. Check whether the environment variable is properly configured.
    1. Open Command Prompt in Windows.
    2. Run the qemu-img --help command.
    If the command output is displayed, it indicates that the environment variable is properly configured.
  4. 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.
  5. 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.

  1. 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 message Unable 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.

  2. 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.

What to do next

Step 4: Import the image to Alibaba Cloud ECS