Using the Virtual Manager to install a KVM guest

A virtual machine (VM) is a software implementation of a computer. Systems that implement virtual machines provide a way of managing the underlying real/physical machine so that it can be split up between different virtual machines, each running its own complete operating system (called a "guest").

The Kernel based Virtual Machine (KVM) takes advantage of the modern x86 chip extensions (Intel VT or AMD-V) to provide hardware based virtualization — allowing a guest operating system to be run in a virtual machine with, ideally, no modifications needed to be made to the guest.

In KVM each running virtual machine is a single process in the operating system of the real machine. This is a neat method of leveraging the scheduling abilities of Linux to manage multiple VMs. Hardware, such as disks and network interfaces can be simulated in various ways. For example, storage devices such as hard disks can be simulated on top of a single real file. Network interfaces can be simulated and connected to the real network using Linux virtual network drivers and bridges. A collection of these techniques are provided by a toolkit called libvirt with a nice graphical user interface through the Virtual Machine Manager.

The Virtual Machine Manager provides a simple method for installing guest operating systems. It can install both Xen and KVM virtual machines (of course, depending on whether Xen or KVM software is installed). This example follows the installation of a Fedora 8 guest using KVM.

Setting up the Virtual Machine

The virtual machine manager can generally be started from the the main applications menu or using the command virt-manager. This opens up a graphical window:

virt-manager opening window

Usually on start up there are no virtual machines running. The machine called "localhost" is the real machine, and it's status is shown as "Disconnected". Systems with the libvirt toolkit installed generally have a demon libvirtd running to manage the virtual machines (it is usually started in the system boot-up process). "Disconnected" simply means a connection to this manager has not yet been made. Double clicking on the localhost line will activate it, and the status should change to "Active" with any virtual machines that have already been created listed below the localhost.

virt-manager localhost connected

In this example, there is one virtual machine present called debian-k. There is also a new icon in the last column of the localhost row. Clicking this icon begins the process of creating a new machine by opening up a new VM creation assistant:

virt-manager vm assistant

The first task is to select a name for the virtual machine. This is the name used to distinguish this VM from the others you may create. In this example, I am creating a fedora install I will use to test SELinux policies, so I give the machine a boring name of "fedora-dev". The second task is to specify the type of virtualization. Full virtualization or paravirtualization. Full virtualization is where enough hardware is simulated in the virtual machine, that the installed operating system needs no modification. Paravirtualization does not necessarily provide simulated hardware, rather provides access (via a special API) to the underlying machine hardware. This can be faster than Full virtualization, but generally requires a modified guest operating system. Note, paravirtualization is only partially supported in KVM — we use full virtualization in this example:

selecting the type of virtualization

It is possible to create virtual machines that have a number of different CPU architectures (i686, x86_64, sparc, ppc, mips etc.). Generally, these will be simulated. However, if the underlying architecture of the real machine (in my example, it's 64bit x86 CPUs) matches the one being simulated, it may be possible to take advantage of this and use hardware virtualization/acceleration. This produces a much faster virtual machine, and is the approach I take here.

The guest operating system CD/DVD and hard disk

Most operating system installs are made either over the network or from a CD/DVD. The VM assistant allows access to the real CD/DVD or setup of a simulated CD/DVD from a provided iso image. The created virtual machine will see the data on the iso image as residing on a CD/DVD device.

setting up the install iso

In addition, this section of the vm setup allows the type of operating system being installed to be defined. This is not necessary, but provides tuning for the resulting final emulation.

A Partition can be set aside for the VM, or alternatively, a file can be used and presented to the virtual machine as a single disk. There are a number of file formats available (including compressed or encrypted), the VM assistant only allows the default raw format (although it is easy to setup the other types by hand).

Setting up the network

The assistant, through libvirt, does a lot of the work for setting up a netwok for the VM using bridges and TUN virtual network drivers. There are many ways to connect the virtual machines to the network, and the assistant provides two of the most common methods as options. The first (default) option is the creation of a "virtual network" (i.e. an entire subnet is simulated and each virtual machine is plugged into that). This network is bridged to the real network via a NAT (provided by iptables) and the IP allocation for the virtual network is provided by dnsmasq. Thankfully, all of this is done for you by simply selecting the Virtual Network option in the assistant:

selecting the virtual network

The second network option provided is a "shared physical device" (everything is sent to a software bridge, and the network device is enslaved to that bridge). Better for wired networks and depends upon external dhcp servers etc.

Allocating hardware resources for the VM

Finally, amount of memory and the number of virtual CPUs for the virtual machine must be set. These should generally be smaller than the real resources available!

selecting memory resouces

After a summary screen, the virtual machine is created and the operating system installation process begins (in this example from the Fedora 8 install iso, being simulated as a CD/DVD).

Fedora 8 install

The VGA output of the virtual machine (showing the installation process, above) is displayed through a VNC viewer integrated in the virtual manager.