Difference between revisions of "KVM"

From ArchWiki
Jump to navigation Jump to search
m (→‎Get the packages: kvm* -> 'kvm*' , or will error)
Line 18: Line 18:
 
You could check if your kernel support kvm with the following command :
 
You could check if your kernel support kvm with the following command :
 
<pre>
 
<pre>
modprobe -l kvm*
+
modprobe -l 'kvm*'
 
</pre>
 
</pre>
 
KVM also requires a modified QEMU (the kvm package in the EXTRA repository, providing the qemu-kvm) to launch and manage virtual machines. Or, you can choose to install qemu >= 0.9.0, which conflicts with the kvm packge, and now provides a qemu-kvm executable (qemu -enable-kvm) that take advantage of this technology.  
 
KVM also requires a modified QEMU (the kvm package in the EXTRA repository, providing the qemu-kvm) to launch and manage virtual machines. Or, you can choose to install qemu >= 0.9.0, which conflicts with the kvm packge, and now provides a qemu-kvm executable (qemu -enable-kvm) that take advantage of this technology.  

Revision as of 06:03, 1 November 2009


Template:I18n links start Template:I18n entry Template:I18n entry Template:I18n links end

KVM, Kernel-based Virtual Machine, is a hypervisor built right into the 2.6 kernel for kernels later than 2.6.20. It is similar to Xen in purpose but much simpler to get running. To start using the hypervisor, just load the appropriate kvm modules and the hypervisor is up. As with Xen's full virtualization, in order for KVM to work, you must have a processor that supports Intel's VT extensions or AMD's Pacifica extensions.

Using KVM, one can run multiple virtual machines running unmodified Linux, Windows or any other system images. (See Guest Support Status) Each virtual machine has private virtualized hardware: a network card, disk, graphics adapter, etc. See KVM Howto

Differences among KVM, Xen, VMware, and QEMU can be found at KVM FAQ.

Get the packages

Arch Kernel 2.6.22 or newer now provide appropriate kvm modules. You could check if your kernel support kvm with the following command :

modprobe -l 'kvm*'

KVM also requires a modified QEMU (the kvm package in the EXTRA repository, providing the qemu-kvm) to launch and manage virtual machines. Or, you can choose to install qemu >= 0.9.0, which conflicts with the kvm packge, and now provides a qemu-kvm executable (qemu -enable-kvm) that take advantage of this technology.

pacman -Sy kernel26 kvm

or

pacman -Sy kernel26 qemu

Setup kernel modules

You could check if your computer support hardware acceleration with this command (must return something on screen) :

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

Firstly, you need to add your user into the kvm group to use the /dev/kvm device.

gpasswd -a <Your_Login_Name> kvm

Secondly, modprobe kvm and kvm-intel modules if you have Intel extensions.

modprobe kvm
modprobe kvm-intel

Or modprobe kvm and kvm-amd modules if you have AMD extensions.

modprobe kvm
modprobe kvm-amd

If modprobing kvm succedes, but modprobing kvm-intel or kvm-amd fails (but /proc/cpuinfo claims that VT is supported), check your bios settings. Some vendors (especially laptop vendors) disable VT by default.

If you want these modules to persist, add them to rc.conf

Using KVM as a non-root user

By default the /dev/kvm device is owned by root:root and is not accessible by other users. To enable a user to invoke qemu-kvm without root privileges, add them to the kvm group then add a udev rule to change the permissions of /dev/kvm when it is created.

groupadd kvm
usermod -aG kvm <the users' username>
cat >>/etc/udev/rules.d/65-kvm.rules <<EOF
KERNEL=="kvm", NAME="%k", GROUP="kvm", MODE="0660"
EOF
modprobe -r kvm-intel  # or kvm-amd if using that hardware
modprobe kvm-intel

It is necessary to for the user to log out before any group membership changes will take effect. /dev/kvm will be recreated with read-write privileges for members of group kvm.

How to use KVM

  1. Create a guest OS image
    $ qemu-img create -f qcow2 <Image_Name> <size>
  2. Install the guest OS
    A CD/DVD image (ISO files) can be used for the installation.
    $ qemu-kvm -hda <Image_Name> -m 512 -cdrom </Path/to/the/ISO/Image> -boot d -vga std
  3. Running the system
    $ qemu-kvm -hda <Image_Name> -m 512 -vga std

Note: The default memory of KVM is 128M, if not provide "-m".

See QEMU for all informations, and the Using the Kernel-based Virtual Machine section.

Easy to Use for New User

If the qemu package has been installed, you can use an GUI tool, such as qtemu, to manage your virtual machine (you need to change "qemu" in the configure item"QEMU start command" to "qemu-kvm" / "qemu-system-x86_64") or append -enable-kvm to the additional start options.