ECS supports importing images in RAW, QCOW2, VMDK, and VHD formats. To import an image in a different format, you must first convert it by using the qemu-img tool.
Scope
You can convert images between RAW, QCOW2, QCOW1, VMDK, VDI, VHD, VHDX, and QED formats.
Procedure
Windows
The following example uses Windows Server 2022.
Install the conversion tool.
Download the qemu-img tool and install it to
C:\Program Files\qemu.Configure environment variables.
Add the
qemuexecutable path to thePATHenvironment variable. This lets you run the tool from any command-line interface.Right-click the
icon and select System.Find and click View advanced system settings.
In the System Properties window, on the Advanced tab, click Environment Variables....
In the System variables section, find and select the Path variable.
If it exists: Select it and click Edit. On the Edit environment variable page, click New, and then add
C:\Program Files\qemu.If the Path variable does not exist: Click New. In the Variable name field, enter
Path. In the Variable value field, enterC:\Program Files\qemu.
Verify that the environment variable is configured correctly.
Right-click the
icon, select Run, and then enter PowerShell.In the
PowerShellwindow, run theqemu-img --versioncommand. If the command returns version information, the environment variable is configured correctly.
Convert the image format.
Convert the image file format.
qemu-img convert [options] <source_image_path> <destination_image_path>Description of
[options]:-f <source_format>: Specifies the format of the source image, such asvhdx,vdi,qed,qcow, orvpc(for VHD).To view all supported source formats, run the
qemu-img --helpcommand and find theSupported formatslist in the output.-O <destination_format>: (Uppercase O) Specifies the format of the destination image, such asraw,qcow2,vpc(for VHD), or VMDK.-p: Displays the conversion progress as a percentage.
Examples:
# Scenario 1: Convert an image from VHD to RAW format. The path of the source image is D:\convertimage\source.vhd, and the 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 format. The path of the source image is D:\convertimage\source.vhdx, and the 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 <destination_image_path>For example, if the path of the destination image is
D:\convertimage\target.raw, run the commandqemu-img info D:\convertimage\target.raw.The conversion is successful if the
file formatin the output matches the destination format.
Use the
cpcommand of ossutil 2.0 to upload the destination image file to OSS for import.The OSS console does not support files larger than 5 GB. Use ossutil to upload larger files.
macOS
Install the conversion tool.
brew install qemuIf you receive a
command not founderror, you may need to install the Homebrew package manager first. Run/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)", follow the prompts to complete the installation, and then run the command to install theqemutool again.Convert the image format.
Convert the image file format.
qemu-img convert [options] <source_image_path> <destination_image_path>[Options]Description:-f <source_format>: Specifies the format of the source image, such asvhdx,vdi,qed,qcow, orvpc(for VHD).To view all supported source formats, run the
qemu-img --helpcommand and find theSupported formatslist in the output.-O <destination_format>: (Uppercase O) Specifies the format of the destination image, such asraw,qcow2,vpc(for VHD), or VMDK.-p: Displays the conversion progress as a percentage.
Examples:
# Scenario 1: Convert an image from VHD to RAW format. The path of the source image is /ConvertImage/source.vhd, and the 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 format. The path of the source image is /ConvertImage/source.vhdx, and the 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 <destination_image_path>For example, if the path of the destination image is
/ConvertImage/target.raw, run the commandqemu-img info /ConvertImage/target.raw.The conversion is successful if the
file formatin the output matches the destination format.
Use the
cpcommand of ossutil 2.0 to upload the destination image file to OSS for import.The OSS console does not support files larger than 5 GB. Use ossutil to upload 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.
Convert the image file format.
sudo qemu-img convert [options] <source_image_path> <destination_image_path>[Options]Description:-f <source_format>: Specifies the format of the source image, such asvhdx,vdi,qed,qcow, orvpc(for VHD).You can run the command
sudo qemu-img --help | grep "Supported formats"to view the supported source formats.-O <destination_format>: (Uppercase O) Specifies the format of the destination image, such asraw,qcow2,vpc(for VHD), or VMDK.-p: Displays the conversion progress as a percentage.
Examples:
# Scenario 1: Convert an image from VHD to RAW format. The path of the source image is /ConvertImage/source.vhd, and the path of the destination image is /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 format. The path of the source image is /ConvertImage/source.vhdx, and the path of the destination image is /ConvertImage/target.qcow2. sudo qemu-img convert -p -f vhdx -O qcow2 /ConvertImage/source.vhdx /ConvertImage/target.qcow2Verify the conversion.
sudo qemu-img info <destination_image_path>For example, if the path of the destination image is
/ConvertImage/target.raw, run the commandsudo qemu-img info /ConvertImage/target.raw.The conversion is successful if the
file formatin the output matches the destination format.
Use the
cpcommand of ossutil 2.0 to upload the destination image file to OSS for import.The OSS console does not support files larger than 5 GB. Use ossutil to upload larger files.
FAQ
Convert an ISO image to a supported format
The
qemu-imgtool cannot directly convert an ISO image to RAW, VHD, QCOW2, or VMDK format. You must use a tool such as VirtualBox to create a virtual machine and install an operating system from the ISO image. Then, you can export the virtual machine to a supported format. For more information, see Create a virtual machine and install an operating system (Linux) or Create a virtual machine and install an operating system (Windows)."Unknown driver 'vhd'" error
In
qemu-img, the format identifier for VHD isvpc, notvhd. When you run the conversion command, usevpcas the format identifier.For example, to convert an image from
VHDXformat toVHDformat, run the following command:qemu-img convert -f vhdx -O vpc source.vhdx target.vhd.
References
For more information about the qemu-img tool, see the official QEMU documentation.
The
qemu-imgtool does not support Open Virtualization Appliance (OVA) or Open Virtualization Format (OVF) formats. These formats are maintained by the Distributed Management Task Force (DMTF). For more information, see the DMTF official website.