This topic describes how to use qemu-img to convert the format of an existing image file to RAW, QCOW2, VHD, or VMDK.
Applicable scenario
The Volcano Engine platform allows you to import image files in RAW, QCOW2, VHD, VMDK formats as custom images. If you have an image file in another format, you need to convert the file format yourself before you import the image file.
You can use the qemu-img tool to convert image files between formats such as RAW, QCOW2, VHD, and VMDK.
tip
You cannot use qemu-img to convert image files in ISO format to RAW or QCOW2 format. Follow the image creation guidelines and use a virtual machine to create RAW or QCOW2 image files from the ISO image files. Procedure
Convert image format in the Linux operating system
- Execute the following command on the server where your image file is stored to install qemu-img.
apt-get install -y qemu-utils
- Execute the following command to convert the format of the image file.
qemu-img convert -f <source image file format> -O <target image file format> <source image file name> <target file name>
- After the format is converted, the new image file is stored in the directory where the source image file is located.
Convert format in the Windows operating system
- On the server where your image file is stored, use a browser to access the qemu-img site.
- Select the required version of qemu-img and click the filename to download it to your local machine.
-
- Double-click the downloaded .exe file and follow the instructions to install qemu.
Make sure to record the installation directory path of qemu.
- Configure the environment variables for qemu.
In this practice, the Windows Server 2022 Datacenter Edition 64 bit operating system is used as an example.
- Click the "Windows" icon, and select "Windows System".
- Right-click "This PC", and then select "More > Properties".
- Select "About" from the directory tree on the left, and at the bottom of the "About" page under "Related settings", click the "Advanced system settings" button.
- On the "Advanced" tab of the "System Properties" page, click the "Environment Variables" button.
- On the "Environment variables" page, select the Path variable in the "System variables" section, and click the "Edit" button.
- On the "Edit environment variable" page, click the "New" button and enter the qemu installation directory path specified in Step 3.
- Click the "OK" button on each configuration page one by one to complete the configuration.
- Open a new PowerShell dialog box, and execute the following command to verify whether qemu-img can be used as expected.
- In the PowerShell dialog box, execute the following command to switch to the directory where the source image file is located.
cd <The directory of the source image file>
- Execute the following command to convert the format of the source image file.
qemu-img convert -f <source image file format> -O <target image file format> <source image file name> <target file name>
- After the format is converted, the new image file is stored in the directory where the source image file is located.
Subsequent steps
After a successful conversion, you can import the obtained image file into Volcano Engine as a custom image. For more information, see Importing custom images.