Help & Documentation>Cloud Virtual Machine

Converting image format

Last updated: 2023-09-27 14:17:06

Scenario

Tencent Cloud currently supports importing image files in the following formats: RAW, VHD, QCOW2, and VMDK. Images in other formats must be converted before importing. This article describes how to use the qemu-img tool to convert images in other formats to VHD or RAW format.

Instructions

Note
qemu-img does not support converting ISO images to VHD or RAW format. If you need to convert an ISO image, it is recommended to create a virtual machine, boot the system using the ISO, install the system onto the disk, and then export it in a supported format.
Select the method according to the operating system of the CVM instance:
Windows OS
Linux OS
Note
This article uses a
Windows
10 operating system as an example for image format conversion. The process may vary slightly depending on the operating system version; please refer to the documentation and adjust accordingly based on your specific situation.

Installing qemu-img

Please visit the qemu-img download page to download and complete the installation. This article assumes that qemu-img is installed in C:\Program Files\qemu.

Configuring environment variable

1. Right-click Start and select System from the context menu.
2. In the pop-up window, select Advanced System Settings.
3. In the System Properties window that appears, select the Advanced tab and click Environment Variables.
4. In the Environment Variables window, select Path in the System Variables section and click Edit. See the image below:

5. In the Edit Environment Variables pop-up window, click New, enter the installation path of qemu-img C:\Program Files\qemu, and then click Confirm.
6. In the Environment Variables window, click OK again.

Verifying environment variable configuration

1. Press Win + R to open the Run window.
2. In the Run window, enter cmd to open the command prompt.
3. Run the following command to determine whether the environment variable has been configured successfully based on the returned result:
qemu-img --help

Converting image format

1. Run the following command on the command line to switch to the directory of the image file:
cd <directory containing the source image file>
2. Run the following command to convert the image format:
qemu-img convert -f <source_image_format> -O <target_image_format> <source_image_filename> <target_image_filename>
The parameters are described as follows:
-f: The parameter value is the format of the source image file.
-O (must be uppercase): The parameter value is the target image format, source image file name, and target file name. For example, execute the following command to convert the test.qcow2 image file to test.raw.
qemu-img convert -f qcow2 -O raw test.qcow2 test.raw
After conversion, the target file will be displayed in the directory of the source image file.
Note
This
document
provides examples of image format conversion using Ubuntu 20.04 and CentOS 7.8 operating systems. The steps may vary depending on the operating system version, so please refer to the document and adjust as per your actual situation.

Installing qemu-img

1. Run the following command to install qemu-img:
Ubuntu:
apt-get clean all # Clear cache
apt-get update # Update the package list
apt-get install qemu-utils # Install qemu-img
CentOS:
yum install qemu-img
2. Run the following command to convert the image format:
qemu-img convert -f qcow2 -O raw test.qcow2 test.raw
The parameters are described as follows:
-f: The parameter value is the format of the source image file.
-O (must be uppercase): The parameter value includes the target image format, source image file name, and target file name. After the conversion is complete, the target file will appear in the directory where the source image file is located.

Documentation