tutorials and ruby scripts

Read my tutorials


Tutorial: kvm

                <p>You have a pc that is just doing nothing? You have a dedicated server and want to play around without messing things up?</p>

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

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

    <li>Check if you have installed a 64bit kernel<br><pre class="prettyprint">

    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.

    <li>Install KVM tools (I am using Ubuntu/Debian commands here)<br><pre class="prettyprint">

    sudo apt-get install qemu-kvm libvirt-bin bridge-utils

  2. Add user that runs virtual servers to group (user has to re-login to get new group permissions)

    sudo adduser [username] libvirtd
  3. 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.

  4. Fix ownership

    sudo chown root:libvirtd /dev/kvm

    I do not know why, but for me /dev/kvm did not had the correct ownership.

  5. Restart kernel modules - or restart the server

    rmmod kvm
    modprobe -a kvm
  6. Optional: Install GUI for virtual server mangment:

    sudo apt-get install virt-manager
  7. 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.

  8. 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 (

  9. Managing your virtual servers

    A) start managing console

    virsh –connect qemu:///system

    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.