2.3. Query an Image for Information

This section is going to show how to query some basic information from a virtual disk. The tools of the trade here are going to be ls to check disk usage, file for a quick check of the types, and qemu-img for more in-depth information. [13]

Example 2.17. Querying an Image

$ ls -lhs
total 136K
136K -rw-r-----. 1 tim tim 256K May  8 18:00 image-qcow.qcow2
   0 -rw-r-----. 1 tim tim  10G May  8 18:00 image-raw.raw

$ file image-qcow.qcow2 image-raw.raw
image-qcow.qcow2: Qemu Image, Format: Qcow , Version: 2
image-raw.raw:    data

$ qemu-img info image-qcow.qcow2
image: image-qcow.qcow2
file format: qcow2
virtual size: 10G (10737418240 bytes)
disk size: 136K
cluster_size: 65536

$ qemu-img info image-raw.raw
image: image-raw.raw
file format: raw
virtual size: 10G (10737418240 bytes)
disk size: 0

[Note]Note

These images are freshly created and don't have any information on them yet. Both were created to be 10G images.

The interesting information we can get from using ls -lhs is how the files are actually sized. What's good about these RAW disks is that you don't need any special kind of tools to know how large the disk is internally. image-raw.raw appears to be 10G but doesn't have any actual blocks allocated to it yet. It is literally an empty file. The RAW image should always match it's reported file size on the host OS.

Our QCOW, on the other hand, is being deceptive and concealing it's true size. QCOWs will grow to their maximum size over time. What makes it different from our RAW image in this case is that it already has blocks allocated to it (that information is in the left-most column and comes from the -s flag to ls). The allocated space is overhead from the meta-data associated with the QCOW image format.

TODO: Link reference to QCOW specification: http://people.gnome.org/~markmc/qcow-image-format.html

The file command tells us immediately what it thinks each file is. This is another query which is simple to perform and we can run on any system without special tools. In the last example we see it correctly reports image-qcow.qcow2's type. Unfortunately, without any content, all it can tell us about image-raw.raw is that it's data.

TODO: Link to concepts section that shows when it doesn't appear as data anymore

[Note]Note

Its worth mentioning that RAW image types will be reported by file as x86 boot sector, code offset 0xb8 once given a filesystem label and a partition table.

Using the qemu-img command we can get more detailed information about the disk images in a clearly presented format.

With qemu-img it's clear that image-qcow.qcow2 is a QCOW2 type image and is only 136K on disk and internally (the virtual size field) is a 10G disk image. If the QCOW had a backing image the path to that file would be shown here as an additional field.

For the RAW image there is no new information here that we didn't already get from the ls command.



[13] The qemu-img command manipulates virtual machine disks and is part of the QEMU suite. QEMU is a Quick EMUlator. It emulates hardware for virtual machines.