How to enable KVM for Poky qemu: Difference between revisions

From Yocto Project
Jump to navigationJump to search
(Created page with '= enable KVM for poky qemu = == KVM introduction == ''KVM'' (for Kernel-based Virtual Machine) is a full virtualization solution for Linux on x86 hardware containing virtualizat…')
 
Line 48: Line 48:
The output of "ls -l /dev/kvm" should be like this:
The output of "ls -l /dev/kvm" should be like this:
  crw-rw----+ 1 root kvm 10, 232 2010-07-02 09:27 /dev/kvm
  crw-rw----+ 1 root kvm 10, 232 2010-07-02 09:27 /dev/kvm
On a system that runs udev, you will probably need to add the following line somewhere in your udev configuration so it will automatically give the right group to the newly created device (i-e for ubuntu add a line to /etc/udev/rules.d/40-permissions.rules).
KERNEL=="kvm", GROUP="kvm"


Note
Note

Revision as of 06:04, 22 December 2010

enable KVM for poky qemu

KVM introduction

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. KVM also requires a modified QEMU although work is underway to get the required changes upstream.

Compared with native qemu, a pure emulator, KVM has better performance based on virtualization as most of guest instruction can be executed directly on the host processor.

detect VT support

You need make sure your x86 processor support VT before using KVM.

With a recent enough Linux kernel, run the command:

$ egrep '^flags.*(vmx|svm)' /proc/cpuinfo

If something shows up, you have VT. You can also check the processor model name (in `/proc/cpuinfo`) in the vendor's web site.

Note:

  • You'll never see (vmx|svm) in /proc/cpuinfo if you're currently running in in a dom0 or domU. The Xen hypervisor suppresses these flags in order to prevent hijacking.
  • Some manufacturers disable VT in the machine's BIOS, in such a way that it cannot be re-enabled.
  • `/proc/cpuinfo` only shows virtualization capabilities starting with Linux 2.6.15 (Intel) and Linux 2.6.16 (AMD). Use the `uname -r` command to query your kernel version.

In case of doubt, contact your hardware vendor.

get the KVM module

The quick & easy way for this is just using it from your distribution. As of now, all major community and enterprise distributions contain kvm kernel modules; these are either installed by default or require installing a kvm package. For someone looking for stability, these are the best choice. No effort is needed to build or install the modules, support is provided by the distribution, and the distribution/module combination is well tested.

In other cases, you need refer getting kvm modules.

After getting the modules, you can install them into kernel by

$ sudo modprobe kvm-intel

make KVM aware QEMU

Upstream QEMU has already supported KVM, and I have already checked in one patch to enable it. So you get a KVM capable qemu after poky build.

Change the kvm dev ownership for non-root user

qemu is started as non-root user in poky, but /dev/kvm from some distribution remains root:root that only allow root to use KVM. To work around this, we need create a new group named kvm, and make both /dev/kvm and the non-root user belongs to it.

$ sudo addgroup --system kvm
$ sudo adduser $USER kvm
$ sudo chown root:kvm /dev/kvm
$ sudo chmod 0660 /dev/kvm

The output of "ls -l /dev/kvm" should be like this:

crw-rw----+ 1 root kvm 10, 232 2010-07-02 09:27 /dev/kvm

On a system that runs udev, you will probably need to add the following line somewhere in your udev configuration so it will automatically give the right group to the newly created device (i-e for ubuntu add a line to /etc/udev/rules.d/40-permissions.rules).

KERNEL=="kvm", GROUP="kvm"


Note

  • You need log out then log in the non-root user to take the effect
  • Some distributions have already made this, so that we can skip this step

running qemu with KVM enabled

just append "kvm" parameter to the poky-qemu like this

$ poky-qemu qemux86 kvm