Saturday, June 21, 2014

Basic guide for setting up virtual machines using QEMU/KVM on Fedora 20

The purpose of this guide is simply to get started using QEMU/KVM with Fedora 20. There is no need to install and boot from a special kernel. Fedora has KVM support built in which makes it rather easy. However, the tools required to install and maintain virtual machines are *not* installed by default. There are quite a few other prerequisites and post installation details that are outside the scope of this article, too.

For now, I think it's enough to say that my host machine is a quad-core x64 system with 16G of RAM and a few hundred gigs of local storage.  It doesn't take much, so let's begin!

While this step isn't required, my opinion is that it's best to begin with the most up-to-date Fedora base packages ...

sudo yum update

 ... and a reboot.

sudo init 6

To begin using the QEMU/KVM support built into the kernel (via libvirtd), I've chosen the following packages as the starting point ...

qemu-kvm
qemu-kvm-tools
virt-dmesg
virt-install
virt-manager
virt-top
virt-v2v
virt-viewer
virt-what
virt-who

The packages are all available from the fedora repository and can be installed with yum. It will determine all of the dependencies (about 135M) ...

sudo yum install qemu-kvm qemu-kvm-tools virt-dmesg virt-install virt-manager virt-top virt-v2v virt-viewer virt-what virt-who 

It's not a bad idea to verify the the packages were actually installed ...

rpm -q qemu-kvm qemu-kvm-tools virt-dmesg virt-install virt-manager virt-top virt-v2v virt-viewer virt-what virt-who 

--begin rpm -q output--
qemu-kvm-1.6.2-6.fc20.x86_64
qemu-kvm-tools-1.6.2-6.fc20.x86_64
virt-dmesg-0.3.0-10.fc20.x86_64
virt-install-1.0.1-3.fc20.noarch
virt-manager-1.0.1-3.fc20.noarch
virt-top-1.0.8-7.fc20.x86_64
virt-v2v-0.9.0-5.fc20.x86_64
virt-viewer-0.6.0-1.fc20.x86_64
virt-what-1.13-2.fc20.x86_64
virt-who-0.8-9.fc20.noarch
--end rpm -q output--

Another reboot (is not necessarily required, but it can't hurt either) ...

init 6

... and the system should be ready to create virtual machines!

The virt-manager (GUI) and virt-install (CLI) are the utilities used to install VMs. By default, everything ends up in /var/lib/libvirt but I find it's easier to have a symlink such as ...

ln -s /var/lib/libvirt /vm

... but that's not required, either, and ultimately your choice.

The virt-manager (GUI) is fairly self explanatory, I think. It provides many options to choose from when creating VMs. It's also possible to modify existing VMs.  Typically, I use the virt-manager wizard to create the first virtual machine, point it at an ISO image to install the OS, and then go from there.

A graphical (or text based) console window to the VM can be opened via virt-manager.  Or, if the VM is already created then the virt-viewer utility can also be used to connect to the virtual machine's (graphical) console.  For example ...

virt-viewer centos6-1

... will connect to the VM named 'centos6-1' (if it exists).  The primary advantage is that virt-viewer isn't as resource intensive as virt-manager and it still provides the necessities such as buttons to turn the VM on/off and/or pause it (etc).

After you've been around the block with virt-manager a few times, I highly recommend learning to use virt-install instead.  It's the equivalent command line utility and significantly more capable once you get the hang of things. 
 
Other utilities that are useful ...

virt-clone
virt-convert
virt-dmesg
virt-host-validate
virt-image
virt-manager
virt-p2v-server
virt-pki-validate
virt-top
virt-uname
virt-viewer
virt-what
virt-who
virt-xml
virt-xml-validate


... and fun!