So you want to run a version of libvirt other than packaged version on your system. You might want to do this to see if a bug you found has been fixed in a later release, or to develop your own new feature. Since libvirt can be very tightly integrated with the rest of the distribution, there are a few things to look out for when building your own version. Here’s how I do it:
Step 0: Install your distribution’s libvirt package
The first thing you should do is install libvirt and its dependencies using your distribution’s usual method. This ensures that the directories, config files, and security policies that are required for your system get installed. Rather than starting from scratch, you’ll want to make use of these things.
Step 1: Get the source code
In order to hack on libvirt you first need to get the source. You can use git or grab a release tarball. Find the details here. Once you have the source, unpack or checkout a copy and change to that directory.
Step 2: Build it
Our goal is to run our own copy of libvirt directly from the build tree (without overwriting the system version). To do this we execute these simple commands:
./autogen.sh --system make
--system argument to
autogen.sh causes libvirt to use the regular system paths for configuration files, sockets, logs, etc. Note that we do not install (as that would overwrite the system installed version).
Step 3: Start the daemon
It is easy to start the daemon from the build root:
sudo ./daemon/libvirtd -d
This will create a system-level daemon listening at the libvirt URI
qemu:///system which you can connect to using virsh:
sudo tools/virsh -c qemu:///system
Both libvirtd and virsh use libtool wrapper scripts around the actual binaries. This means that:
Will not work as expected. The easiest way to work around this problem is to launch the daemon as suggested in Step 3 and then attach to the running process:
gdb -p `pidof lt-libvirtd`
If you cannot do this (because you want to place a breakpoint in initialization code), you can use this workaround. First, run libvirtd once as normal and stop it. This will create a binary which can then be directly executed:
This same trick can be used with virsh. Run it once normally, then:
I hope this gets you off to a good start with libvirt development. Happy hacking!