Total Pageviews

Monday, November 22, 2010

KVM Virtualization Unleashed

What is Kernel Based Virtual Machine (kvm)?

   KVM (for Kernel-based Virtual Machine) is a full virtualization solution for Linux on x86 hardware containing virtualization extensions (Intel VT or AMD-V). It consists of a loadable kernel module, kvm.ko, that provides the core virtualization infrastructure and a processor specific module, kvm-intel.ko or kvm-amd.ko.

Using KVM, one can run multiple virtual machines running unmodified Linux or Windows images. Each virtual machine has private virtualized hardware: a network card, disk, graphics adapter, etc. 

What do I need to use KVM? 


You will need an x86 machine running a recent Linux kernel on an Intel processor with VT (virtualization technology) extensions, or an AMD processor with SVM extensions (also called AMD-V). Xen has a complete list of compatible processors. For Intel processors, see also the Intel® Virtualization Technology List.

What is Intel VT / AMD-V / hvm?  

Intel VT and AMD's AMD-V are instruction set extensions that provide hardware assistance to virtual machine monitors. They enable running fully isolated virtual machines at native hardware speeds, for some workloads.
HVM (for Hardware Virtual Machine) is a vendor-neutral term often used to designate the x86 instruction set extensions.

Will my hardware support KVM ?

 To test this open a terminal and enter :

egrep --color=auto '(vmx|svm)' /proc/cpuinfo

If you see vmx or svm in the output your hardware (CPU) will support KVM. If you get no output with that command you are out of luck.
You can also verify it on your system  BIOS for VT , If  it disabled  enable it if you didn't find any such then your hardware won't support VT .

What is Qemu ?

QEMU is a generic and open source machine emulator and virtualizer.

When used as a machine emulator, QEMU can run OSes and programs made for one machine (e.g. an ARM board) on a different machine (e.g. your own PC). By using dynamic translation, it achieves very good performance.

When used as a virtualizer, QEMU achieves near native performances by executing the guest code directly on the host CPU. QEMU supports virtualization when executing under the Xen hypervisor or using the KVM kernel module in Linux. When using KVM, QEMU can virtualize x86, server and embedded PowerPC, and S390 guests.

What is qemu-kvm? 

By itself, KVM does not perform any emulation. Instead, a user-space program uses the /dev/kvm interface to set up the guest VM's address space, feeds it simulated I/O and maps its video display back onto the host's. At least two programs exploit this feature: Qemu itself since version 0.10.0. and a modified version of Qemu, called qemu-kvm to instantiate the virtual machine

What virtual disk formats can KVM use? 

KVM inherits a wealth of disk formats support from QEMU; it supports raw images, the native QEMU format (qcow2), VMware format, and many more.

How to Choose disk formats for kvm virtual machines?

The native disk image file format of qemu is qcow2. Qcow2 provides enhanced features over raw images, including: base images, snapshots, compression, and encryption.

Users wishing to protect guest machine data from host crashes commonly disable write caching on the host. Previously, this led to very poor performance for guests in qcow2 images.

The I/O performance of qcow2 disk images has been greatly improved. Users who did not use qcow2 because of the poor performance may consider to switch and take advantage of the additional features the format provides over raw disk images. 

Kernel Same Page Merging and Reduced Guest Memory Usage

Kernel SamePage Merging (KSM) allows identical memory pages to be merged by the kernel into a single page shared between one or more processes. This feature is leveraged by KVM to allow multiple, similar, guest virtual machines to have a reduced memory footprint. Because memory is shared, the combined memory usage of the guests is reduced.

KVM Huge Page Backed Memory

Enable KVM guests to use huge page backed memory in order to reduce memory consumption and improve performance by reducing CPU cache pressure. Users of KVM guests using huge page backed memory should experience improved performance with some savings in host memory consumption. The performance benefit is workload dependent.Using huge pages for guest memory does have a downside, however - you can no longer swap nor balloon guest memory.

What is libvirt?

