Quickly Importing an Image File (Linux)

Scenarios

This section describes how to quickly import an image file in Linux. You are advised to use an EulerOS ECS on the cloud platform for converting image formats and generating bitmap files.

In Linux, you are advised to use qemu-img-hw to convert image formats.

Prerequisites

  • The image file has been optimized. For details, see Optimization Process or Optimization Process. In addition, ensure that the image file meets the requirements in Table 1 or Table 1.

    Select the reference content based on the OS type in the image file.

  • You have created an ECS running EulerOS on the management console and bound an EIP to the ECS.
  • An OBS bucket has been created on the management console.

Procedure

  1. Upload the image file to the ECS.

    • If the local host runs a Linux OS, run the scp command.

      For example, to upload image01.qcow2 to the /usr/ directory on the ECS, run the following command:

      scp /var/image01.qcow2 root@xxx.xxx.xx.xxx:/usr/

      xxx.xxx.xx.xxx indicates the EIP bound to the ECS.

    • If the local host runs a Windows OS, use a file transfer tool, such as WinSCP, to upload the image file to the ECS.

  2. Obtain the image conversion tool (qemu-img-hw.zip) and bitmap file generation tool (createMF.zip), upload them to the ECS, and decompress the packages.

  3. Use qemu-img-hw to convert the image format.

    1. Go to the directory where qemu-img-hw is stored, for example, /usr/qemu-img-hw.

      cd /usr/qemu-img-hw

    2. Run the following command to change file permissions:

      chmod +x qemu-img-hw

    3. Run the qemu-img-hw command to convert the image file to the ZVHD2 (recommended) or RAW format.

      The command format of qemu-img-hw is as follows:

      ./qemu-img-hw convert -p -O Target_image_format Source_image_file Target_image_file

      For example, run the following command to convert an image01.qcow2 file to an image01.zvhd2 file:

      ./qemu-img-hw convert -p -O zvhd2 image01.qcow2 image01.zvhd2

      • If the image file is converted to the ZVHD2 format, go to 5.
      • If the image file is converted to the RAW format, go to 4.

  4. Use CreateMF.jar to generate a bitmap file.

    1. Ensure that JDK has been installed on the ECS.

      Run the following command to check whether JDK is installed:

      source /etc/profile

      java -version

      If the Java version is displayed, JDK has been installed.

    2. Run the following command to enter the directory where CreateMF.jar is stored:

      cd /usr/createMF

    3. Run the following command to generate a bitmap file:

      java -jar CreateMF.jar /Original RAW file path /Generated .mf file path

      Example:

      java -jar CreateMF.jar image01.raw image01.mf

      The generated bitmap file must have the same name as the RAW image file. For example, if the image file name is image01.raw, the generated bitmap name is image01.mf.

  5. Use s3cmd to upload files to the OBS bucket.

    1. Install s3cmd.

      If s3cmd has been installed, skip this step.

      1. Run the following command to install setuptools:

        yum install python-setuptools

      2. Run the following command to install wget:

        yum install wget

      3. Run the following commands to obtain the s75pxd software package:

        wget https://github.com/s3tools/s3cmd/archive/master.zip

        mv master.zip s3cmd-master.zip

      4. Run the following commands to install s3cmd:

        unzip s3cmd-master.zip

        cd s3cmd-master

        python setup.py install

    2. Configure s3cmd.

      Run the following command to configure s3cmd:

      s3cmd --configure
      Access Key: Enter the AK.
      Secret Key: Enter the SK.
      Default Region: Enter the region where the bucket is located.
      S3 Endpoint: Refer to the OBS endpoint.
      DNS-style bucket+hostname:port template for accessing a bucket: Enter a server address with a bucket name, for example, mybucket.obs.myclouds.com.
      Encryption password: Press Enter.
      Path to GPG program: Press Enter.
      Use HTTPS protocol: Specifies whether to use HTTPS. The value can be Yes or No.
      HTTP Proxy server name: Specifies the proxy address used to connect the cloud from an external network. (If you do not need connect to the cloud, press Enter.)
      HTTP Proxy server port: Specifies the proxy port used to connect to the cloud from an external network (If you do not need connect to the cloud, press Enter.)
      Test access with supplied credentials? y
      (If Success. Your access key and secret key worked fine :-) is displayed, the connection is successful.)
      Save settings? y (Specifies whether to save the configuration. If y is entered, the configuration will be saved.)

      The configuration is stored in the /root/.s3cfg directory. If you want to modify the configuration, run the s3cmd --configure command again or directly edit the .s3cfg file by running the vi .s3cfg command.

    3. Run the s3cmd command to upload the ZVHD2 image file to the OBS bucket, or upload the RAW image file and its bitmap file to the OBS bucket.

      s3cmd put image01.zvhd2 s3://mybucket/

      The .mf file must be in the same OBS bucket as the RAW image file.

  6. Register a private image.

    You can register a private image using the converted ZVHD2 or RAW file on the console or using an API.

    Method 1: Create a private image on the console.

    1. Log in to the management console.
    2. Under Computing, click Image Management Service.

      The IMS console is displayed.

    3. In the upper right corner, click Create Image.
    4. In the Image Type and Source area, select System disk image or Data disk image for Type.
    5. Select Image File for Source. Select the bucket storing the ZVHD2 or RAW image file and then select the image file. If the image file is in the RAW format, you also need to select its bitmap file.
    6. Select Enable Fast Create, ensure that the image file has been optimized, and select the sentence following Image File Preparation.
      Figure 1 Importing an image file quickly
    7. Set parameters as prompted.

      For details about the parameters, see Registering an External Image File as a Private Image and Registering an External Image File as a Private Image.

      • The OS must be the same as that in the image file.
      • The size of the system disk must be greater than the size in the image file.

        You can use the qemu-img-hw tool to query for the image file size.

        qemu-img-hw info test.zvhd2

    Method 2: Create a private image using an API.

    You can use the POST /v2/cloudimages/quickimport/action API to quickly import an image file.

    For details about how to call this API, see Importing an Image File Quickly.