How to manage storage in KVM - Tutorial

Updated: June 1, 2011

All right, a few days back, I introduced you to Kernel-based Virtual Machine (KVM) technology, a free and open-source virtualization solution that you may consider using instead of VirtualBox and VMware products - or maybe alongside those. Either way, we dabbled in basic management, but we left storage and network for separate tutorials.

Today, I'd like to give you an more in-depth guide on managing storage in KVM. This is somewhat similar to what we did with VirtualBox, including adding, shrinking and expanding virtual disks. We will learn how to create storage pools and volumes, including examining some of the fancier options, like using NFS storage and USB-connected external disks formatted with NTFS.

Teaser

Storage management

Open the Virtual Machine Manager (VMM). Click Edit > Host Details > Storage tab.

Storage tab

This will open the Storage section. In the left column, you will see all of your listed storage pools. By default, there will be only one, default, located under /var. In the screenshot below, 18% of the storage pool is currently in use, with no volumes available just yet. Not bad, but not necessarily what we need.

Storage pools

In the right pane, you get the overview of the selected pool. First, its type. We will discuss those soon. Second, the location. State tells us the pool status; whether it's active and in use or suspended. Autostart tells us whether this pool is available to your virtual machines when KVM launches. The Volumes sub-section lists all of the virtual disks that exist in the pool, including their names size and format. We'll see an example in a second. KVM supports many kinds of images; we will soon learn more.

Add storage pool

Now, we want to add more storage. Take a look at the bottom of the left column. There are several buttons. Plus denotes adding storage pools. The play and stop buttons are used to activate and deactivate pools, respectively, without deleting them. The last button will do just that. Let's add some disk space.

Buttons

Remember: storage pool - a logical storage group that can contain one or more volumes, which are virtual disks in all kinds of formats. There are two steps.

First, choose a name and type. You can use directories (mount points), including NFS, SCSI and iSCSI storage, LVM, and even physical disks. I tried using an NTFS-formatted external disk connected via USB and it worked just fine.

Pool options

Step 2 will differ, depending on your choices. For filesystem directories, most boxes will be grayed out. Just input the Target Path and you're done.

Step 2

But if you choose, say NFS, then you will need to input additional information, like the hostname, the export directory, the mountpoint, the filesystem type.

NFS types

NFS options

Create new volume

Now, we need new volumes (disks). They will be suffixed with .img, but they can be formatted any which way. You may want to use raw or vmdk, for instance. The format will determine if you can use the virtual machines with other solutions.

Create volume

New volume

Storage formats include raw, bochs, loopback, dmg, iso, qemu copy on write, vmdk, and vpc. In theory, this allows you to use your virtual disks with Bochs, Parallels, QEMU, VMware, and Hyper-V. You can also create loopback devices and ISO images.

Types

Max. capacity is the max. size of the volume. Allocation is how much you want to allocate now. Basically, if you choose zero size, you are creating a sparse file with 0 size. You can allocate any value between zero and max. capacity.

Job done

Eventually, you will get something like this:

Finished creating

And that's it. Finito il tutorial, so to speak.

Conclusion

This tutorial is not rocket science, but it does elaborate on some of the typical questions a new KVM user may have regarding storage management. We did limit our work to the graphical interface, so the question begs, what about the command line? We'll get there, eventually, for now, we learned the basics. We know what storage pools and volumes are and how to use them.

We have many more tutorials ahead of us, including getting VirtualBox and KVM to cooperate, setup a bridged networking and taking a look at many other neat, open-source virtualization solutions. Stay tuned.

Cheers.