Libvirt is collection of software that provides a convenient way to manage virtual machines and other virtualization functionality, such as storage and network interface management. These software pieces include an API library, a daemon (libvirtd), and a command line utility (virsh).

An primary goal of libvirt is to provide a single way to manage multiple different virtualization providers/hypervisors. For example, the command 'virsh list --all' can be used to list the existing virtual machines for any supported hypervisor (KVM, Xen, VMWare ESX, etc.) No need to learn the hypervisor specific tools!

How do I know if I am using libvirt? 

You are using libvirt if you manage virtual machines using virsh, virt-manager, or virt-install (pretty much any virtualization tool that starts with virt-*).

If you are using hypervisor specific tools like 'xm', 'qemu-kvm', etc. directly, you probably are not using libvirt.

If you have virtual machines on your existing machine and you are using libvirt, 'virsh list --all' (usually run as root) should show something.

What is some of the major functionality provided by libvirt?

VM management: Various domain lifecycle operations such as start, stop, pause, save, restore, and migrate. Hotplug operations for many device types including disk and network interfaces, memory, and cpus. 

Remote machine support: All libvirt functionality is accessible on any machine running the libvirt daemon, including remote machines. A variety of network transports are supported for connecting remotely, with the simplest being SSH, which requires no extra explicit configuration. If is running libvirtd and SSH access is allowed, the following command will provide access to all virsh commands on the remote host for qemu/kvm:
virsh --connect qemu+ssh://

 Storage management: Any host running the libvirt daemon can be used to manage various types of storage: create file images of various formats (qcow2, vmdk, raw, ...), mount NFS shares, enumerate existing LVM volume groups, create new LVM volume groups and logical volumes, partition raw disk devices, mount iSCSI shares, and much more. Since libvirt works remotely as well, all these options are available for remote hosts as well.

Network interface management: Any host running the libvirt daemon can be used to manage physical and logical network interfaces. Enumerate existing interfaces, as well as configure (and create) interfaces, bridges, vlans, and bond devices. This is with the help of netcf.

 Virtual NAT and Route based networking: Any host running the libvirt daemon can manage and create virtual networks. Libvirt virtual networks use firewall rules to act as a router, providing VMs transparent access to the host machines network. 

What hypervisors does libvirt support?

A complete list can be found here:

What is the difference between KVM and Xen?

Xen is an external hypervisor; it assumes control of the machine and divides resources among guests. On the other hand, KVM is part of Linux and uses the regular Linux scheduler and memory management. This means that KVM is much smaller and simpler to use; it is also more featureful; for example KVM can swap guests to disk in order to free RAM.

KVM only run on processors that supports x86 hvm (vt/svm instructions set) whereas Xen also allows running modified operating systems on non-hvm x86 processors using a technique called paravirtualization. KVM does not support paravirtualization for CPU but may support paravirtualization for device drivers to improve I/O performance.

Does KVM support live migration from an AMD host to an Intel host and back?

Yes. There may be issues on 32-bit Intel hosts which don't support NX (or XD), but for 64-bit hosts back and forth migration should work well. Migration of 32-bit guests should work between 32-bit hosts and 64-bit hosts. If one of your hosts does not support NX, you may consider disabling NX when starting the guest on a NX-capable system. You can do it by passing "-cpu qemu64,-nx" parameter to the guest.

Can KVM run a 32-bit guest on a 64-bit host? What about PAE?

KVM supports 32-bit guests on 64-bit hosts, and any combination of PAE and non-PAE guests and hosts. The only unsupported combination is a 64-bit guest on a 32-bit host.
If you are running a Windows Virtual Machine and have problems enabling PAE in your guest see the Windows PAE Workaround page.
Does KVM support SMP hosts? 

Does KVM support SMP guests? 

Yes. Up to 16 CPUs can be specified using the -smp option.

What OSs can I run inside KVM VM?

Several. See the Guest Support Status page for details. Note that several Linux flavors are known to hang on Intel processors during startup. Workaround is to disable splash screens in grub.








No comments: