Howto Xen 4.4 on Debian Jessie at Hetzner

Introduction

This instructions are for base installation of Xen hypervisor on Debian Wheezy/Jessie server on Hetzner root server.
First we are going to install useful linux tools.
After installation and configuration of Xen on Debian, we are doing the network setup with IPv4 and IPv6. There is a difference wheter you buy a IP address subnet or single additional IP address – espacially if you are dependent on IPv4 (as we all are, actually).

Several useful information are collected in the Hetzner wiki: German English

For beginners:
Dom0 is the hypervisor host.
DomU is an instance of a “virtual machine“.

Xen Management

See my blog post for thoughts about how to manage Xen DomU.

Base installation of Hetzner Server

First we need to chose a hostname scheme if you are planning to setup further server.
A name for the hypervisor host is needed and some domain name scheme for easy handling all the DomU.

Suggestion for naming scheme:
*(brand)*-*(tst|stg|live)*-*(0..999)*.domain.tld

Make sure you set a proper hostname.
Example configuration for the hetzner image installer (chose Debian):

DRIVE1 /dev/sda
DRIVE2 /dev/sdb
SWRAID 1
SWRAIDLEVEL 1
BOOTLOADER grub
HOSTNAME XXXXXXXX
PART /boot ext2 512M
PART lvm vg0 all
LV vg0 root / ext4 40G
LV vg0 swap swap swap 8G
LV vg0 tmp /tmp reiserfs 10G
LV vg0 var /var ext4 20G
LV vg0 web /web ext4 20G
IMAGE /root/.oldroot/nfs/install/../images/Debian-XX-XXXXX-64-minimal.tar.gz

Upgrade to Debian Jessie

Debian wheezy is current stable and can be chosen during automatic install.
As Debian Jessie is the next upcoming Debian stable and is freezed for months, it is worth considering to go since there is Xen 4.4 available.
We like to make use of Xen 4.4 which comes with Jessie.

This guide is based on Debian Jessie.

sed -i 's/wheezy/jessie/' /etc/apt/sources.list

apt-get update
apt-get dist-upgrade

Install packages

Following tools might be useful for monitoring and analysis of several problems.

iotop  - input output monitoring
iftop  - network stats in top layout
htop   - enhanced top task list
screen - attachable/detachable virtual terminals
psmisc - pstree and few utils

Install these helpful tools

apt-get update
apt-get -y install iotop iftop htop screen psmisc
apt-get autoremove

Free some performance

Activate the performance mode, default is on-demand. But who wants to wait for cpu core to speed up?

sed -i '/GOVERNOR/s/=.*/="performance"/' /etc/default/cpufrequtils

Install Xen packages

Install base packages and kernel. For kernel replacement use the dpkg-divert command.

apt-get -y install xen-linux-system xen-tools
# switch boot order
dpkg-divert --divert /etc/grub.d/08_linux_xen --rename /etc/grub.d/20_linux_xen
# write changes to grub
update-grub
# cross fingers
reboot

 Set default Xen toolstack

sed -i '/TOOLSTACK/s/=.*/=xl/' /etc/default/xen

Configure xend

For those having used xen in the past: Forget about it. xend is depricated. See http://wiki.xen.org/wiki/MigrationGuideToXen4.1%2B#Toolstack_upgrade_notes

Tune Dom0 memory and cpu

The
Insert into /etc/default/grub

GRUB_CMDLINE_XEN_DEFAULT="dom0_mem=1024M,max:1024M dom0_max_vcpus=1 dom0_vcpus_pin"

And execute update-grub. A reboot is neccessary.

Create xen-tools configuration

Set default values for xen-create-image.

