Qemu-img

From NovaOrdis Knowledge Base
Jump to navigation Jump to search

External

Internal

Overview

qemu-img is a command-line tool used to create, format, convert, modify and verify virtual machine images offline. It can handle all image formats supported by QEMU.


qemu-img must not be used to modify images in use by a running virtual machine or any other process - this may destroy the image. If an image is queried while it is modified by another process may result in an inconsistent state.

Sub-Commands

info

qemu info <filename>
qemu-img  info /main-storage-pool/testvm-01.img
image: /main-storage-pool/testvm-01.img
file format: qcow2
virtual size: 4.0G (4294967296 bytes)
disk size: 1.3G
cluster_size: 65536
Format specific information:
    compat: 1.1
    lazy refcounts: true

check

Performs a consistency check of the virtual machine image file. Only the "qcow2", "qed" or "vdi" support consistency checks. The command output can be in either "human" or "json" format.

qemu-img check <filename>

create

snapshot

List the Existent Snapshots

All snapshots present in a disk image can be listed with:

qemu-img snapshot -l <volume-name>
Snapshot list:
ID        TAG                 VM SIZE                DATE       VM CLOCK 
1         appproxy-test-snapshot.qcow2      0 2017-07-04 10:20:45   00:00:00.000

Take a Snapshot

Use "-c" and identify the snapshot with a tag. Note that there is no need to include time information in the tag, the snapshot will automatically include that, and the time stamp of the moment the snapshot was taken is available when listing the snapshots with qemu-img snapshot -l. It is recommended to use the following snapshot tag naming conventions.

qemu-img snapshot -c <snapshot-tag> <volume-name>

Example:

 qemu-img snapshot -c before_installation /main-storage-pool/appproxy.qcow2

Multiple tags with the same name are accepted, each snapshot gets a unique ID.

Revert the Disk to a Saved State

The following command applies the snapshot specified by the tag, which means the disk will be reverted to the state specified by the snapshot.

qemu-img snapshot -a <snapshot-tag> <volume-name>

Example:

qemu-img snapshot -a before_the_installation /main-storage-pool/appproxy.qcow2

Delete the Snapshot

qemu-img snapshot -d <snapshot-ID> <volume-name>

List Differences between Snapshots

Differences between Snapshots