Compiling libvirt 1.0.0 on Ubuntu 12.04 and 12.10

In case you hadn’t noticed late last week, the open source virtualization API project libvirt released version 1.0.0—a major milestone, obviously. To celebrate the 1.0.0 release, here are instructions for compiling the libvirt 1.0.0 release on Ubuntu 12.04 and 12.10.

(If you need instructions on compiling an earlier release of libvirt on Ubuntu, see this post. It works for libvirt 0.10.1 and 0.10.2 on Ubuntu 12.04 LTS; I haven’t yet tested it on Ubuntu 12.10.)

These instructions assume that you have built a plain-jane Ubuntu system (either 12.04 LTS or 12.10). I tested these instructions on an Ubuntu 12.04.1 LTS VM, freshly built and updated using apt-get update && apt-get upgrade, on a freshly-built Ubuntu 12.01 VM (also up to date), and a physical system running an up-to-date instance of Ubuntu 12.04.1 that also had KVM and an earlier version of libvirt installed. These instructions worked in all three cases.

Ready? Let’s get started!

  1. Download the libvirt-1.0.0.tar.gz tarball from the libvirt.org HTTP server.

  2. Extract the tarball using tar -xvzf libvirt-1.0.0.tar.gz.

  3. Using apt-get, ensure that the following packages are installed: gcc, make, pkg-config (already installed in my testing), libxml2-dev, libgnutls-dev, libdevmapper-dev, libcurl4-gnutls-dev, and python-dev. (Interestingly enough, earlier versions also required libyajl-dev, but this version didn’t seem to need it.) You can probably omit the libcurl4-gnutls-dev package if you don’t want ESX support; I did want ESX support, so I included it.

  4. From within the extracted libvirt-1.0.0 directory, run the configure command. I specified particular directories because that’s where the prebuilt binaries from Ubuntu are normally placed. I’ve line-wrapped it here for readability:

  5. ./configure --prefix=/usr --localstatedir=/var \
    --sysconfdir=/etc --with-esx=yes
  6. The above command does not include Xen support; if you need Xen support, you’ll need to add --with-xen=yes to the command, and your list of prerequisite packages will change (there are additional packages you’ll need to install).

  7. Once the configure command completes, then complete the process with make and make install. Note that I used sudo make install here because I’m installing files into privileged system locations.

  8. make
    sudo make install
  9. Finally, to verify that everything seems to be working as expected, restart libvirt with initctl stop libvirt-bin and initctl start libvirt-bin. (Yes, you could use initctl restart, but this allows you to see the clean stop and start of the libvirt daemon.) As an aside, note that this step only works if you either a) had a previous version of libvirt installed, or b) create the initctl job for libvirt. I chose the first approach.

  10. As a final verification step, run virsh --version or libvirtd --version to verify that you’re running libvirt 1.0.0.

That’s it! Now, as others have pointed out, this will create some potential system administration challenges, in that apt-get will still suggest new libvirt packages to install when you try to update the system. I think that there are some commands you can run to keep the manually compiled version instead of the version apt-get is suggesting, but I haven’t yet determined exactly which commands to use. (If you have more information, please speak up in the comments!)

I have a series of new libvirt-related blog posts in the works, so stay tuned for those. In the meantime, feel free to post any questions, corrections, or clarifications in the comments below. Courteous comments are always welcome.

Tags: , , , , ,

  1. Theron Conrey’s avatar

    Scott,

    Nice writeup! With all of the apt challenges that get added in with compiling your own apps on any debian based distro, I tend to stick with known good repos or build my own .deb packages to try at least to keep my servers aware of potential issues.

    It’s just a matter of time before the ubuntu virtualization team has 1.0 packaged up, and I tend to leverage this repository heavily:

    https://launchpad.net/~ubuntu-virt/+archive/ppa

  2. David Magda’s avatar

    I noticed that you didn’t explicitly include support for NUMA. Was this on purpose?

    Seems that you can get a decent performance boost by having libvirt try to consistently schedule KVM processes on same CPU; see page 36:

    http://www.linux-kvm.org/wiki/images/5/59/Kvm-forum-2011-performance-improvements-optimizations-D.pdf

    Haven’t had a chance to deploy it on our KVM infrastructure yet.

  3. can.’s avatar

    I got this error:
    configure: error: You must install the YAJL development package in order to compile libvirt

  4. can.’s avatar

    and this:
    libvirtd: initialization failed

  5. slowe’s avatar

    David, I didn’t explicitly exclude NUMA, but since my home lab systems are only single-socket systems I didn’t feel NUMA support would provide any benefit.

    CanX, if you look back at the instructions for compiling previous versions of libvirt (http://blog.scottlowe.org/2012/09/07/compiling-libvirt-0-10-1-on-ubuntu-12-04/) you’ll see that libyajl-dev was required. Try installing that package and see if it helps with your issues.

  6. can.’s avatar

    Well, I figured it out and installed libyajl-dev afterwards, but as my second comment said, libvirtd initialization failed. I checked the log, and found(ignored warnings and duplicated errors):

    2012-11-08 09:49:02.728+0000: 4256: error : networkCheckRouteCollision:2036 : internal error Network is already in use by interface br0

    2012-11-08 09:49:02.785+0000: 4256: error : virExecWithHook:419 : Cannot find ‘pm-is-supported’ in path: No such file or directory

    For the network part, I added a br0 and eth0 to it.

  7. can.’s avatar

    For the ‘pm-is-supported’ error, I got https://bugs.launchpad.net/ubuntu/+source/libvirt/+bug/994476/comments/2

    The first error is related to the configuration of ovs. I managed to solve it, but haven’t got a clear idea about it.

    And a new question comes to me: is it OK to first install a lower version libvirt using apt-get and then manually compile a new one to replace it? Have you met any problems related to this approach?

  8. Simon Green’s avatar

    Just thought I’d note you also need to `apt-get install libnl-dev` to complete dependancies.

  9. Elisha’s avatar

    I don’t seem to have any daemon named libvirt-bin. Is this a problem?

    I can start libvirtd daemon through “sudo libvirtd -d” though.

  10. wopub’s avatar

    hi?i want to know when i shut down or reboot the host?and how libvirt or OS deal with the vms on this host?

  11. Tad’s avatar

    Thank you for your post. It proved really useful. Here is complete list of packages I needed to install, before I was able to compile libvirt on completely new system: “libcurl4-gnutls-dev libncurses5-dev libdevmapper-dev libxml2-dev libnuma-dev libpciaccess-dev python-dev libnl-dev”.
    As of my experience with compiled libvirt… Well, I wouldn’t consider using it in production environment. Ubuntu proved to be quite unstable, with library problems now and then, with libvirt compiled this way. But maybe it was “checkinstall” package’s problem(I used it, because I wanted to be able to remove all the components easily, but checkinstall has failed few times, leaving various unneeded files behind). Anyway, for test/development environment it can be useful to test new features, but for the production environment the downside is too big.

  12. saju’s avatar

    I have created a Video for newbies to show How to Compile and Install libvirt 1.0.0 on Ubuntu

    https://www.youtube.com/watch?v=aNiNGmZvNUg

  13. Noor’s avatar

    Is there a way to enable xen (–with-xen=yes) after installing using yum install in fedora-18?

  14. Will Dennis’s avatar

    Scott said in the post above:
    “Now, as others have pointed out, this will create some potential system administration challenges, in that apt-get will still suggest new libvirt packages to install when you try to update the system. I *think* that there are some commands you can run to keep the manually compiled version instead of the version apt-get is suggesting, but I haven’t yet determined exactly which commands to use. (If you have more information, please speak up in the comments!)”

    The command to “freeze” a package (prevent it from being updated) is:
    (sudo) apt-mark hold [package_name]

    For instance, I have the following libvirt packages on my Ubuntu 12.04 system:
    root@server:~# dpkg -l | grep libvirt
    ii libvirt-bin 0.9.8-2ubuntu17.7 programs for the libvirt library
    ii libvirt0 0.9.8-2ubuntu17.7 library for interfacing with different virtualization systems

    I can see their update status by issuing the command:

    root@server:~# dpkg –get-selections | grep libvirt
    libvirt-bin install
    libvirt0 install

    (status “install” means “update”)

    So then we can set them to “hold” status (meaning “do not update”):

    root@server:~# apt-mark hold libvirt-bin
    libvirt-bin set on hold.
    root@server:~# apt-mark hold libvirt0
    libvirt0 set on hold.

    Then to confirm:

    root@server:~# dpkg –get-selections | grep libvirt
    libvirt-bin hold
    libvirt0 hold

    Now they will not be updated any longer (unless the hold is removed.)

  15. Bar’s avatar

    Trying to compile I get this issue (from git version)

    CCLD virnettlscontexttest
    /usr/bin/ld: virnettlscontexttest.o: undefined reference to symbol ‘gnutls_x509_crt_set_activation_time@@GNUTLS_1_4′
    /usr/bin/ld: note: ‘gnutls_x509_crt_set_activation_time@@GNUTLS_1_4′ is defined in DSO /usr/lib/x86_64-linux-gnu/libgnutls.so.26 so try adding it to the linker command line
    /usr/lib/x86_64-linux-gnu/libgnutls.so.26: could not read symbols: Invalid operation
    collect2: error: ld returned 1 exit status
    make[2]: *** [virnettlscontexttest] Error 1