Compute
Elastic Cloud Server
Huawei Cloud Flexus
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Cloud Phone Host
Huawei Cloud EulerOS
Networking
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
VPC Endpoint
Cloud Connect
Enterprise Router
Enterprise Switch
Global Accelerator
Management & Governance
Cloud Eye
Identity and Access Management
Cloud Trace Service
Resource Formation Service
Tag Management Service
Log Tank Service
Config
OneAccess
Resource Access Manager
Simple Message Notification
Application Performance Management
Application Operations Management
Organizations
Optimization Advisor
IAM Identity Center
Cloud Operations Center
Resource Governance Center
Migration
Server Migration Service
Object Storage Migration Service
Cloud Data Migration
Migration Center
Cloud Ecosystem
KooGallery
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP Filing
Support Plans
My Credentials
Customer Operation Capabilities
Partner Support Plans
Professional Services
Analytics
MapReduce Service
Data Lake Insight
CloudTable Service
Cloud Search Service
Data Lake Visualization
Data Ingestion Service
GaussDB(DWS)
DataArts Studio
Data Lake Factory
DataArts Lake Formation
IoT
IoT Device Access
Others
Product Pricing Details
System Permissions
Console Quick Start
Common FAQs
Instructions for Associating with a HUAWEI CLOUD Partner
Message Center
Security & Compliance
Security Technologies and Applications
Web Application Firewall
Host Security Service
Cloud Firewall
SecMaster
Anti-DDoS Service
Data Encryption Workshop
Database Security Service
Cloud Bastion Host
Data Security Center
Cloud Certificate Manager
Edge Security
Situation Awareness
Managed Threat Detection
Blockchain
Blockchain Service
Web3 Node Engine Service
Media Services
Media Processing Center
Video On Demand
Live
SparkRTC
MetaStudio
Storage
Object Storage Service
Elastic Volume Service
Cloud Backup and Recovery
Storage Disaster Recovery Service
Scalable File Service Turbo
Scalable File Service
Volume Backup Service
Cloud Server Backup Service
Data Express Service
Dedicated Distributed Storage Service
Containers
Cloud Container Engine
SoftWare Repository for Container
Application Service Mesh
Ubiquitous Cloud Native Service
Cloud Container Instance
Databases
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GeminiDB
GaussDB
Distributed Database Middleware
Database and Application Migration UGO
TaurusDB
Middleware
Distributed Cache Service
API Gateway
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
Multi-Site High Availability Service
EventGrid
Dedicated Cloud
Dedicated Computing Cluster
Business Applications
Workspace
ROMA Connect
Message & SMS
Domain Name Service
Edge Data Center Management
Meeting
AI
Face Recognition Service
Graph Engine Service
Content Moderation
Image Recognition
Optical Character Recognition
ModelArts
ImageSearch
Conversational Bot Service
Speech Interaction Service
Huawei HiLens
Video Intelligent Analysis Service
Developer Tools
SDK Developer Guide
API Request Signing Guide
Terraform
Koo Command Line Interface
Content Delivery & Edge Computing
Content Delivery Network
Intelligent EdgeFabric
CloudPond
Intelligent EdgeCloud
Solutions
SAP Cloud
High Performance Computing
Developer Services
ServiceStage
CodeArts
CodeArts PerfTest
CodeArts Req
CodeArts Pipeline
CodeArts Build
CodeArts Deploy
CodeArts Artifact
CodeArts TestPlan
CodeArts Check
CodeArts Repo
Cloud Application Engine
MacroVerse aPaaS
KooMessage
KooPhone
KooDrive
Help Center/ Image Management Service/ Best Practices/ Converting the Image Format/ Converting the Image Format Using qemu-img

Converting the Image Format Using qemu-img

Updated on 2024-10-31 GMT+08:00

Scenarios

You can import an image file in VHD, VMDK, QCOW2, RAW, VHDX, QCOW, VDI, QED, ZVHD, or ZVHD2 format to Huawei Cloud. Image files in other formats need to be converted before being imported. The open-source tool qemu-img is provided for you to convert image file formats.

Description

This section describes how to convert an image format on a local Windows or Linux PC.

Tool and Costs

Table 1 Tool and costs

Tool

Description

Costs

qemu-img

qemu-img is an open-source tool for converting image formats.

You can obtain it from:

https://qemu.weilnetz.de/w64/

Free

