The new development of Xen and Linux kernel make it easy to install Xen on Fedora as the Domain-0 now. This post uses Fedora 17 as an example platform to introduce how to set up Domain-0 on Fedora Linux. Compared to our old method (https://www.systutorials.com/setting-up-stable-xen-dom0-with-fedora-xen-3-4-3-with-xenified-linux-kernel-2-6-32-13-in-fedora-12/) which requires manually compiled Xen and patched kernel, the current packages and support to Xen in Fedora and Linux kernel make the system administrators life much easier.
On the other hand, Xen has changed its tool stack from xm/xend to xl and the network configuration should be done manually on different platforms.
Table of Contents
First, install the xen pacakges:
# yum install xen
The Linux kernel is already ready to run in Domain-0 with the pv_ops technology enabled. The xen and kernel versions I used is listed as follows.
Run this command to make config for grub2 again:
# grub2-mkconfig -o /boot/grub2/grub.cfg
Otherwise, the kernel will fail to boot and print messages like “swap not trainted…”.
Then, we can boot the Fedora to run on Xen as Domain-0 by selecting the Fedora, with Xen hypervisor in Grub2 during booting the system. We can also https://www.systutorials.com/setting-default-entry-in-grub2-and-grub/.
After booting Linux on Xen as Domain-0, we can list the information by ‘xl info’ as follow.
# xl info host : office.zhiqiangma.com release : 3.6.6-1.fc17.x86_64 version : #1 SMP Mon Nov 5 21:59:35 UTC 2012 machine : x86_64 nr_cpus : 4 nr_nodes : 1 cores_per_socket : 4 threads_per_core : 1 cpu_mhz : 2809 hw_caps : bfebfbff:28100800:00000000:00003b40:0098e3fd:00000000:00000001:00000000 virt_caps : hvm total_memory : 2039 free_memory : 126 free_cpus : 0 xen_major : 4 xen_minor : 1 xen_extra : .3 xen_caps : xen-3.0-x86_64 xen-3.0-x86_32p hvm-3.0-x86_32 hvm-3.0-x86_32p hvm-3.0-x86_64 xen_scheduler : credit xen_pagesize : 4096 platform_params : virt_start=0xffff800000000000 xen_changeset : unavailable xen_commandline : placeholder cc_compiler : gcc version 4.7.2 20120921 (Red Hat 4.7.2-2) (GCC) cc_compile_by : mockbuild cc_compile_domain : [unknown] cc_compile_date : Sun Oct 28 23:08:22 UTC 2012 xend_config_format : 4
Configuring the network
Method 1: The VMs and the host form a private network
If the computer has no wired NIC, such as a laptop that only has wireless network, a dummy device may be helpful. I also show the script I used on my laptop here.
#!/bin/bash # set up a bridge as the backed device for xen brctl addbr xenbr0 # set up a dummy device modprobe dummy ip link set name xendummy0 dev dummy0 brctl addif xenbr0 xendummy0 # give the bridge an IP ifconfig xenbr0 10.0.0.2 # set its netmask ifconfig xenbr0 netmask 255.255.0.0 # set up NAT and make the Domain-0 acts as a gateway # You may change this rule for better security iptables -I FORWARD -j ACCEPT iptables -t nat -I POSTROUTING --out-interface wlan0 -j MASQUERADE echo 1 > /proc/sys/net/ipv4/ip_forward
Method 2: bridged networking
NetworkManager does not work with bridge currently. To use bridge-based network for Xen. We should change the network management service from NetworkManager to network. The networking configuration is stored in ‘/etc/sysconfig/network-scripts/’.
To disable NetworkManager and start network, do the following:
# systemctl disable NetworkManager.service # systemctl restart network.service
Make sure that the network service is automatically started by:
# chkconfig network on
Then, we can create the configuration file for the bridge. Let’s call the bridge ‘xenbr0’.
Edit ‘/etc/sysconfig/network-scripts/ifcfg-xenbr0’ (we assume dhcp here. You can also give the bridge a static IP as for the other network devices.):
DEVICE=xenbr0 TYPE=Bridge ONBOOT=yes DELAY=0 NM_CONTROLLED=no BOOTPROTO=dhcp
Then find the configuration file for your existing network adaptor (e.g. ifcfg-em1) and edit it as follows.
Finally, make the network configuration take effect by:
# systemctl restart network.service
As I have stated, the network configuration should be done by the administrator according to the Linux distro’s method. On Fedora, we use NetworkManager as it is. In this tutorial, we set up bridge-based network for xen. This method works well not only for wired network but also wireless network. I make all the steps together into one script as follows:
#!/bin/bash # set up a bridge as the backed device for xen brctl addbr xenbr0 # bridge to eth0 brctl addif xenbr0 eth0 # bring up the bridge ifconfig xenbr0 up
In this script, we first set up the bridge xenbr0 for xen and bridge it to eth0 which is the real NIC device. Then, we can set up Domain-U to use this bridge as the backed to set up its network.
You can make Linux run this this script each time the system is booted by adding ‘@reboot /path/to/the/script.sh’ to cron jobs through ‘crontab -e’ or setting up a new service to invoke this script.
One example Dom-U configuration file
I give one example Domain-U configuration file here as follows.
name="10.1.0.114" vcpus=2 memory=2048 disk=['phy:/dev/vg_xen/vm-10.1.0.114,xvda,w'] vif=['bridge=xenbr0'] bootloader="/usr/bin/pygrub" on_reboot="restart" on_crash="restart" # extra="single"
Most of the old ‘xm’ commands for Domain-U management work under ‘xl’ by just simply replacing ‘xm’ with ‘xl’.