Install xen on Fedora20

Installing the Packages

To install the Xen Project software, just run:

1
# yum install xen

as root. yum will, as usual, take care of downloading and installing anything that is needed. As a part of that, it also create a new GRUB2 boot menu entry. Once the installation is complete, just reboot and select “Xen 4.x.x” from the GRUB2 menu.

If on Fedora 18 and 19, you will likely see something like “Xen 4.2.x”. If on Fedora 16 or 17, it will have “Xen 4.1.x” in it. It is also possible that you only see something like “Fedora, with Xen hypervisor”, and that is also ok.

Networking deserves some special attention. In fact, it is something that gave a lot of trouble in the past (Xen 3/4.0). That is why, from Xen Project 4.1 on, the default behavior is to let the dom0’s network scripts (i.e., the ones that came with the distribution, not the ones that come with Xen Project) handle setting up a network bridge, and let the toolstack just attach the domU’s network interface to the it. More on this matter down in the page.

Booting the Xen Project hypervisor by Default

Although a Xen Project GRUB2 menu entry will be automatically created, it will likely not be the default one. To make it so, ensure to you have a line like this in /etc/default/grub:

1
GRUB_DEFAULT=saved

and then do

1
2
3
# grub2-mkconfig -o /boot/grub2/grub.cfg
# grep ^menuentry /boot/grub2/grub.cfg | cut -d "'" -f2
# grub2-set-default <menu entry title you want>

Typically, it would be something like this:

1
2
3
4
# grep ^menuentry /boot/grub2/grub.cfg | cut -d "'" -f2
Fedora, with Linux 3.11.3-201.fc19.x86_64
Fedora, with Xen hypervisor
# sudo grub2-set-default "Fedora, with Xen hypervisor"

Disabling Network Manager

In case of any networking issues, or if you want to manually manage the network configuration, disabling NetworkManager is necessary (e.g., because NetworkManager does not support bridges), and that requires manually editing a couple of config files. This is particularly true if you do not plan to install and use the typical Fedora virtualization tools, like libvirt, etc. In fact, libvirt automatically creates a bridge and sets up the VMs created via its interface(s) to use it by default. On the other hand, if not using libvirt, the bridge has to be created by hand.

For Red Hat-based distros, the networking configuration is stored in /etc/sysconfig/network-scripts/.

Also, make sure that the network service is kicked off automatically on subsequent restarts by running:

1
# chkconfig network on

Next, create the configuration file for the bridge. The most common bridge name is br0, so let’s stick to that (although other Xen Project documentation suggests using xenbr0 to make it obvious that the bridge is for the hypervisor):

1
# touch /etc/sysconfig/network-scripts/ifcfg-xenbr0

open the file in a text editor and put the following lines in it:

1
2
3
4
5
6
DEVICE=xenbr0
TYPE=Bridge
BOOTPROTO=dhcp
ONBOOT=yes
DELAY=0
NM_CONTROLLED=no

Next, you need to find the configuration file for your existing network adaptor. It’s most likely named ifcfg-eth0 or ifcfg-em0 (the part after the dash can and does change depending on the actual hardware). Once you know what config file you’re using, open it, find the line

1
NM_CONTROLLED=yes

and change it to

1
NM_CONTROLLED=no

Also, do not forget to add the line

1
BRIDGE=xenbr0

(or whatever you named your bridge) to that file.

Finally, run this:

1
# systemctl restart network.service

and the bridge should look like this:

1
2
3
4
5
6
7
8
9
# ifconfig xenbr0
xenbr0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10.66.8.134 netmask 255.255.252.0 broadcast 10.66.11.255
inet6 fe80::26be:5ff:fe09:7bf9 prefixlen 64 scopeid 0x20<link>
ether 24:be:05:09:7b:f9 txqueuelen 0 (Ethernet)
RX packets 8051 bytes 692327 (676.1 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 304 bytes 34893 (34.0 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

Note that in earlier versions of Fedora (prior to 21), libvirt with xen would always assume that the default bridge was ‘xenbr0’. And even if you did change the option (using the libvirt overrides) it would ignore it. Fedora 21 libvirt has that fixed.

Rebooting and “Running” the Xen Project hypervisor

Now that the software is installed, (re)boot in the proper option, as explained above, and check it’s working, e.g., by running xl info from the command line, which should then tell something like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# xl info
host : localhost.localdomain
release : 3.7.6-201.fc18.x86_64
version : #1 SMP Mon Feb 4 15:54:08 UTC 2013
machine : x86_64
nr_cpus : 16
max_cpu_id : 63
nr_nodes : 2
cores_per_socket : 4
threads_per_core : 2
cpu_mhz : 2394
hw_caps : bfebfbff:2c100800:00000000:00003f40:029ee3ff:00000000:00000001:00000000
virt_caps : hvm hvm_directio
total_memory : 12285
free_memory : 128
sharing_freed_memory : 0
sharing_used_memory : 0
free_cpus : 0
xen_major : 4
xen_minor : 2
xen_extra : .1
...

If the hypervisor is not working, you’ll get something like:

1
2
3
libxl: error: libxl.c:56:libxl_ctx_init Is xenstore daemon running?
failed to stat /var/run/xenstored.pid: No such file or directory
cannot init xl context

If you get something like the error message above, double check that all the needed servic are up and running and, if not, make sure they start automatically at boot. That is the case of xenconsoled.service and xenstored.service are enabled and running. You can check their status with #systemctl status xenstored. If it says something like “inactive (dead)”, do the following:

1
2
# systemctl enable xenstored
# systemctl start xenstored

(and the same for xenconsoled)

Xen