Skip to main content

Using xen-tools on Fedora

By January 24, 2013March 7th, 2019Uncategorized

Xen.org blog already hosted a very nice post by Ian Jackson, greatly explaining how useful xen-tools is for automatically installing Debian (and Debian-derived) VMs. Now, if this all happens on a Debian host, it is nice and easy, as getting xen-tools is just a matter of apt-get install-ing it. But what if your host machine runs something else, for instance, a copy of Fedora? As a matter of fact, starting from Fedora 16, Xen is quite easy to install and use on Fedora, making it interesting to cover this case too.
There is no xen-tools RPM package, thus we need to go the good old way: download the sources, compile and  install them. Luckily enough, this is not difficult at all, and this blog post will explain in details how to achieve it.

Installing Fedora and Xen

So, let’s assume that you just finished installing the new and shiny Spherical Cow. Official instructions and advice on that are available here. The first thing to do now is to install Xen there. This has become very simple these days; all that’s needed is the following (where an # prompt means the command must be run as root):

# yum install xen

Followed by a reboot. Note that Xen will not be the default boot option, so you’ll need to make sure to select it from the GRUB2 menu. You can also make Xen the default by setting GRUB_DEFAULT=saved in your /etc/defaults/grub.conf and running the following:

# grub2-mkconfig -o /boot/grub2/grub.cfg
# XEN=$(grep ^menuentry /boot/grub2/grub.cfg | cut -f2 -d"'" | tail -n1)
# grub2-set-default $XEN

If the libvirt‘s services are needed too, some more packages must be installed, but this is out of the scope of this post. For more information on how to install Xen on Fedora, check the Fedora pages on Xen.org’s Wiki, in particular, this one: Fedora Host Installation.
What is important is that, at the end of this step, querying for Xen related installed package looks at least as follows:

$ rpm -qa | grep xen
xen-licenses-4.2.1-3.fc18.x86_64
xen-hypervisor-4.2.1-3.fc18.x86_64
xen-4.2.1-3.fc18.x86_64
xen-doc-4.2.1-3.fc18.x86_64
xen-libs-4.2.1-3.fc18.x86_64
xen-runtime-4.2.1-3.fc18.x86_64

Installing Prerequisite Packages

As we are installing from sources, the distro’s package manager is not able to help with dependencies, and we need to sort them out manually. At the time of writing, on an updated Fedora 18, all the packages needed for having xen-tools working properly can be installed like this:

# yum install debootstrap perl-Text-Templateh \
              perl-Config-IniFiles perl-File-Slurp \
              perl-File-Which perl-Data-Dumper'

And yes, that’s it! We are ready to go fetch the sources on the project Web site. Just very quickly, notice the presence of debootstrap among the packages. Well, the fact that a Fedora debootstrap package exists is what makes things so easy… Thanks a lot to jvcelak for the good job maintaining it. 🙂

Downloading and Installing xen-tools

The xen-tools sources are available here, if you are interested in a released version, and here, if you want to fetch the latest development branch. For convenience, here it is how to achieve both. Released version (4.3.1, at the time of this post):

$ wget http://xen-tools.org/software/xen-tools/xen-tools-4.3.1.tar.gz
[...]
$ tar zxvf xen-tools-4.3.1.tar.gz

And development version (of course, for this, you need git to be installed):

$ git clone git://gitorious.org/xen-tools/xen-tools.git xen-tools.git

After that, enter either xen-tools-4.3.1 or xen-tools.git and proceed with the installation, by running:

# make install

(Auto)Installing your first VM

Well, believe it or not, we’re done: all set for starting provisioning debian-alike VMs via the super-handy xen-create-image! For an example, try this:

# xen-create-image --genpass=0 --memory=1024M --noswap --dhcp \
                   --password="xenroot" --pygrub --size=8G \
                   --vcpus=2 --arch=amd64 --bridge=virbr0 \
                   --hostname=wheezy64 --lvm=vms \
                   --mirror=http://cdn.debian.net/debian \
                   --install-method=debootstrap \
                   --dist=wheezy

Most of the parameters have talking enough names, and don’t need much commenting. Just notice that --lvm takes the name of the volume group name where the logical volume for the disk of the new VM should be created (use vgscan to see the existing VGs). Also, --size is how big you want that disk to be, and --bridge must point to the configured bridge (as reported by ifconfig or brctl show). For more information on the other parameters, check out man xen-create-image and/or Ian’s post. Since we are not on a Debian host, it is important to specify a --mirror=URL option. For a list of valid URLs, this is the official list of Debian mirrors. The tool will complain a bit about not finding anything useful in /etc/apt/sources.list, but that is harmless (hey, you’re running on Fedora, dude!).

# xl create -c /etc/xen/wheezy64
[...]
Debian GNU/Linux 7.0 wheezy64 hvc0
wheezy64 login: root
Password:
Last login: Mon Jan 21 17:17:16 CET 2013 from 192.168.122.1 on pts/0
Linux wheezy64 3.2.0-4-amd64 #1 SMP Debian 3.2.35-2 x86_64
The programs included with the Debian GNU/Linux system are free
software; the exact distribution terms for each program are described
in the individual files in /usr/share/doc/*/copyright.
Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
root@wheezy64:~# virt-what
xen
root@wheezy64:~# free -m
             total      used      free    shared   buffers    cached
Mem:           998        37       960         0         1        16
-/+ buffers/cache:        19       979
Swap:            0         0         0

Non Debian-alike VMs

Last but not least, although Debian and Debian-alike distros are the preferred targets of xen-tools, it is possible to deal with RPM based distros, like CentOS, OpenSuSE and Fedora itself, via rinse. Again, it is something that needs to be fetched (e.g., with git) and installed manually:

$ git clone git://gitorious.org/rinse/rinse.git rinse.git
$ cd rinse.git
# make install

After that, the following will become possible:

# xen-create-image --genpass=0 --memory=1024M --noswap --dhcp \
                   --password="xenroot" --pygrub --size=8G \
                   --vcpus=2 --arch=amd64 --bridge=virbr0 \
                   --install-method=rinse --hostname=f16-x64 \
                   --lvm=vms --dist="fedora-16" --cache=no

Where this is the full list of distributions currently supported by rinse:

$ rinse --list-distributions
The following distributions are available:
    centos-4
    centos-5
    centos-6
    fedora-10
    fedora-12
    fedora-13
    fedora-14
    fedora-15
    fedora-16
    fedora-7
    fedora-8
    fedora-9
    fedora-core-4
    fedora-core-5
    fedora-core-6
    opensuse-10.1
    opensuse-10.2
    opensuse-10.3
    opensuse-11.0
    opensuse-11.1
    opensuse-11.2
    opensuse-11.3