Elastic Compute Service (ECS) supports importing images only in RAW, QCOW2, VMDK, and VHD formats. If your image is in another format, use the qemu-img tool to convert it before importing it.
Usage note
You can convert images between RAW, QCOW2, QCOW1, VMDK, VDI, VHD, VHDX, and QED formats.
Procedure
Windows
This topic uses Windows Server 2022 as an example.
Install the conversion tool.
Download the qemu-img tool and install it to
C:\Program Files\qemu.Configure environment variables.
Add the
qemuexecutable's file path to thePATHenvironment variable. This allows you to run the tool from any command-line interface.Right-click the
icon and select System.In the left-side navigation pane, search for and open View advanced system settings.
In the System Properties window, on the Advanced tab, click Environment Variables....
In the System variables section, find the Path variable.
If the variable exists: Select it and click Edit.... In the Edit environment variable window, click New and add
C:\Program Files\qemu.

If the variable does not exist: Click New.... Set Variable name to
Pathand Variable value toC:\Program Files\qemu.
Test the environment variable configuration.
Right-click the
icon, select Run, and enter PowerShell.In the
PowerShellwindow, run theqemu-img --version. If the output shows the tool's version, the environment variable is configured correctly.
Convert the image format.
Run the conversion command.
qemu-img convert [Options] <Full path of the source image> <Full path of the destination image>[OPTIONS]include:-f <source_format>: Specifies the format of the source image, such asvhdx,vdi,qed,qcow, orvpc(for VHD).You can view the supported source formats in the
Supported image formatsfield of the output from theqemu-img --helpcommand.-O <destination_format>: (Uppercase O) Specifies the format of the target image, such asraw,qcow2,vpc(for VHD), orvmdk.-p: Displays the conversion progress as a percentage.
Command examples:
# Scenario 1: Convert an image from VHD to RAW. The full path of the source image is D:\convertimage\source.vhd, and the full path of the destination image is D:\convertimage\target.raw. qemu-img convert -p -f vpc -O raw D:\convertimage\source.vhd D:\convertimage\target.raw # Scenario 2: Convert an image from VHDX to QCOW2. The full path of the source image is D:\convertimage\source.vhdx, and the full path of the destination image is D:\convertimage\target.qcow2. qemu-img convert -p -f vhdx -O qcow2 D:\convertimage\source.vhdx D:\convertimage\target.qcow2Verify the conversion.
qemu-img info <Full path of the destination image>For example, if the full path to the target image is
D:\convertimage\target.raw, runqemu-img info D:\convertimage\target.raw.The conversion is successful if the
file formatin the output matches your target format.
Use the ossutil
cpcommand to upload the destination image file to Object Storage Service (OSS) for later import.The OSS console does not support uploading files larger than 5 GB. Use ossutil for larger files.
MacOS
Install the conversion tool.
brew install qemuIf you receive a
command not founderror, run/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"and follow the prompts to install the Homebrew package manager. Then, runbrew install qemuto install the tool.Convert the image format.
Run the conversion command.
qemu-img convert [Options] <Full path of the source image> <Full path of the destination image>[OPTIONS]include:-f <source_format>: Specifies the format of the source image, such asvhdx,vdi,qed,qcow, orvpc(for VHD).You can view the supported source formats in the
Supported image formatsfield of the output from theqemu-img --helpcommand.-O <destination_format>: (Uppercase O) Specifies the format of the target image, such asraw,qcow2,vpc(for VHD), orvmdk.-p: Displays the conversion progress as a percentage.
Command examples:
# Scenario 1: Convert an image from VHD to RAW. The full path of the source image is /ConvertImage/source.vhd, and the full path of the destination image is /ConvertImage/target.raw. qemu-img convert -p -f vpc -O raw /ConvertImage/source.vhd /ConvertImage/target.raw # Scenario 2: Convert an image from VHDX to QCOW2. The full path of the source image is /ConvertImage/source.vhdx, and the full path of the destination image is /ConvertImage/target.qcow2. qemu-img convert -p -f vhdx -O qcow2 /ConvertImage/source.vhdx /ConvertImage/target.qcow2Verify the conversion.
qemu-img info <Full path of the destination image>For example, if the full path to the target image is
/ConvertImage/target.raw, runqemu-img info /ConvertImage/target.raw.The conversion is successful if the
file formatin the output matches your target format.
Use the
cpcommand of ossutil 2.0 to upload the target image file to OSS so you can import it later.The OSS console does not support uploading files larger than 5 GB. Use ossutil for larger files.
Linux
Install the conversion tool.
For Alibaba Cloud Linux and CentOS:
sudo yum install -y qemu-imgFor Ubuntu and Debian:
sudo apt-get update sudo apt-get install -y qemu-utils
Convert the image format.
Run the conversion command.
sudo qemu-img convert [Options] <Full path of the source image> <Full path of the destination image>[OPTIONS]include:-f <source_format>: Specifies the format of the source image, such asvhdx,vdi,qed,qcow, orvpc(for VHD).To view the supported source formats, run
sudo qemu-img --help | grep "Supported formats".-O <destination_format>: (Uppercase O) Specifies the format of the target image, such asraw,qcow2,vpc(for VHD), orvmdk.-p: Displays the conversion progress as a percentage.
Command examples:
# Scenario 1: Convert an image from VHD to RAW. Source: /ConvertImage/source.vhd. Target: /ConvertImage/target.raw. sudo qemu-img convert -p -f vpc -O raw /ConvertImage/source.vhd /ConvertImage/target.raw # Scenario 2: Convert an image from VHDX to QCOW2. Source: /ConvertImage/source.vhdx. Target: /ConvertImage/target.qcow2. sudo qemu-img convert -p -f vhdx -O qcow2 /ConvertImage/source.vhdx /ConvertImage/target.qcow2Verify the conversion.
sudo qemu-img info <Full path of the destination image>For example, if the full path to the target image is
/ConvertImage/target.raw, runqemu-img info /ConvertImage/target.raw.The conversion is successful if the
file formatin the output matches your target format.
Use the
cpcommand of ossutil 2.0 to upload the target image file to OSS so you can import it later.The OSS console does not support uploading files larger than 5 GB. Use ossutil for larger files.
FAQ
How can I convert an ISO image to a supported format (RAW, VHD, QCOW2, or VMDK)?
The
qemu-imgtool does not directly support converting ISO images to RAW, VHD, QCOW2, or VMDK formats. You must first use a virtualization tool such as VirtualBox to create a virtual machine and install an operating system, and then export the virtual machine to a supported format. For detailed instructions, see Create a virtual machine and install an operating system (Linux) or Create a virtual machine and install an operating system (Windows).What do I do if I get an "Unknown driver 'vhd'" error when converting an image to the VHD format?
In
qemu-img, the format identifier for VHD isvpc, notvhd. Usevpcas the format identifier.For example, to convert an image from VHDX to VHD format, run
qemu-img convert -f vhdx -O vpc source.vhdx target.vhd.
References
For more information about the
qemu-imgtool, see the QEMU official website.The
qemu-imgtool does not support the Open Virtualization Appliance (OVA) or Open Virtualization Format (OVF) formats. The Distributed Management Task Force (DMTF) maintains these formats. For more information, see the DMTF official website.