Red Hat Training

A Red Hat training course is available for Red Hat Enterprise Linux

33.3. Using qemu-img

The qemu-img command line tool is used for formatting various file systems used by Xen and KVM. qemu-img should be used for formatting guest images, additional storage devices and network storage. qemu-img options and usages are listed below.
Formatting and creating new images or devices

Create the new disk image filename of size size and format format.

# qemu-img create [-6] [-e] [-b base_image] [-f format] filename [size]
If base_image is specified, then the image will record only the differences from base_image. No size needs to be specified in this case. base_image will never be modified unless you use the "commit" monitor command.
Convert an existing image to another format

The convert option is used for converting a recognized format to another image format.

Command format:
# qemu-img convert [-c] [-e] [-f format] filename [-O output_format] output_filename
Convert the disk image filename to disk image output_filename using format output_format. The disk image can be optionally encrypted with the -e option or compressed with the -c option.
Only the format "qcow" supports encryption or compression. the compression is read-only. it means that if a compressed sector is rewritten, then it is rewritten as uncompressed data.
The encryption uses the AES format with very secure 128-bit keys. Use a long password (over 16 characters) to get maximum protection.
Image conversion is also useful to get smaller image when using a format which can grow, such as qcow or cow. The empty sectors are detected and suppressed from the destination image.
getting image information

the info parameter displays information about a disk image. the format for the info option is as follows:

# qemu-img info [-f format] filename
give information about the disk image filename. use it in particular to know the size reserved on disk which can be different from the displayed size. if vm snapshots are stored in the disk image, they are displayed too.
Supported formats

The format of an image is usually guessed automatically. The following formats are supported:

Raw disk image format (default). This format has the advantage of being simple and easily exportable to all other emulators. If your file system supports holes (for example in ext2 or ext3 on Linux or NTFS on Windows), then only the written sectors will reserve space. Use qemu-img info to know the real size used by the image or ls -ls on Unix/Linux.
QEMU image format, the most versatile format. Use it to have smaller images (useful if your file system does not supports holes, for example: on Windows), optional AES encryption, zlib based compression and support of multiple VM snapshots.
Old QEMU image format. Only included for compatibility with older versions.
User Mode Linux Copy On Write image format. The cow format is included only for compatibility with previous versions. It does not work with Windows.
VMware 3 and 4 compatible image format.
Linux Compressed Loop image, useful only to reuse directly compressed CD-ROM images present for example in the Knoppix CD-ROMs.