Constraints

  • qemu-img supports the mutual conversion of image formats VHD, VMDK, QCOW2, RAW, VHDX, QCOW, VDI, and QED.
  • ZVHD and ZVHD2 are self-developed image file formats and cannot be identified by qemu-img. To convert image files to any of the two formats, use the qemu-img-hw tool. For details, see Converting the Image Format Using qemu-img-hw.
  • When you run a command to convert the format of VHD image files, replace vhd with vpc.

    For example, to convert a CentOS 6.9 image file from VHD to QCOW2, run the following command:

    qemu-img convert -p -f vpc -O qcow2 centos6.9.vhd centos6.9.qcow2

    NOTE:

    If an error occurs, delete -f vpc. Then, qemu-img can identify the correct image format.

Windows

  1. Install qemu-img.
    1. Download the qemu-img installation package from https://qemu.weilnetz.de/w64/.
    2. Double-click the setup file to install qemu-img in D:\Program Files\qemu (an example installation path).
  2. Configure environment variables.
    1. Choose Start > Computer and right-click Properties.
    2. Click Advanced system settings.
    3. In the System Properties dialog box, click Advanced > Environment Variables.
    4. In the Environment Variables dialog box, search for Path in the System Variable area and click Edit. Add D:\Program Files\qemu to Variable Value. Use semicolons (;) to separate variable values.
      NOTE:

      If Path does not exist, add it and set its value to D:\Program Files\qemu.

    5. Click OK.
  3. Verify the installation.

    Choose Start > Run, enter cmd, and press Enter. In the cmd window, enter qemu-img --help. If the qemu-img version information is contained in the command output, the installation is successful.

  4. Convert the image format.
    1. In the cmd window, run the following commands to switch to D:\Program Files\qemu:

      d:

      cd D:\Program Files\qemu

    1. Run the following command to convert the image file format from VMDK to QCOW2:

      qemu-img convert -p -f vmdk -O qcow2 centos6.9.vmdk centos6.9.qcow2

      The parameters are described as follows:

      • -p indicates the image conversion progress.
      • -f indicates the source image format.
      • The part following -O (which must be in upper case) consists of the required format, source image file, and target image file.

      After the conversion is complete, the target image file is displayed in the directory where the source image file is located.

      The following information is displayed:

      # qemu-img convert -p -f vmdk -O qcow2 centos6.9.vmdk centos6.9.qcow2
          (100.00/100%)
    2. Run the following command to query details about the converted image file in QCOW2 format:

      qemu-img info centos6.9.qcow2

      The following information is displayed:

      # qemu-img info centos6.9.qcow2
      image: centos6.9.qcow2
      file format: qcow2
      virtual size: 1.0G (1073741824 bytes)
      disk size: 200K
      cluster_size: 65536
      Format specific information:
          compat: 1.1
          lazy refcounts: false

Linux

NOTE:

If any error occurs, see "Appendix 2: Common qemu-img-hw Errors" in Converting the Image Format Using qemu-img-hw.

  1. Install qemu-img.
    • For Ubuntu or Debian, run the following command:

      apt install qemu-img

    • For CentOS, Red Hat, or Oracle, run the following command:

      yum install qemu-img

    • For SUSE or openSUSE, run the following command:

      zypper install qemu-img

  2. Run the following command to check whether the installation is successful:

    qemu-img -v

    If the version information and help manual of the qemu-img tool are contained in the command output, the installation is successful. If CentOS 7 is used, the command output is as follows:

    [root@CentOS7 ~]# qemu-img -v
    qemu-img version 1.5.3, Copyright (c) 2004-2008 Fabrice Bellard
    usage: qemu-img command [command options]
    QEMU disk image utility
    
    Command syntax:
      check [-q] [-f fmt] [--output=ofmt] [-r [leaks | all]] [-T src_cache] filename
      create [-q] [-f fmt] [-o options] filename [size]
      commit [-q] [-f fmt] [-t cache] filename
      compare [-f fmt] [-F fmt] [-T src_cach]
  3. Convert the image format. For example, perform the following steps to convert a VMDK image file running CentOS 7 to a QCOW2 image file:
    1. Run the following command to convert the image file format to QCOW2:

      qemu-img convert -p -f vmdk -O qcow2 centos6.9.vmdk centos6.9.qcow2

      The parameters are described as follows:

      • -p: indicates the conversion progress.
      • -f indicates the source image format.
      • The part following -O (which must be in upper case) is the converted image format + source image file name + target image file name.

      After the conversion is complete, the target image file is displayed in the directory where the source image file is located.

      The following information is displayed:

      [root@CentOS7 home]# qemu-img convert -p -f vmdk -O qcow2 centos6.9.vmdk centos6.9.qcow2
          (100.00/100%)
    2. Run the following command to query details about the converted image file in QCOW2 format:

      qemu-img info centos6.9.qcow2

      The following information is displayed:

      [root@CentOS7 home]# qemu-img info centos6.9.qcow2
      image: centos6.9.qcow2
      file format: qcow2
      virtual size: 1.0G (1073741824 bytes)
      disk size: 200K
      cluster_size: 65536
      Format specific information:
          compat: 1.1
          lazy refcounts: false

