Wednesday, March 13, 2013

Installting libvirt on Ubuntu 12.04.2 LTS for ESX

After listening to the vBrownBag podcast on OpenStack I was eager to try out libvirt, a toolkit to manage virtualization. I primarily use Ubutu and so fired up putty and installed libvirt via Ubuntu's package management tool, aptitutude. I was surprised (and dismayed) that Ubuntu's packaged version of libvirt does not support ESX.  Upon trying out virsh I was greeted with the error:
error: invalid argument in libvirt was built without the 'esx' driver
I turned to Google and found Launchpad bug 565771 and a reference to the libvirt package listserv. It appears that the Ubuntu package maintainer has declined to include support for the libvirt ESX driver unless someone steps forward to maintain it.

My favorite Linux distribution is Ubuntu for a number of reasons. After using Debian for a number of years Ubuntu's updated packages was welcome relief.  If an updated package was unavlabile on Debian the only recourse was to build from source and so I am familiar with make and stow.  I encourage you to check out stow if you compile frequently from source. Drawing on this experience I set out to compile libvirt from source on Ubuntu 12.04.2 LTS.

First I needed some pre-requisite development libraries.
aptitude update && aptitude install -y stow libxml2-dev libdevmapper-dev libpciaccess-dev python-dev libnl-dev libcurl4-openssl-dev

I downloaded libvirt to /usr/local/src, untared the archive and configured the source.
./configure --with-esx --prefix=/usr/local

Next I ran make and make install with one adjustment. Since I am using stow to keep the installation separate I wanted to use the install option "prefix=/usr/local/stow/libvirt".  I am not 100% on the make process but it appeared some libraries needed to be installed and libtool didn't like that I was using the "prefix" option.

I turned to Google once again and found this listserv thread on using stow. It was recommended to use DESTDIR to work around this issue.
make install DESTDIR=/usr/local/stow/libvirt

Next I used stow to install the package under /usr/local
cd /usr/local/stow
stow -d /usr/local/stow -t / libvirt

After installing I needed to run ldconfig before using virsh to pick up any new libraries installed.

At this point we're all set to run virsh!
virsh -c esx://host.local?no_verify=1
Enter username for host.local [root]:
Enter root's password for host.local:
Welcome to virsh, the virtualization interactive terminal.
Type:  'help' for help with commands
       'quit' to quit
virsh #