Building the Xen Hypervisor with PetaLinux 2016.3


Before starting you need to create a PetaLinux project. It is assumed that a default PetaLinux reference design is used unchanged in these instructions.

Boot Xen and dom0 on QEMU or Hardware

To run Xen you can either use the prebulit version shipped with PetaLinux or build it yourself using PetaLinx. See the section below for steps about buildling Xen yourself.

Configurng and building XEN from source using PetaLinux (Optional)

The default PetaLinux configuration has all the necessary options set by default. The XEN tools and XEN hypervisor will be built by default. So simply run:

You have to manually copy the xen-qemu.dtb from the pre-built directory:

Run Xen dom0 on QEMU:

To use the Xen you built yourself run:

To use the prebuilt Xen run:

Run Xen dom0 on HW:

To use the Xen you built yourself run:

To use the prebuilt Xen run:

You should eventually see something similar to this, when you do press any key to stop the autoboot.

If u-boot wasn't able to get an IP address from the DHCP server you may need to manually set the serverip (it's typically 10.0.2.2 for QEMU):

Now to download and boot Xen, if running on QEMU, use xen-qemu.dtb otherwise use xen.dtb. Example:
Below is an example of what you will see.

Starting additional guests (Tested on QEMU with the 2016.3 ZCU102 BSP)


PetaLinux has no pre-built or automatic support for starting additional guests.
We'll go through the manual steps needed to do so.

First, we'll enable SSH. This is done by configuring the rootfs.

We navigate to Filesystem Packages->console/network->dropbear and enable all of the options there.
Once enabled exit petalinux-config and ensure that the new selection is saved. Then rebuild PetaLinux

If running on QEMU, we'll need to setup a port mapping for port 22 (SSH) in our VM.
In this example, we forward the hosts port 2222 to the VM's port 22.

Once you hit the u-boot prompt, follow the steps in the earlier section on how to run Xen dom0.
When dom0 is done starting, we'll need to copy a guest Image into dom0's filesystem.
We'll simply reuse the PetaLinux Image as our domU guest.

If running on QEMU, we use scp's -P option to connect to our hosts port 2222 where QEMU will forward the connection to the guests port 22:
If running on HW:

Now we need an xl configuration file that describes the VM. We'll create it in /etc/xen/example1.cfg. Here's a small example of the contents of such a file:

Next step is to start the VM. This is done from a dom0 prompt:

You'll see another instance of Linux booting up.
At any time you can leave the console of the guest and get back to dom0 by pressing ctrl+].
You can list the guests from dom0:

To get back to the guests console:

You can create further guests by for example running:

To destroy a guest:

Starting Linux guests with Para-Virtual networking


In this section we'll describe how to run Linux guests that use para-virtual network connections with dom0 and external networks.
First, we need to reconfigure the PetaLinux kernel.

Enable Device Drivers, Network devices, Xen backend network device. Save and exit.
Now, we'll reconfigure the rootfs.

Enable dropbear as described in the previous section nr 2.
We also need to enable the bridge-utils. These are found under Filesystem Packages, net, bridge-utils.

This time we will run QEMU slightly different. We'll create two port mappings. One for dom0's SSH port and another for the Para-Virtual domU.
The default IP addresses assigned by QEMUs builtin DHCP server start from 10.0.2.15 and count upwards.
Dom0 will be assigned 10.0.2.15, the next guest 10.0.2.16 and so on.
So here's the command line that maps host port 2222 to dom0 port 22 and 2322 to domUs port 22.

Now, follow the instructions from section 1 on how to boot Xen dom0.
Once you are at the dom0 prompt, we'll need to setup the networking.
In this example, we will configure the guests to directly join the external network by means of a bridge.

First of all, we need to de-configure the default setup.
Kill the dhcp client for eth0:

List and remove existing addresses from eth0:
In our example the address is 10.0.2.15/24:

Then, create the bridge and start DHCP on it for dom0:

You should see something like the following:

Now we need an xl config file describing the VM. The contents are very similar to the example in section 2, we only add one line.
In this example we create /etc/xen/example-pvnet.cfg in dom0's filesystem:

Now we are good to go:

You should see a new linux instance boot up.
Now we'll ssh into the domU running Para-Virtual networking: