QEMU-IMG command Explanation

Source: Internet
Author: User

Qemu-img is a QEMU Disk Management tool that compiles qemu-img binary files by default after compiling QEMU-KVM source code. Qemu-img is also a more important tool in the use of QEMU/KVM, and this section introduces its usage and practice usage.

The basic use of the command line for the Qemu-img tool is as follows:

qemu-img command [command Options]

The commands it supports are divided into the following types:

(1) Check [-F fmt] filename

Check the disk image file for consistency check, look for errors in the image file, currently only support for "Qcow2", "QED", "VDI" format files. Among them, Qcow2 is the image file format introduced by the QEMU 0.8.3 version, and is the most widely used format in the present. QED (qemu enhanced disk) is an enhanced disk file format that has been added since QEMU version 0.14, to avoid some of the drawbacks of the QCOW2 format and to improve performance, but it is not yet mature enough. and VDI (virtual Disk Image) is the storage format in Oracle's VirtualBox virtual machines. The parameter-F fmt is the format of the specified file, and if the format is not specified qemu-img is automatically detected,filename is the name of the disk image file (including the path).

The following command line demonstrates how to use the qemu-img Check command.

[Email protected] kvm_demo]# qemu-img check Rhel6u3.qcow2

No errors were found on the image.

(2) Create [-F fmt] [-O options] filename [size]

Create an image file formatted with the fmt size file named filename . Depending on the file format fmt , you can also add one or more optionsto attach various feature settings to the file, using "-O?" To query for a format file that supports those options, separated by commas for each option in the "-o" option.

If the Backing_file option is used in the "-o" option to specify a back-end image file, the created image file only records the differences from the back-end image file. The back-end image files are not modified unless you use the "commit" command in QEMU Monitor or use the "qemu-img commit" command to manually commit the changes. In this case, the size parameter is not required, and its value defaults to the back-end image file. In addition, the direct use of the "-B backfile" parameter is the same as the "-O backing_file=backfile" effect.

The size option specifies how large the image file is, its default unit is bytes (bytes), and it can support K (?%x8?). K), M, G, T to represent the KB, MB, GB, and TB sizes, respectively. In addition, the size of the image file (size%f??? %9 does not have to be written at the end of the command, it can also be written as one of the options in the "-o" option.

A demonstration of the C2eate command is shown below, where is the package? The EAC queries the options supported by the QCOW2 format, creates an image file in the Qcow2 format with Backing_file, and Gen-%b? e89backing_file 10GB Size of the image file in qcow2 format.

[Email protected] kvm_demo]# qemu-img create-f qcow2-o? Temp.qcow

Supported options:

Size Virtual Disk size

Compat compatibility level (0.10 or 1.1)

Backing_file file name of a base image

BACKING_FMT image format of the base image

Encryption Encrypt the image

Cluster_size qcow2 Cluster size

Preallocation preallocation mode (allowed Values:off, metadata)

[Email protected] kvm_demo]# qemu-img create-f qcow2-b rhel6u3.img R (El6u3.qcow2

Formatting ' rhel6u3.qcow2′, fmt=qcow2 size=8589934592 backing_file= ' rhel6u3.img ' Encryption=off cluster_size=6u536

[Email protected] kvm_demo]# qemu-img create-f qcow2-o backing_file=rhel6u3.img rhel6u3-1.qcow2

Formatting ' rhel6u3-1.qcow2′, fmt=qcow2 size=8589934592 backing_file= ' rhel6u3.img ' Encryption=off cluster_size=65536

[Email protected] kvm_demo]# qemu-img create-f qcow2-o backing_file=rhel6u3.img,size=20g rhel6u3-2.qcow2

Formatting ' rhel6u3-2.qcow2′, fmt=qcow2 size=21474836480 backing_file= ' rhel6u3.img ' Encryption=off cluster_size= 65536

[Email protected] kvm_demo]# qemu-img create-f qcow2 ubuntu.qcow2 10G

Formatting ' ubuntu.qcow2′, Fmt=qcow2 size=10737418240 encryption=off cluster_size=65536

(3) Commit [-F fmt] filename

Commit the changes in the filename file to the backend support image file (specified by Backing_file when created).

(4) Convert [-c] [-F fmt] [-o output_fmt] [-O options] filenam% [filename2  [...]] Output_filename

Convert the filename image file in fmt format to the format output_fmt named Output_ according to the options option the image file for filename. It supports conversion between image files in different formats, such as the ability to convert a vmdk file from VMware to a qcow2 file, which is useful for users moving from other virtualization scenarios to KVM. In general, the input file format FMT is automatically detected by the Qemu-img tool, and the output file format output_fmt according to its own needs to specify, The default is converted to the raw file format (and is stored by default using sparse files to save storage space).

Where the "-C" parameter compresses the output image file, only the image files in the Qcow2 and Qcow formats support compression, and the compression is read-only, and if the compressed sector is overridden, it is overwritten with uncompressed data. You can also use "-O options" to specify options such as back-end mirroring, file size, encryption, and so on. Using the Backing_file option to specify a back-end image, so that the resulting file is a copy-on-write delta file, you must make the backend image specified in the conversion command the same as the content of the back-end mirror of the input file, although the directories and formats of their respective back-end mirrors may be different.

If you use Qcow2, Qcow, cow, and so on as the output file format to convert the RAW format image file (non-sparse file format), the mirror transform can also be used to transform the image file into a smaller mirror, because it can remove the empty sector so that it does not exist in the generated output file.

The following command line demonstrates two transformations: convert a VMware VMDK format image to a qcow2 image that KVM can use, and transform a raw image file into a qcow2-formatted image.

[Email protected] kvm_demo]# qemu-img convert my-vmware.vmdk my-kvm.img

(There is no actual vmdk file present, only the command-line action shown)

[Email protected] kvm_demo]# qemu-img convert-o qcow2 rhel6u3.img rhel6u3-a.img

(5) Info [-F fmt] filename

Displays information about the filename image file. If the file is stored using a sparse file, it will also show the size of its original allocation and the amount of disk space actually occupied. If the file contains a snapshot of the client, the snapshot information is displayed. The following command line shows the input and output file information for the previous file conversion.

[Email protected] kvm_demo]# qemu-img info rhel6u3.img

Image:rhel6u3.img

File format: raw

Virtual size:8.0g (8589934592 bytes)

Disk size:8.0g

[Email protected] kvm_demo]# qemu-img info rhel6u3-a.img

Image:rhel6u3-a.img

File format: qcow2

Virtual size:8.0g (8589934592 bytes)

Disk size:6.8g

cluster_size:65536

(6) Snapshot [-l |-a snapshot |-c Snapshot |-d snapshot] filename

The "-l" option is to query and list all snapshots in the image file, "-a snapshot" is to have the image file use a snapshot, "-C Snapshot" is to create a snapshot, "-D" is to delete a snapshot.

(7) Rebase [-F fmt] [-t Cache] [-P] [-u]-b backing_file [-F backing_fmt] fil Ename

Change the back-end image file of the image file, only the QCOW2 and QED formats support the rebase command. Using the file specified in "-B backing_file" as the back-end mirror, the back-end image is also converted to the back-end image format specified in "-F backing_fmt".

It can work in two modes, one is Safe mode is also the default mode, QEMU-IMG will compare the original back-end image and the current back-end image of the difference between the reasonable processing, and the other is non-safe mode, is through the "-U" Parameters to specify, this mode is mainly used to rename the back-end image or move the location after the front-end image file repair processing, by the user to ensure the consistency of the back-end image.

(8) Resize filename [+ |-]size

Changes the size of the image file so that it differs from the size at the time of creation. The "+" and "-" respectively indicate the size of the image file is increased and decreased, and size is supported for use in units such as K, M, G, T, and so on. To reduce the size of the image, you need to ensure that the file system in the client has free space, otherwise the data will be lost, in addition, the QCOW2 format file does not support the operation of narrowing the image. After increasing the size of the image file, it is also necessary to start the client into the application of the "Fdisk", "parted" and other partition tools to do the corresponding operation in order to really allow the client to use the increased mirror space. However, you need to be careful when using the resize command (preferably a backup), and if it fails, it can result in data loss due to the image file not being used properly.

The following command line shows the size change of two mirrors: add 2GB of space to a 8GB qcow2 mirror, and reduce 1GB space by a 8GB size RAW image.

[Email protected] kvm_demo]# qemu-img resize rhel6u3-a.img +2g

Image resized.

[Email protected] kvm_demo]# qemu-img info rhel6u3-a.img

Image:rhel6u3-a.img

File Format:qcow2

Virtual size: 10G (10737418240 bytes)

Disk size:6.8g

cluster_size:65536

[Email protected] kvm_demo]# qemu-img resize rhel6u3-b.img-1g

Image resized.

[Email protected] kvm_demo]# qemu-img info rhel6u3-b.img

Image:rhel6u3-b.img

File Format:raw

Virtual size: 7.0G (7516192768 bytes)

Disk size:6.5g

QEMU-IMG command Explanation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.