Fast Import in Linux
Scenarios
This section describes how to convert the format of a large image file on a Linux server and then quickly import it to the cloud platform. You are advised to use an EulerOS ECS for converting image file 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 (Windows) or Optimization Process (Linux). Ensure that the image file meets the requirements in Table 2 (Windows) or Table 2 (Linux).
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
- Upload an image file.
- If the image file is uploaded from a Linux PC, run the scp command.
For example, to upload image01.qcow2 to the /usr/ directory of 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 image file is uploaded from a Windows PC, use a file transfer tool, such as WinSCP, to upload the image file.
- If the image file is uploaded from a Linux PC, run the scp command.
- 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.
Table 1 Tool packages Tool Package
How to Obtain
qemu-img-hw.zip
https://cn-south-1-cloud-reset-pwd.obs.cn-south-1.myhuaweicloud.com/imageImportTools/qemu-img-hw.zip
createMF.zip
https://cn-south-1-cloud-reset-pwd.obs.cn-south-1.myhuaweicloud.com/imageImportTools/createMF.zip
- Use qemu-img-hw to convert the image format.
- Go to the directory where qemu-img-hw is stored, for example, /usr/qemu-img-hw.
cd /usr/qemu-img-hw
- Run the following command to make qemu-img-hw executable:
chmod +x qemu-img-hw
- Execute qemu-img-hw to convert the image file format to ZVHD2 (recommended) or RAW.
Command format:
./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
- Go to the directory where qemu-img-hw is stored, for example, /usr/qemu-img-hw.
- Use CreateMF.jar to generate a bitmap file.
- Ensure that JDK has been installed on the ECS.
Run the following commands to check whether JDK is installed:
source /etc/profile
java -version
If a Java version is displayed, JDK has been installed.
- Run the following command to enter the directory where CreateMF.jar is stored:
cd /usr/createMF
- 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 .mf 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.
- Ensure that JDK has been installed on the ECS.
- Use s3cmd to upload the file(s) to an OBS bucket.
- Install s3cmd on the ECS.
If s3cmd has been installed, skip this step.
- Run the following command to install setuptools:
- Run the following command to install wget:
- Run the following commands to obtain the s3cmd software package:
wget https://github.com/s3tools/s3cmd/archive/master.zip
mv master.zip s3cmd-master.zip
- Run the following commands to install s3cmd:
unzip s3cmd-master.zip
cd s3cmd-master
python setup.py install
- Configure s3cmd.
Run the following command to configure s3cmd:
s3cmd --configure Access Key: Enter an AK. Secret Key: Enter an 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 it, 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 it, 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 configurations. If you enter y, the configuration will be saved.)
The configurations will be stored in /root/.s3cfg. If you want to modify these configurations, run the s3cmd --configure command to configure the parameters or run the vi .s3cfg command to edit the .s3cfg file.
- Run the following command to upload the ZVHD2 image file (or the RAW image file and its bitmap file) to an OBS bucket.
s3cmd put image01.zvhd2 s3://mybucket/
The .mf bitmap file must be in the same OBS bucket as the RAW image file.
- Install s3cmd on the ECS.
- 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: Register a private image on the console.
- Access the IMS console.
- Log in to the management console.
- Under Compute, click Image Management Service.
The IMS console is displayed.
- In the upper right corner, click Create Image.
- In the Image Type and Source area, select Import Image for Type and then select System disk image or Data disk image for Image Type.
- 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.
- Select Enable Fast Create, and select the sentence following Image File Preparation.
Figure 1 Fast import of an image file
- Set parameters as prompted.
For details about the parameters, see Registering an External Image File as a Private Image.
Method 2: Register a private image using an API.
The API is POST /v2/cloudimages/quickimport/action.
For details about how to call this API, see Importing an Image File Quickly.
- Access the IMS console.
Appendix 1: Common qemu-img-hw Commands
- Converting image file formats: qemu-img-hw convert -p -O Target_image_format Source_image__file Target_image_file
The parameters are described as follows:
-p: indicates the conversion progress.
The part following -O (which must be in upper case) consists of the target image format, source image file, and target image file.
For example, run the following command to convert a QCOW2 image file to a ZVHD2 file:
qemu-img-hw convert -p -O zvhd2 test.qcow2 test.zvhd2
- Querying image file information: qemu-img-hw info Source image file
An example command is qemu-img-hw info test.zvhd2.
- Viewing help information: qemu-img-hw -help
Appendix 2: Common Errors During qemu-img-hw Running
- Symptom:
The following information is displayed when you run the qemu-img-hw command:
./qemu-img-hw: /lib64/libc.so.6: version `GLIBC_2.14' not found (required by ./qemu-img-hw)
Solution:
Run the strings /lib64/libc.so.6 | grep glibc command to check the glibc version. If the version is too early, install the latest version. Run the following commands in sequence:
wget http://ftp.gnu.org/gnu/glibc/glibc-2.15.tar.gz
wget http://ftp.gnu.org/gnu/glibc/glibc-ports-2.15.tar.gz
tar -xvf glibc-2.15.tar.gz
tar -xvf glibc-ports-2.15.tar.gz
mv glibc-ports-2.15 glibc-2.15/ports
mkdir glibc-build-2.15
cd glibc-build-2.15
../glibc-2.15/configure --prefix=/usr --disable-profile --enable-add-ons --with-headers=/usr/include --with-binutils=/usr/bin
If configure: error: no acceptable C compiler found in $PATH is displayed, run the yum -y install gcc command.
make
make install
- Symptom:
The following information is displayed when you run the qemu-img-hw command:
./qemu-img-hw: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
Solution: Run the yum install libaio command first.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot