How to Install Xen Hypervisor on Debian 9 “Stretch” and Debian 8 “Jessie” Linux Systems

undefined

In this article, we will discuss the installation of Xen hypervisor server on Linux systems (Debian Family “Debian 9 “Stretch” and Debian 8 “Jessie” /Ubuntu 14.04, and higher”). The following steps worked on Debian 9 “stretch” and the result was installing xen 4.8 on Debian 9. For Debian 8 “Jessie” the only difference you’ll find is the version of Xen hypervisor which will be Xen 4.4 or 4.6, but As I’m not specifying the versions of xen on my commands, the following commands will work find on Debian 9/8 and may be Ubuntu 16.04/14.04 Linux systems.

The Xen Project hypervisor is an open-source type-1 or baremetal hypervisor, which makes it possible to run many instances of an operating system or indeed different operating systems in parallel on a single machine (or host). The Xen Project hypervisor is the only type-1 hypervisor that is available as open source. It is used as the basis for a number of different commercial and open source applications, such as: server virtualization, Infrastructure as a Service (IaaS), desktop virtualization, security applications, embedded and hardware appliances. The Xen Project hypervisor is powering the largest clouds in production today.

Requirements:

There are no requirements for installing Xen hypervisor, but only some general points to take into consideration:

  • Install Xen on 64 bit Linux systems, 32 bit it too old these days
  • Disk partition layout is very important since this will have an impact on the disk configurations available to the guests. 

  • Ensure that your Linux machine has suitable amount of ram for guests vms.

Let’s Install Xen hypervisor through the following steps:

Step 1: Install Xen and Xen-Tools

The installation is very direct and simple, but first I prefer to use the root account not sudo, run the following command “or you’ll use sudo in each command”:

$ sudo su -

Now, run the following commands to install the two needed packages xen and xen-tools:

# apt-get update
# apt-get -y install xen-hypervisor-4.8-amd64 xen-tools

This will install all the additional packages needed by the xen hypervisor on Debian 9. For Debian 8 you may not find xen 4.8 available in your repository, just install the available version 4.4 or higher.

Step 2: Configure Grub to Switch the Boot Order

Before do any other configuration to the installed xen hypervisor, you must configure the grub to switch the boot order. This very important as in some cases after you reboot your machine doesn’t come back and lose all your work, run the following command to switch the boot order:

# dpkg-divert --divert /etc/grub.d/08_linux_xen --rename /etc/grub.d/20_linux_xen
Adding 'local diversion of /etc/grub.d/20_linux_xen to /etc/grub.d/08_linux_xen'

Now, update the grub to apply your changes, run the following command:

# update-grub
Including Xen overrides from /etc/default/grub.d/xen.cfg
WARNING: GRUB_DEFAULT changed to boot into Xen by default!
 Edit /etc/default/grub.d/xen.cfg to avoid this warning.
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-4.9.0-3-amd64
Found initrd image: /boot/initrd.img-4.9.0-3-amd64
Found linux image: /boot/vmlinuz-4.9.0-3-amd64
Found initrd image: /boot/initrd.img-4.9.0-3-amd64
Found linux image: /boot/vmlinuz-4.9.0-3-amd64
Found initrd image: /boot/initrd.img-4.9.0-3-amd64
done

Now, run this command to check the the grub boot order is correct, the first line should be ” 0 menuentry ‘Debian GNU/Linux, with Xen hypervisor’

# grep -i "menuentry '" /boot/grub/grub.cfg|sed -r "s|--class .*$||g"|nl -v 0
 0 menuentry 'Debian GNU/Linux, with Xen hypervisor' 
 1 menuentry 'Debian GNU/Linux, with Xen 4.8-amd64 and Linux 4.9.0-3-amd64' 
 2 menuentry 'Debian GNU/Linux, with Xen 4.8-amd64 and Linux 4.9.0-3-amd64 (recovery mode)' 
 3 menuentry 'Debian GNU/Linux, with Xen 4.8-amd64.efi and Linux 4.9.0-3-amd64' 
 4 menuentry 'Debian GNU/Linux, with Xen 4.8-amd64.efi and Linux 4.9.0-3-amd64 (recovery mode)' 
 5 menuentry 'Debian GNU/Linux' 
 6 menuentry 'Debian GNU/Linux, with Linux 4.9.0-3-amd64' 
 7 menuentry 'Debian GNU/Linux, with Linux 4.9.0-3-amd64 (recovery mode)'

Perfect!, the boot order is set to the xen hypervisor. Now, reboot your Linux machine:

# reboot

Step 3: Checks and Configuration Tweaks

Now, I suppose that your Machine started normally after the last reboot. To check that Xen successfully installed and UP run the following commands:

