KVM (简体中文)

From ArchWiki
Revision as of 13:53, 21 August 2009 by GD (talk | contribs) (fixed i18n and categories)
Jump to navigation Jump to search

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 the kvm, xen, vmware, and qemu can be found from KVM FAQ.


Arch 内核 2.6.22 或更新版本现在提供合适的KVM模块. 你可以使用下面命令来检查你的内核版本是否支持KVM :

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


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"
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.


  1. 创建一个操作系统镜像
    $ qemu-img create -f qcow2 <Image_Name> <size>
  2. 安装操作系统
    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. 运行系统
    $ 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").