Translation(s): English - Español - Norsk - Русский

(!) Discussion


KVM is a full virtualization solution for Linux on x86 (64-bit included) 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.

In Debian, Xen and VirtualBox are alternatives to KVM.


Install the qemu-kvm package with apt-get or aptitude, e.g. using this command:

# aptitude install qemu-kvm libvirt-bin

The daemon libvirt-bin daemon will start automatically at boot time and load the appropriate kvm modules, kvm-amd or kvm-intel, which are shipped with the Linux kernel Debian package. If you intend to create VMs from the command-line, install virtinst.

In order to be able to manage virtual machines as regular user you should put this user into the kvm and libvirt groups:

# adduser <youruser> kvm
# adduser <youruser> libvirt

You should then be able to list your domains:

# virsh list --all

libvirt defaults to qemu:///session for non-root. So from <youruser> you'll need to do:

$ virsh --connect qemu:///system list --all

You can use LIBVIRT_DEFAULT_URI to change this.

Creating a new host

To create a Squeeze host to test LTS packages:

virt-install --virt-type kvm --name squeeze-amd64 --memory 512 --cdrom ~/iso/Debian/cdimage.debian.org_mirror_cdimage_archive_6.0.10_live_amd64_iso_hybrid_debian_live_6.0.10_amd64_gnome_desktop.iso --disk size=4 --os-variant debiansqueeze

Using this method you will need to use the GUI (virt-viewer squeeze-amd64) to complete the install.

You can avoid pulling the ISO by using the --location option. To obtain text console for the installation you can also provide --extra-args "console=ttyS0":

virt-install --virt-type kvm --name squeeze-amd64 \
--location \
--extra-args "console=ttyS0" -v --os-variant debiansqueeze \
--disk size=4 --memory 512

For a fully automated install look into preseed or debootstrap.

Starting and stopping

To shutdown a host, use the shutdown command:

virsh shutdown squeeze-amd64

If the host is not responding, you can also force-stop it with:

virsh destroy squeeze-amd64

To start it again, use start:

virsh start --force-boot --console squeeze-amd64

Notice how, above, we tell libvirt to ignore a potentially saved previous state and give us a console. As mentionned above, with this specific host, it would hang the host to connect to the console, so use control-] to exit the console and use this to connect to the GUI:

virt-viewer squeeze-amd64

You can use to connect to the host and transfer files with scp if you have a ssh server running on the host.

Automatic guest management on host shutdown/startup

Host behavior on shutdown/startup is configured in /etc/default/libvirt-guests.

This file specifies whether guests should be shutdown or suspended, if they should be restarted on host startup, etc.

First parameter defines where to find running guests. For instance:

# URIs to check for running guests
# example: URIS='default xen:/// vbox+tcp://host/system lxc:///'

Setting up bridge networking

By default, QEMU invokes the -nic and -user options to add a single network adapter to the guest and provide NATed external Internet access. The host and guest will not see each other.

In order to provide full network accessibility for the VM clients, you may set up a bridge and as described at QEMU page.

For example, you may modify network configuration file /etc/network/interfaces for setup ethernet interface eth0 to a bridge interface br0 similar as below. After the configuration, you can set using Bridge Interface br0 as the network connection in VM clients configuration.

auto lo
iface lo inet loopback

# The primary network interface
auto eth0
iface eth0 inet manual

auto br0
iface br0 inet static
        bridge_ports eth0
        bridge_stp off
        bridge_fd 0
        bridge_maxwait 0

Managing VMs from the command-line

You can then use the virsh(1) command to start and stop virtual machines. VMs can be generated using virtinst. For more details see the libvirt page. Virtual machines can also be controlled using the kvm command in a similar fashion to QEMU. Below are some frequently used commands:

Start a configured VM client "VMCLIENT":

# virsh start VMCLIENT

Notify the VM client "VMCLIENT" to graceful shutdown:

# virsh shutdown VMCLIENT

Force the VM client "VMCLIENT" to shutdown in case it is hanged, i.e. graceful shutdown not work:

# virsh destroy VMCLIENT

Managing VMs with a GUI

On the other hand, if you want to use a graphical UI to manage the VMs, you can use the Virtual Machine Manager virt-manager.

Migrating guests to a Debian host

Migrating guests from RHEL/CentOS 5.x

There are a few minor things in guest XML configuration files (/etc/libvirt/qemu/*.xml you need to modify:

In other words, the relevant sections should look something like this:

    <type arch='x86_64' machine='pc'>hvm</type>

  --- snip ---


If you had configured a bridge network on the CentOS host, please refer to this wiki article on how to make it work on Debian.

Performance Tuning

Below are some options which can improve performance of VM clients.


Disk I/O

Disk I/O is usually the bottleneck of performance due to its characteristics. Unlike CPU and RAM, VM host may not allocate a dedicated storage hardware for a VM. Worse, disk is the slowest component between them. There is two types of disk bottleneck, throughput and access time. A modern harddisk can perform 100MB/s throughput which is sufficient for most of the systems. While a modern harddisk can only provides around 60 transactions per seconds (tps).

For VM Host, you can benchmark different disk I/O parameters to get the best tps for your disk. Below is an example of disk tuning and benchmarking using fio:

For Windows VM Clients, you may wish to switch between the slow but cross-platform Windows built-in IDE driver or fast but KVM specific VirtIO driver. As a result, the installation method for Windows VM Clients provided below is a little bit complicated while provides a way to install both driver and use one for your needs. Under virt-manager:

Network I/O

Using virt-manager:



No network bridge available

virt-manager uses a virtual network for its guests, by default this is routed to and you should see this by typing ip route as root.

If this route is not present in the kernel routing table then the guests will fail to connect and you will not be able to complete a guest creation.

Fixing this is simple, open up virt-manager and go to "Edit" -> "Host details" -> "Virtual networks" tab. From there you may create a virtual network of your own or attempt to fix the default one. Usually the problem exists where the default network is not started.

cannot create bridge 'virbr0': File exists:

To solve this probelm you may remove the virbr0 by running:

brctl delbr virbr0

Open virt-manager and go to "Edit" -> "Host details" -> "Virtual networks" start the default network.

You can check the netstatus

virsh net-list --all

Optionally, you can use bridge network BridgeNetworkConnections

See also

External links

Please, add links to external documentation. This is not a place for links to non-free commercial products.