Install and configure KVM to your dedicated server


Content Contributer
You have a pc that is just doing nothing? You have a dedicated server and want to play around without messing things up?

Enable KVM on your linux kernel to create one/view virtual servers.

  • Check if your cpu has Intel VT-x or AMD-V

    egrep -c '(vmx|svm)' /proc/cpuinfo
    1 means that your cpu does have support for hardware virtualization. 0 means you might create quite slow vps. But you are able to run virtual servers.
  • Check if you have installed a 64bit kernel
    uname -m
    Something like amd64 or x86_64 indicates your are running a 64-bit kernel. You do not want to run a 32-bit kernel. That would limit your RAM usage to 2GB.
  • Install KVM tools (I am using Ubuntu/Debian commands here)
    sudo apt-get install qemu-kvm libvirt-bin bridge-utils
  • Add user that runs virtual servers to group (user has to re-login to get new group permissions)
    sudo adduser [username] libvirtd
  • Test your installation
    virsh -c qemu:///system list
     Id Name                 State
    An output like "libvir: Remote error : Permission denied" or "error: failed to connect to the hypervisor" says that something went wrong.
  • Fix ownership
    sudo chown root:libvirtd /dev/kvm
    I do not know why, but for me /dev/kvm did not had the correct ownership.
  • Restart kernel modules - or restart the server
    rmmod kvm
    modprobe -a kvm
  • Optional: Install GUI for virtual server mangment:
    sudo apt-get install virt-manager
  • Networking
    Well per default KVM has it's own network - called usermode networking. Works like OpenVPN. You have your own subnet - e.g. and every KVM gets one ip address out of it.

    Enough for me. I once need a connection to one of my webservers out of the KVM. I used port forwarding (iptables) to forward a connection from my host to the KVM.
  • Create a virtual server
    There are quite a view options. I prefer a python script called "virt-install".

    sudo apt-get install python-virtinst
    First look to the man page of virt-install
    man virt-install
    And create your first vps:
    sudo virt-install --connect qemu:///system -n kvm1 -r 2048 --vcpus=2 \
    --disk path=/var/lib/libvirt/images/kvm1-image.img,size=20 \
    -c /isos/ubuntu-min-install.iso --vnc --noautoconsole --os-type linux \
    --accelerate --network=network:default --hvm --vncport=5951
    Name: "kvm1", RAM: 2 GB, CPUs: 2, HDD: 20GB and a defined vnc port you can connect to (
  • Managing your virtual servers

    A) start managing console

    virsh --connect qemu:///system
    B) List virtual servers
    list -all
    C) start virtual server
    start [name of virtual server]
    D) stop virtual server
    shutdown [name of virtual server]
That's it. I know there are a lot of additional topics. Maybe someone wants to explain bridged networking and ip/gateway assignment. Did not need it and therefore did not play around with it.
Please feel free to add additional steps to this mini guide.
Last edited by a moderator:


New Member
A nice tutorial wlanboy. More virsh commands to create, modify vm's and the usage plus examples would be much appreciated too :D


Content Contributer
More virsh commands
Well, there are a lot of commands. Some common ones:

  • Start VM:start [name of vps]
  • Stop VM:

    shutdown [name of vps]
  • Delete VM:

    virsh destroy [name of vps]

    virsh undefine [name of vps]
  • Export VM definition to xml

    virsh dumpxml [name of vps] > ~/myvps.xml
  • Create VM out of xml

    virsh create ~/myvps.xml
  • Edit VM (if you like vi)

    virsh edit [name of vps]
  • Open serial console to vps

    virsh console [name of vps]
  • Viewing all commands

    virsh help
In my opinion altering the XML file is quite easy. Virsh is limited.

E.g. adding a second hard disk with "attach-disk [name of vps] ~/newdisk.img" is limited because some parameters are lacking.

But you can call "attach-device [name of vpy]~/myhdd.xml".

With myhdd.xml like:

<disk type='file' device='disk'>
<driver name='qemu' type='qcow2' cache='writeback'/>
<source file='/home/wlanboy/images/seconddisk.img'/>
<target dev='vdb' bus='virtio'/>

But this is only working if hotplug is working on your vps's os.
Last edited by a moderator:


Content Contributer
And an example file of one of my small debian test vms:

<domain type='qemu'>
    <type arch='i686' machine='pc-0.14'>hvm</type>
    <boot dev='hd'/>
  <clock offset='utc'/>
    <disk type='file' device='disk'>
      <driver name='qemu' type='raw'/>
      <source file='/var/lib/libvirt/images/debian.img'/>
      <target dev='hda' bus='ide'/>
      <address type='drive' controller='0' bus='0' unit='0'/>
    <disk type='block' device='cdrom'>
      <driver name='qemu' type='raw'/>
      <target dev='hdc' bus='ide'/>
      <address type='drive' controller='0' bus='1' unit='0'/>
    <controller type='ide' index='0'>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/>
    <interface type='network'>
      <mac address='52:54:00:1f:d6:79'/>
      <source network='default'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
    <serial type='pty'>
      <target port='0'/>
    <console type='pty'>
      <target type='serial' port='0'/>
    <input type='tablet' bus='usb'/>
    <input type='mouse' bus='ps2'/>
    <graphics type='vnc' port='-1' autoport='yes'/>
    <sound model='ac97'>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
      <model type='cirrus' vram='9216' heads='1'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
    <memballoon model='virtio'>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>


Article Submitter
Verified Provider
And for others that want a virtual control panel installed in a few steps stop and look at proxmox. Uses kvm and openvz easy setup for new users to the virtual world who want to learn as it gives them both the command line and a gui interface.


Content Contributer
virt-manager is not that bad:







Everyone can use this. It is a build-in feature of the Linux kernel.
Last edited by a moderator:


Content Contributer
Another cool feature of KVM are snapshots.

  • Get list of current snapshots
    virsh snapshot-list
  • Create a snapshot
    virsh snapshot-create-as [name of vps] [


New Member

thanks for the tutorial! I'm having an issue. i have a windows 7 vm, it shows 0% cpu usage on windows, but it's showing 50% on all cores in htop, any idea how to fix this?

load average: 4.91, 5.22, 5.23
Last edited by a moderator:


New Member
Hmm... there's something that I always forget until I restart the node. :)

virsh autostart [name of vps].


New Member
Any other GUI that doesnt require installing an application, and can control the vm with the broswer, like Solus/OverVZ web panel? I know proxmox has support for kvm.


The Irrational One
Retired Staff
Any other GUI that doesnt require installing an application, and can control the vm with the broswer, like Solus/OverVZ web panel? I know proxmox has support for kvm.
Proxmox, Virtualizor, Solus, oVirt, honestly any on this list:

There's also WebVirtMgr

There are a ton available with a Web Panel.  However, some people prefer not managing their services through a browser because it's considered additional overhead and also a potential security risk.