Thursday, January 9, 2014

How to install Xen on Ubuntu 12.04 from Source

1) You need to install ubuntu 12.04 (64 bit) on one machine. I am proceeding to next step assuming you have machine with ubuntu installed.
2) Install Xen:
I am going to download Xen source code and going to compile it, for this purpose I need some libraries installed on machine.
Prerequisites are-
    * GCC v3.4 or later
    * GNU Make
    * GNU Binutils
    * Development install of zlib (e.g., zlib-dev)
    * Development install of Python v2.3 or later (e.g., python-dev)
    * Development install of curses (e.g., libncurses-dev)
    * Development install of openssl (e.g., openssl-dev)
    * Development install of x11 (e.g. xorg-x11-dev)
    * Development install of uuid (e.g. uuid-dev)
    * bridge-utils package (/sbin/brctl)
    * iproute package (/sbin/ip)
    * hotplug or udev
    * GNU bison and GNU flex
    * GNU gettext
    * 16-bit x86 assembler, loader and compiler (dev86 rpm or bin86 & bcc debs)
    * ACPI ASL compiler (iasl)

root@dom0$ sudo su
root@dom0$ apt-get install bcc bin86 gawk bridge-utils iproute libcurl3 libcurl4-openssl-dev bzip2 module-init-tools transfig tgif texinfo texlive-latex-base texlive-latex-recommended texlive-fonts-extra texlive-fonts-recommended pciutils-dev mercurial build-essential make gcc libc6-dev zlib1g-dev python python-dev python-twisted libncurses5-dev patch libvncserver-dev 
root@dom0$ apt-get install libsdl-dev libjpeg62-dev iasl libbz2-dev e2fslibs-dev git-core uuid-dev ocaml libx11-dev bison flex xz-utils ocaml-findlib gcc-multilib
Download Xen 4.3.0 source code:
root@dom0# wget http://bits.xensource.com/oss-xen/release/4.3.0/xen-4.3.0.tar.gz
Now we can extract, build and install it:
root@dom0# tar xvf xen-4.3.0.tar.gz
root@dom0# cd xen-4.3.0
root@dom0# make xen
root@dom0# make tools
root@dom0# make stubdom
root@dom0# make install-xen
root@dom0# make install-tools PYTHON_PREFIX_ARG=
root@dom0# make install-stubdom
We should have the following files in ‘/boot’ directory:
/boot/xen.gz
/boot/xen-4.gz
/boot/xen-4.3.gz
/boot/xen-4.3.0.gz
Now, in the file ‘/etc/xen/xend-config.sxp’ we enable the following option:
#(xend-unix-server no) --> (xend-unix-server yes)
3) Compile kernel for Dom0 :
Download kernel from kernel org:
root@dom0# wget http://www.kernel.org/pub/linux/kernel/v3.0/linux-3.8.1.tar.gz
Extract it
root@dom0# tar xvf linux-3.8.1.tar.gz
we can configure our new kernel by running:
We need to set some parameters-
root@dom0# cd linux-3.8.1
root@dom0# make menuconfig

Processor type and features →
    High memory support (64GB)
       PAE (Physical Address Extension) Support - enabled

Processor type and features →
    Allocate 2nd-level pagetables from highmem - disabled

ACPI (Advanced Configuration and Power Interface) Support - enabled

Processor type and features →
     Paravirtualized guest support [y] →
          Xen guest support – enabled

Bus oprions-
     Xen PCI frontend – enabled

Device Drivers → 
     Block Devices [*] → 
           Xen virtual block device support – enabled 
           Block-device backend driver – enabled 

     Network device support [*] → 
           Xen network device frontend driver – enabled 
           Xen backend network device – enabled

     Input device support →
           Miscellaneous devices →
                Xen virtual keyboard and mouse support – enabled

     Character devices →
           Xen Hypervisor console support – enabled

     Xen driver support →
           Xen memory balloon driver – enabled
           Scrub pages before returning them to system – enabled
           Xen /dev/xen/evtchn device Backend driver support – enabled
           Xen filesystem – enabled
           Create compatibility mount point /proc/xen – enabled
           Create xen entries under /sys/hypervisor – enabled
           userspace grant access device driver – enabled
           User-space grant reference allocator driver – enabled
           xen platform pci device driver – enabled
Below, is a list of options needed to compile Linux kernel with dom0 support: (save to ".config")
Modify in config file: ".config"
CONFIG_ACPI_PROCFS=y 
CONFIG_XEN=y 
CONFIG_XEN_MAX_DOMAIN_MEMORY=32 
CONFIG_XEN_SAVE_RESTORE=y 
CONFIG_XEN_DOM0=y 
CONFIG_XEN_PRIVILEGED_GUEST=y 
CONFIG_XEN_PCI=y 
CONFIG_PCI_XEN=y 
CONFIG_XEN_BLKDEV_FRONTEND=y 
CONFIG_XEN_NETDEV_FRONTEND=y 
CONFIG_XEN_KBDDEV_FRONTEND=y 
CONFIG_HVC_XEN=y 
CONFIG_XEN_FBDEV_FRONTEND=y 
CONFIG_XEN_BALLOON=y 
CONFIG_XEN_SCRUB_PAGES=y 
CONFIG_XEN_DEV_EVTCHN=y 
CONFIG_XEN_GNTDEV=y 
CONFIG_XEN_BACKEND=y 
CONFIG_XEN_BLKDEV_BACKEND=y 
CONFIG_XEN_NETDEV_BACKEND=y 
CONFIG_XENFS=y 
CONFIG_XEN_COMPAT_XENFS=y 
CONFIG_XEN_XENBUS_FRONTEND=y 
CONFIG_XEN_PCIDEV_FRONTEND=y
Now, we can build and install the kernel:
user@dom0$ sudo make
root@dom0$ sudo make modules_install
root@dom0$ sudo make install
root@dom0$ cd /boot
root@dom0$ sudo mkinitramfs -o initrd.img-3.7.1 3.7.1
root@dom0$ sudo update-grub
We can now reboot our system to the Xen enabled 3.8.1 Linux kernel. To verify that Xen is running we can do the following:
$ uname -a
> Linux 3.8.1
$ cd /lib/modules/3.8.0-29-generic/kernel/drivers/xen
$ modprobe xen-evtchn 
$ mount -t xenfs none  /proc/xen.
root@dom0$ cat /proc/xen/capabilities
The output must be same as the following line:
control_d
You can manually start xen daemons with-
$ /sbin/ldconfig
service xencommons start

(Modified from http://pravinchavan.wordpress.com/2013/08/14/xen-hypervisor-setup/)