Using KVM on Mandriva 2009.0

Introduction

My new Dell Latitude E6400 laptop, is my first system which support hardware visualization. It also has 4 GB RAM, making this an ideal machine to start experimenting with KVM, the kernel based virtual machine system which is now integrated in Linux itself.

In the past I had already used different virtualization systems. VMWare Server is annoying because you have to rebuild the kernel modules by hand each time you install a new kernel and it’s not Free (as in Free Speech). Virtualbox handles the modules rebuild nicely thanks to the use of DKMS in Mandriva, but always randomly crashes on an assert, making it totally unusable for serious work. Also it does not really include a server mode, where virtual machines just run in the background. Xen is especially nice if you have a system which does not support hardware virtualization and you just want to run a paravirtualized Linux in it. However, the host system (Dom0) needs to run a very specific kernel version (normally version 2.6.18, although Debian has a 2.6.26 based one now). OpenVZ is nice for lightweight Linux server containers (some kind of chroot on steroids), but is not a complete virtualization solution.

Because KVM is built into the standard Linux kernel, this means there won’t be any problems with kernel modules which have to be installed separately. It’s a complete virtualization system which means that you can run all kind of operating systems on it, like for example also Windows. KVM is evolving very quickly and its performance and features are constantly improving. Thanks to libvirt and virt-manager, it also has a nice GUI front-end which make configuring and managing virtual machines very easy (libvirt and virt-manager also include support for Xen and OpenVZ, but I don’t know how well that works).

Installing and using KVM on Mandriva 2009.0

Before installing KVM, it’s important to verify that the CPU on your system has hardware virtualization support. Start up a terminal, and run


$ cat /proc/cpuinfo

If you have an Intel CPU, you should have vmx in the flags. If you are using an AMD CPU, you should have svm.

It’s best to use KVM, libvirt and virt-manager from Mandriva’s backports repositories. The versions included there, are the most recent ones, and fix a few problems which made networking not work out of the box with the ones included in the standard repositories. So start up the Mandriva Control Center (Tools – System Tools – Configure Your Computer), and in the Software category, launch the media sources configuration tool and enable the Main Backports and Contrib Backports sources by checking the checkboxes.

Before we install the necessary packages, it’s necessary to make a change to udev’s configuration file to prevent the virbr* and vnet* virtual ethernet devices and bridges being configured automatically by Mandriva’s configuration tools. To do so, edit the file /etc/sysconfig/udev_net and add virbr* and vnet* to the BLACKLIST_ALL line if they are not there yet. The line should look like this:

BLACKLIST_ALL="ppp*|ippp*|isdn*|plip*|hso*|lo*|irda*|dummy*|ipsec*|vmnet*|wifi*|
wmaster*|br*|vbd*|vtpm*|vif*|ax*|nr*|rose*|bce*|scc*|virbr*|vnet*"

Then install the kvm and virt-manager packages with the graphical software installation utility or with urpmi. Some extra dependencies will be installed, such as dnsmasq-base, libvirt-utils and python-virtinst.

After the installation, make sure that the libvirtd service is running. You can use the graphical tool in the Mandriva Control Center in the category System – Manager system services, or you can run “service libvirtd status” to verify whether it’s running and “service libvirtd start” to start it.

Now start the Virtual Machine Manager from Tools – Emulators. Choose File – Add Connection and set up a Local QEMU connection. Double click on the localhost/qemu connection in the virtual machine manager, and enter your root password. You can now create new virtual machines by clicking on the New button. To use KVM, choose a fully virtualized system, and choose KVM as hypervisor. If you want to run Mandriva 2009.0 or later in a KVM based virtual machine, you can probably choose Linux as OS type and Ubuntu Hardy as OS variant, because that should give better performance than the generic options.

I currently have Windows Vista and Debian Lenny running in KVM. It works very fast and very reliably. The only problem I encounter, is that sometimes I cannot switch back from my Windows virtual machine to my host system: the mouse and keyboard cannot leave the VNC window anymore and also the Ctrl-Alt keystroke does not release the mouse pointer. The only solution is to shut down the Windows system.

