Get started Bring yourself up to speed with our introductory content.

Use QEMU Qcow2 and other tools for virtual storage management

QEMU Qcow2 and libguestfs' guestfish tool can help improve your virtual storage management practices. Read on to learn how they are able to work together in your environment.

When working with KVM VMs, storage is often managed through QEMU, but the libguestfs project can also help you...

manage storage in KVM environments. The key is knowing how KVM, QEMU and libguestfs are related, and which utilities are provided by these projects to manage storage in virtualized environments.

The evolution of QEMU

QEMU was first developed in 2003 as the Quick EMUlator, a product that emulated CPU as well as devices. When Intel and AMD later began offering hardware support for virtualization, QEMU moved in that direction as well, providing many tools to work with these new virtualization features. As Xen and KVM emerged as hypervisors that offered virtualization through the Linux kernel, QEMU's emulation features became less relevant, as virtualization proved more efficient than emulation.

However, a lot of utilities from QEMU proved effective in virtualized environments, which is why many tasks are taken care of by QEMU utilities in current KVM and Xen environments. Also, QEMU Qcow2 virtual disk format is frequently used in current day cloud environments.

Managing virtual storage with QEMU Qcow2

The most important tool used to work with storage in a QEMU environment is qemu-img, a utility that offers virtualization administrators no less than 27 different block storage formats. Administrators who create KVM VMs from the command line often create a block storage file first, using the qemu-img command.

Among the most significant of the qemu-img block storage formats is QEMU copy on write version 2 (Qcow2) format, which delays allocation of storage until it's actually needed. This makes storage more efficient compared to the RAW format because a VM can start with a relatively small image file that grows automatically when more space is needed.

Another specific feature offered by QEMU Qcow2 is that it can work with a read-only base image -- using a separate file that contains all modifications -- using copy on write technology. This approach makes it easy to revert to a previous state of the file. The administrator can use this feature by creating snapshots using the qemu-img snapshot tool. Although hardly efficient, any Qcow2 virtual disk can have a maximum of 65,536 snapshots. In most cases it doesn't make much sense to use any more than just a few snapshots, though.

Adding libguestfs to the mix

One of the challenges of working with files in the QEMU Qcow2 format is that they can't easily be mounted on the host operating system. To solve that problem, the libguestfs project was started. This project provides a library as well as a utility for working with virtual block devices and file systems. Libguestfs is not a part of QEMU, but an upstream project that was developed for working with any file system and block device that's compatible with the libvirt project. So you won't just find it in QEMU environments, but in other platforms that support libvirt as well, such as Xen.

The most important tool that libguestfs provides is guestfish, a rich shell interface that works with many different virtual block devices, and which makes it possible to mount image files, including Qcow2. As working with the guestfish shell isn't always easy, the libguestfs project has created some more user-friendly utilities. The virt-inspector command, for instance, allows administrators to read a virtual disk image and display information about the operating system that it contains. A particularly useful command is virt-rescue, which opens a rescue shell on a virtual disk, thus allowing administrators to troubleshoot disk images that can't be opened anymore.

Next Steps

Consider an in-house KVM cloud

Add a second software bridge to your KVM environment

Learn the benefits of a VM-aware storage array

This was last published in September 2016

Dig Deeper on Open source virtualization

PRO+

Content

Find more PRO+ content and other member only offers, here.

Join the conversation

1 comment

Send me notifications when other members comment.

By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Please create a username to comment.

What tools do you use to manage storage in your virtualized environment?
Cancel

-ADS BY GOOGLE

SearchVMware

SearchWindowsServer

SearchCloudComputing

SearchVirtualDesktop

SearchDataCenter

Close