Virtualization with KVM

Introducing KVM, its internals and how to configure and install it.

Virtualization has made a lot of progress during the last decade, primarily due to the development of myriad open-source virtual machine hypervisors. This progress has almost eliminated the barriers between operating systems and dramatically increased utilization of powerful servers, bringing immediate benefit to companies. Up until recently, the focus always has been on software-emulated virtualization. Two of the most common approaches to software-emulated virtualization are full virtualization and paravirtualization. In full virtualization, a layer, commonly called the hypervisor or the virtual machine monitor, exists between the virtualized operating systems and the hardware. This layer multiplexes the system resources between competing operating system instances. Paravirtualization is different in that the hypervisor operates in a more cooperative fashion, because each guest operating system is aware that it is running in a virtualized environment, so each cooperates with the hypervisor to virtualize the underlying hardware.

Both approaches have advantages and disadvantages. The primary advantage of the paravirtualization approach is that it allows the fastest possible software-based virtualization, at the cost of not supporting proprietary operating systems. Full virtualization approaches, of course, do not have this limitation; however, full virtualization hypervisors are very complex pieces of software. VMware, the commercial virtualization solution, is an example of full virtualization. Paravirtualization is provided by Xen, User-Mode Linux (UML) and others.

With the introduction of hardware-based virtualization, these lines have blurred. With the advent of Intel's VT and AMD's SVM, writing a hypervisor has become significantly easier, and it now is possible to enjoy the benefits of full virtualization while keeping the hypervisor's complexity at a minimum.

Xen, the classic paravirtualization engine, now supports fully virtualized MS Windows, with the help of hardware-based virtualization. KVM is a relatively new and simple, yet powerful, virtualization engine, which has found its way into the Linux kernel, giving the Linux kernel native virtualization capabilities. Because KVM uses hardware-based virtualization, it does not require modified guest operating systems, and thus, it can support any platform from within Linux, given that it is deployed on a supported processor.

KVM

KVM is a unique hypervisor. The KVM developers, instead of creating major portions of an operating system kernel themselves, as other hypervisors have done, devised a method that turned the Linux kernel itself into a hypervisor. This was achieved through a minimally intrusive method by developing KVM as kernel module. Integrating the hypervisor capabilities into a host Linux kernel as a loadable module can simplify management and improve performance in virtualized environments. This probably was the main reason for developers to add KVM to the Linux kernel.

This approach has numerous advantages. By adding virtualization capabilities to a standard Linux kernel, the virtualized environment can benefit from all the ongoing work on the Linux kernel itself. Under this model, every virtual machine is a regular Linux process, scheduled by the standard Linux scheduler. Traditionally, a normal Linux process has two modes of execution: kernel and user. The user mode is the default mode for applications, and an application goes into kernel mode when it requires some service from the kernel, such as writing to the hard disk. KVM adds a third mode, the guest mode. Guest mode processes are processes that are run from within the virtual machine. The guest mode, just like the normal mode (non-virtualized instance), has its own kernel and user-space variations. Normal kill and ps commands work on guest modes. From the non-virtualized instance, a KVM virtual machine is shown as a normal process, and it can be killed just like any other process. KVM makes use of hardware virtualization to virtualize processor states, and memory management for the virtual machine is handled from within the kernel. I/O in the current version is handled in user space, primarily through QEMU.

A typical KVM installation consists of the following components:

  • A device driver for managing the virtualization hardware; this driver exposes its capabilities via a character device /dev/kvm.

  • A user-space component for emulating PC hardware; currently, this is handled in the user space and is a lightly modified QEMU process.

  • The I/O model is directly derived from QEMU's, with support for copy-on-write disk images and other QEMU features.

How do you find out whether your system will run KVM? First, you need a processor that supports virtualization. For a more detailed list, have a look at wiki.xensource.com/xenwiki/HVM_Compatible_Processors. Additionally, you can check /proc/cpuinfo, and if you see vmx or smx in the cpu flags field, your system supports KVM.

______________________

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Thanks for the heads up!

Anonymous's picture

Thanks for the original link....I like that article better!

Suspicious circumstances

noticer's picture

I may be mistaken, but the content of this article appears to be copied (at times word for word) from an earlier article written on April 18th 2007, found here - http://www.ibm.com/developerworks/linux/library/l-linux-kvm/ . If so the circumstances are unfortunate and apalling.

An example is the section in this article (written on 1st Feb 2008)

"Two of the most common approaches to software-emulated virtualization are full virtualization and paravirtualization. In full virtualization, a layer, commonly ..... so each cooperates with the hypervisor to virtualize the underlying hardware. "

is almost the IDENTICAL to

"Two of the most common approaches to virtualization are full virtualization and para-virtualization. With full virtualization, a layer exists between the virtualized operating systems ...... so each cooperates with the hypervisor to virtualize the underlying hardware." from the article by Tim Jones linked above.

SHAME!

Oops

Mitch Frazier's picture

I would have to agree with you, it appears that much of this was copied from the article that you mention. We do attempt, when circumstances warrant it, to check the web to make sure content is original, but mostly we just have to rely on the honesty of our authors.

So yes, shame on us and shame on the author.

Mitch Frazier is an Associate Editor for Linux Journal.

HOW to get KVM going on Suse 10.3

awilcox's picture

Hello,
I installed the two KVM packages using Yast. That was the easy part.

Now what do I do?

"kvm-intel" isn't recognized. Is there some script you didn't mention? Am I supposed to use modprobe?

Webinar
One Click, Universal Protection: Implementing Centralized Security Policies on Linux Systems

As Linux continues to play an ever increasing role in corporate data centers and institutions, ensuring the integrity and protection of these systems must be a priority. With 60% of the world's websites and an increasing share of organization's mission-critical workloads running on Linux, failing to stop malware and other advanced threats on Linux can increasingly impact an organization's reputation and bottom line.

Learn More

Sponsored by Bit9

Webinar
Linux Backup and Recovery Webinar

Most companies incorporate backup procedures for critical data, which can be restored quickly if a loss occurs. However, fewer companies are prepared for catastrophic system failures, in which they lose all data, the entire operating system, applications, settings, patches and more, reducing their system(s) to “bare metal.” After all, before data can be restored to a system, there must be a system to restore it to.

In this one hour webinar, learn how to enhance your existing backup strategies for better disaster recovery preparedness using Storix System Backup Administrator (SBAdmin), a highly flexible bare-metal recovery solution for UNIX and Linux systems.

Learn More

Sponsored by Storix