lvm = vg0                                               # volume group created during install
install-method = debootstrap                            # debian install routine
size   = 10Gb                                           # disk image size
memory = 2G                                             # memory size
swap   = 2G                                             # swap size
noswap = 1                                              # disable swap
fs     = ext4                                           # use ext4 as default file system
dist   = `xt-guess-suite-and-mirror --suite`            # default distribution to install
image  = sparse                                         # sparse vs. full disk images
gateway    = X.X.X.X                                    # gateway, that dom0 is also using with bridge
netmask    = 255.255.255.0                              # netmask, may vary
broadcast  = 10.0.9.255                                 # broadcast, usually last ip address in range
bridge = xenbr0                                         # xen bridge to physical eth0 on host
cachedir = /var/cache/xen-tools/archives/               # cache path for debootstrap deb files
passwd = 0                                              # asks for a root password during debootstrap
kernel = /boot/vmlinuz-`uname -r`                       # same kernel as dom0
initrd = /boot/initrd.img-`uname -r`                    # same initrd as dom0
mirror = `xt-guess-suite-and-mirror --mirror`           # chose right mirror
mirror = http://ftp.de.debian.org/debian/                # debian mirror
ext4_options     = noatime,nodiratime,errors=remount-ro # ext4 default
ext3_options     = noatime,nodiratime,errors=remount-ro # ext3 default
ext2_options     = noatime,nodiratime,errors=remount-ro # ext2 default
xfs_options      = defaults                             # xfs default
reiserfs_options = defaults                             # reiserfs default
btrfs_options    = defaults                             # btrfs default
boot = 1                                                # create domU immediately after creation and launch it
output = /etc/xen/config.d                              # domU config path<br>extension = .cfg                                        # domU config extension

 Create domU config path

The config files of virtual machines are going to its own directory. Thus create this path and modify the configuration of xen-tools.conf above.

mkdir -p /etc/xen/config.d

Setup network

According to the official documentation network setup is not done by toolstack xl.
We are going to configure it on our own.

This setup covers:

  • xenbr0: network bridge for internet IPv4 (server services)
  • xenbr1: network bridge for internal network (IPv4 private, add IPv6 later)
  • IPv6 based on Hetzners custom infrastructure

Modify /etc/network/interfaces :

# loopback
auto lo
iface lo inet loopback

# physical network interface
auto  eth0
iface eth0 inet manual

# bridge public
auto xenbr0
iface xenbr0 inet static
  address   X.X.X.X
  broadcast ?.?.?.?
  netmask   255.255.255.224
  gateway   Z.Z.Z.Z
  bridge_ports eth0
  bridge_stp off       # disable Spanning Tree Protocol
  bridge_waitport 0    # no delay unless port available
  bridge_fd 0          # no forwarding delay

# bridge internal
auto xenbr1
iface xenbr1 inet static
  address   10.0.10.1
  broadcast 10.0.10.255
  netmask   255.255.255.0
  pre-up brctl addbr xenbr1

# ipv6
iface eth0 inet6 static
  address Y:Y:Y:Y::2
  netmask 64
  gateway fe80::1

Continue with setup xen vm template.

Alternatives

Interesting sources concerning Xen and virtualization:

4 thoughts on “Howto Xen 4.4 on Debian Jessie at Hetzner

  1. Hello, helpful post
    I have the following problem trying it locally inside a vmware, and online at my hetzner clean server.
    Dom0 and DomU cannot ping each other.
    ex.
    xenbr1 : ip 10.0.10.1
    guest : ip 10.0.10.2

    Please advise.
    Thanks in advance.

  2. Hello,
    thank you for your article, for the moment, it is not easy to find informations about xen+jessie!
    I face a problem with the network configuration:
    as explained, I set my public IP on xenbr0 and it works only if I comment the xenbr1 block. Otherwise, I just cannot ping or ssh my Dom0 (which is quite annoying since it is a dedicated server so I cannot access it physically…)
    Any idea why the xenbr1 block could cause network troubles?
    In syslog, I can see those lines:
    May 15 09:52:52 mx-02 networking[361]: Configuring network interfaces…/etc/network/interfaces:27: misplaced option
    May 15 09:52:52 mx-02 networking[361]: ifquery: couldn’t read interfaces file “/etc/network/interfaces”
    May 15 09:52:52 mx-02 networking[361]: /etc/network/interfaces:27: misplaced option
    May 15 09:52:52 mx-02 networking[361]: failed.

    Line 27 is :
    address 10.0.10.1

    Thanks!

    1. maybe you have just fix the problem but the error says :”/etc/network/interfaces:27: misplaced option”. This mean that in your’s interfaces file at line 27 there is some error.

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.