8 Replies to “Using KVM on Mandriva 2009.0”

  1. The problem with KVM is the performance. I ran XP on a machine with 4 cores (AMD) and 8Gb RAM and it was dog slow. VirtualBox is a good option for me at the moment. Using a network bridge allows me to run the XP installation as a server with no issues. Performance is fantastic and stability is as would be with a stand alone machine. KVM has a lot of work on the performance side to do to become a real alternative to other virtualization technologies.

  2. For me KVM seems very fast. My Windows Vista virtual machine boots much faster than the Windows XP installed on the real hardware (OK, that’s probably more due to the Windows version and the amount of software installed on it, but at least it is definitely not slow in KVM here), and my Debian VM also feels very fast. Also at work, someone is using it for running virtual servers, and I haven’t heard him complain about the performance. KVM is evolving very rapidly, so make sure you are using a recent version. I’m using Linux 2.6.27 and KVM 77 (I just see that KVM 78 is already out).

  3. I followed the steps you described but I can’t get it to work. When I double click on the localhost/qemu connection in the virtual machine manager, I get an error message:
    “Unable to open a connection to the libvirt management daemon.
    Verify that:
    – The ‘libvirtd’ daemon has been started”

    The daemon is started:
    “[root@LT-NDG /home/nick]# service libvirtd status
    libvirtd (pid 6215) is running…”

    Any idea what goes wrong?

    Thanks

    The details of the error dialog:

    Unable to open connection to hypervisor URI ‘qemu:///system’:
    virConnectOpenAuth() failed Failed to collect auth credentials
    Traceback (most recent call last):
    File “/usr/share/virt-manager/virtManager/connection.py”, line 427, in _open_thread
    None], flags)
    File “/usr/lib64/python2.5/site-packages/libvirt.py”, line 98, in openAuth
    if ret is None:raise libvirtError(‘virConnectOpenAuth() failed’)
    libvirtError: virConnectOpenAuth() failed Failed to collect auth credentials

  4. Maybe try checking with ps whether there is really a libvirtd process running, and try to run /etc/init.d/libvirtd restart. Other than that, I have not really an idea.

  5. It seems to be running:

    [root@LT-NDG /home]# service libvirtd restart
    Stopping libvirtd daemon: [ OK ]
    Starting libvirtd daemon: [ OK ]

    [root@LT-NDG /home]# service libvirtd status
    libvirtd (pid 22941) is running…

    [root@LT-NDG /home]# ps -e|grep libvirtd
    22941 ? 00:00:00 libvirtd

    If you haven’t got further advise I’ll post my problem on the Mandriva forum.

    Thanks anyway.

  6. Is it really listening on a socket in /var/run/libvirt/?

    # netstat -anp | grep virt
    unix 2 [ ACC ] STREAM LISTENING 9832 4163/master private/virtual
    unix 2 [ ACC ] STREAM LISTENING 85626 1838/libvirtd /var/run/libvirt/libvirt-sock
    unix 2 [ ACC ] STREAM LISTENING 85627 1838/libvirtd /var/run/libvirt/libvirt-sock-ro
    unix 3 [ ] STREAM CONNECTED 85703 1838/libvirtd /var/run/libvirt/libvirt-sock
    unix 3 [ ] STREAM CONNECTED 85628 1838/libvirtd

    Could it be that /var/run/libvirt does not exist on your system?

    Also make sure you are using all the latest packages from backports:
    python-virtinst-0.400.0-2mdv2009.1
    python-libvirt-0.4.6-3mdv2009.0
    lib64virt0-0.4.6-3mdv2009.0
    virt-manager-0.6.0-1mdv2009.0
    libvirt-utils-0.4.6-3mdv2009.0

  7. Everything seems to be more-or-less like yours:

    [root@LT-NDG /home]# netstat -anp | grep virt
    unix 2 [ ACC ] STREAM LISTENING 151494 22941/libvirtd /var/run/libvirt/libvirt-sock
    unix 2 [ ACC ] STREAM LISTENING 151496 22941/libvirtd /var/run/libvirt/libvirt-sock-ro
    unix 3 [ ] STREAM CONNECTED 151498 22941/libvirtd

    [root@LT-NDG /home]# ls -la /var/run/libvirt*
    -rw-r–r– 1 root root 6 2008-11-17 10:44 /var/run/libvirtd.pid

    /var/run/libvirt:
    total 8
    drwxr-xr-x 2 root root 4096 2008-11-17 10:44 ./
    drwxr-xr-x 27 root root 4096 2008-11-17 11:01 ../
    srwxrwxrwx 1 root root 0 2008-11-17 10:44 libvirt-sock=
    srwxrwxrwx 1 root root 0 2008-11-17 10:44 libvirt-sock-ro=

    [root@LT-NDG /home]# rpm -qa| grep python-virtinst
    python-virtinst-0.400.0-2mdv2009.0
    [root@LT-NDG /home]# rpm -qa| grep python-libvirt
    python-libvirt-0.4.6-3mdv2009.0
    [root@LT-NDG /home]# rpm -qa| grep lib64virt
    lib64virt0-0.4.6-3mdv2009.0
    [root@LT-NDG /home]# rpm -qa| grep virt-manager
    virt-manager-0.6.0-1mdv2009.0
    [root@LT-NDG /home]# rpm -qa| grep libvirt-utils
    libvirt-utils-0.4.6-3mdv2009.0

Comments are closed.