# xl info
host : octopus
release : 4.9.0-3-amd64
version : #1 SMP Debian 4.9.30-2+deb9u2 (2017-06-26)
machine : x86_64
nr_cpus : 8
max_cpu_id : 7
nr_nodes : 1
cores_per_socket : 4
threads_per_core : 2
cpu_mhz : 3600
hw_caps : b7ebfbff:77faf3ff:2c100800:00000121:0000000f:009c6fbf:00000000:00000100
virt_caps : hvm hvm_directio
total_memory : 65329
free_memory : 128
sharing_freed_memory : 0
sharing_used_memory : 0
outstanding_claims : 0
free_cpus : 0
xen_major : 4
xen_minor : 8
xen_extra : .1
xen_version : 4.8.1
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 : 
xen_commandline : placeholder
cc_compiler : gcc (Debian 6.3.0-16) 6.3.0 20170425
cc_compile_by : ian.jackson
cc_compile_domain : eu.citrix.com
cc_compile_date : Tue May 2 14:06:04 UTC 2017
build_id : 0b619fa14fca0e6ca76f2a8b52eba64d60aa37de
xend_config_format : 4

Again, our xen server is up, the above command is very important as it shows more details about the server’s specs. I highlighted the important details in brown. I’m using 64 bit OS, 8 VCPU, and total 64 GB of ram.

Now, we list the running guest xen vms, yes we’ll find only dom0 as we didn’t create any guests, run the following command:

# xl list
Name     ID   Mem    VCPUs State  Time(s)
Domain-0 0    64357  8     r----- 6.8

As you see, our domain 0 is using all the available ram “64 GB in our case” and uses all cpus. This amount of memory and cpu are shared among dom0 and all domU (guests). Here’s comes our configuration tweaks. We need to tweak the memory and cpu assigned to dom0 and force dom0 to use dedicated amount of RAM and certain number of CPU for better performance:

Step 3.1: Configure Domain 0 Memory AND CPUs

By default on a Xen system the majority of the hosts memory is assigned to dom0 on boot and dom0’s size is dynamically modified (“ballooned”) automatically in order to accommodate new guests which are started. However on a system which is dedicated to running Xen guests it is better to instead give dom0 some static amount of RAM and to disable ballooning.

By default all CPUs are shared among dom0 and all domU (guests). It may broke dom0 responsibility if guests consume too much CPU time. To avoid this, it is possible to grant one (or more) processor core to dom0 and also pin it to dom0.

Here we will assign 4 GB of ram to dom0 and one CPU. The following commands will do this task:

# echo 'GRUB_CMDLINE_XEN="dom0_mem=4096M,max:4096M dom0_max_vcpus=1 dom0_vcpus_pin"' >> /etc/default/grub

This command updates grub configuration, and assign dedicated resources to dom0, yes we have to update grub and reboot the machine but this will be after the next modification.

Now, edit/create /etc/xen/xend-config.sxp to configure the toolstack to match by changing/adding the following settings:

(dom0-min-mem 4096)
(enable-dom0-ballooning no)
(dom0-cpus 1)

Find the above lines and change their values to the above values. If /etc/xen/xend-config.sxp not exists do not panic, just create it and add the above three lines to it.

Now, update the grub to apply your changes, run the following command:

# update-grub
Including Xen overrides from /etc/default/grub.d/xen.cfg
WARNING: GRUB_DEFAULT changed to boot into Xen by default!
 Edit /etc/default/grub.d/xen.cfg to avoid this warning.
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-4.9.0-3-amd64
Found initrd image: /boot/initrd.img-4.9.0-3-amd64
Found linux image: /boot/vmlinuz-4.9.0-3-amd64
Found initrd image: /boot/initrd.img-4.9.0-3-amd64
Found linux image: /boot/vmlinuz-4.9.0-3-amd64
Found initrd image: /boot/initrd.img-4.9.0-3-amd64
done

Perfect!, the boot order is set to the xen hypervisor. Now, reboot your Linux machine:

# reboot

Now, I suppose that your Machine started normally after the last reboot. To check that Xen correctly configured, run the following commands:

# xl list
Name     ID   Mem   VCPUs  State   Time(s)
Domain-0 0    4096  1      r-----  3.6

As you see, now dom0 uses 4GB and one dedicated cpu. To continue reading this article, check the next page

Step 4: Configure Xen-Tools

Soon will be completed.

Summary

I hope this article is good enough for you.
See you in other articles.

undefined

If You Appreciate What We Do Here On Mimastech, You Should Consider:

  1. Stay Connected to: Facebook | Twitter | Google+
  2. Support us via PayPal Donation
  3. Subscribe to our email newsletters.
  4. Tell other sysadmins / friends about Us - Share and Like our posts and services

We are thankful for your never ending support.

Leave a Reply

Your email address will not be published. Required fields are marked *