Examples

  • Scenario

    A pre-allocated image depends on two files: xxxx.vmdk (configuration file) and xxxx-flat.vmdk (data file) and cannot be directly imported to the cloud platform. When you export a pre-allocated image file in VMDK monolithic Flat format from the VMware platform, you must convert its format to common VMDK or QCOW2 before it can be imported to the cloud platform.

    The following uses the image files centos6.9-64bit-flat.vmdk and centos6.9-64bit.vmdk as an example to describe how to use qemu-img to convert image formats.

  • Procedure
  1. Run the following commands to query the image file details:

    ls -lh centos6.9-64bit*

    qemu-img info centos6.9-64bit.vmdk

    qemu-img info centos6.9-64bit-flat.vmdk

    The following information is displayed:

    [root@CentOS7 tmp]# ls -lh centos6.9-64bit*
    -rw-r--r--. 1 root root 10G Jun 13 05:30 centos6.9-64bit-flat.vmdk
    -rw-r--r--. 1 root root 327 Jun 13 05:30 centos6.9-64bit.vmdk
    [root@CentOS7 tmp]# qemu-img info centos6.9-64bit.vmdk
    image: centos6.9-64bit.vmdk
    file format: vmdk
    virtual size: 10G (10737418240 bytes)
    disk size: 4.0K
    Format specific information:
        cid: 3302005459
        parent cid: 4294967295
        create type: monolithicFlat
        extents:
            [0]:
                virtual size: 10737418240
                filename: centos6.9-64bit-flat.vmdk
                format: FLAT
    [root@CentOS7 tmp]# qemu-img info centos6.9-64bit-flat.vmdk
    image: centos6.9-64bit-flat.vmdk
    file format: raw
    virtual size: 10G (10737418240 bytes)
    disk size: 0
    NOTE:

    The command output shows that the format of centos6.9-64bit.vmdk is VMDK and that of centos6.9-64bit-flat.vmdk is RAW. You can convert the format of only centos6.9-64bit.vmdk. For details about how to convert it, see 3.

  2. Run the following command to query the configuration of the pre-allocated image file:

    cat centos6.9-64bit.vmdk

    The following information is displayed:

    [root@CentOS7 tmp]# cat centos6.9-64bit.vmdk
    # Disk DescriptorFile
    version=1
    CID=c4d09ad3
    parentCID=ffffffff
    createType="monolithicFlat"
     
    # Extent description
    RW 20971520 FLAT "centos6.9-64bit-flat.vmdk" 0
     
    # The Disk Data Base
    #DDB
     
    ddb.virtualHWVersion = "4"
    ddb.geometry.cylinders = "20805"
    ddb.geometry.heads = "16"
    ddb.geometry.sectors = "63"
    ddb.adapterType = "ide"
  3. Place centos6.9-64bit-flat.vmdk and centos6.9-64bit.vmdk in the same directory. Run the following command to convert the format of centos6.9-64bit.vmdk to QCOW2 using qemu-img:
    [root@CentOS7 tmp]# qemu-img convert -p -f vmdk -O qcow2 centos6.9-64bit.vmdk centos6.9-64bit.qcow2
        (100.00/100%)
  4. Run the following command to query details about the converted image file in QCOW2 format:

    qemu-img info centos6.9-64bit.qcow2

    The following information is displayed:

    [root@CentOS7 tmp]# qemu-img info centos6.9-64bit.qcow2
    image: centos6.9-64bit.qcow2
    file format: qcow2
    virtual size: 10G (10737418240 bytes)
    disk size: 200K
    cluster_size: 65536
    Format specific information:
        compat: 1.1
        lazy refcounts: false

Follow-up Procedure

After the image file format is converted, you can use obsutil to upload the image file to an OBS bucket for creating a private image. For details about how to use obsutil to upload an image file, see Uploading an Object.

We use cookies to improve our site and your experience. By continuing to browse our site you accept our cookie policy. Find out more

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback