Build xen-hypervisor 4.16 and xen-tools on Ubuntu 22.04 / 20.04 / 18.04 for PVH from source

Posted by kelly on Fri, 06/10/2022 - 15:05

To get latest version to protect your system or use zstd-compressed Kernels you can build your xen-hypervisor from source.

This howto based on this official howto.

Updated for Ubuntu 22.04: Boot with pygrub and xen-tools (2022-08-18)

Updates for Ubuntu 22.04: Added build dependencies (2022-06-10)

Updated to xen 4.16: Added ninja-build to build environment (2021-12-16)

Updates to xen 4.15: Added libzstd1-dev / libzstd-dev for zstd-compressed Kernels.

Xen-Hypervisor

Install requirements for build

For Ubuntu 22.04:

apt-get -qq install build-essential
apt-get -qq install bcc bin86 gawk bridge-utils iproute2 libcurl4 libcurl4-openssl-dev bzip2 kmod transfig tgif pkg-config
apt-get -qq install texinfo texlive-latex-base texlive-latex-recommended texlive-fonts-extra texlive-fonts-recommended libpci-dev mercurial
apt-get -qq install make gcc libc6-dev zlib1g-dev python-all python-all-dev python3-twisted libncurses5-dev patch libvncserver-dev libsdl1.2-dev libjpeg-dev
apt-get -qq install python3-dev libglib2.0-dev
apt-get -qq install libnl-3-dev libnl-cli-3-dev libnl-genl-3-dev libnl-route-3-dev libnl-idiag-3-dev libnl-xfrm-3-dev
apt-get -qq install iasl libbz2-dev e2fslibs-dev git-core uuid-dev ocaml ocaml-findlib ocamlbuild libx11-dev bison flex xz-utils libyajl-dev
apt-get -qq install gettext libpixman-1-dev libaio-dev markdown pandoc iasl cmake figlet
 
apt-get -qq install libssh2-1-dev libssh-dev libsnappy-dev
apt-get -qq install libc6-dev-i386
apt-get -qq install lzma lzma-dev liblzma-dev
apt-get -qq install libsystemd-dev
 
apt-get -qq install libzstd-dev
apt-get -qq install ninja-build

For Ubuntu 20.04

apt-get -qq install build-essential
apt-get -qq install bcc bin86 gawk bridge-utils iproute2 libcurl4 libcurl4-openssl-dev bzip2 kmod transfig tgif pkg-config
apt-get -qq install texinfo texlive-latex-base texlive-latex-recommended texlive-fonts-extra texlive-fonts-recommended libpci-dev mercurial
apt-get -qq install make gcc libc6-dev zlib1g-dev python python-dev python3-twisted libncurses5-dev patch libvncserver-dev libsdl-dev libjpeg-dev
apt-get -qq install python3-dev libglib2.0-dev
apt-get -qq install libnl-3-dev libnl-cli-3-dev libnl-genl-3-dev libnl-route-3-dev libnl-idiag-3-dev libnl-xfrm-3-dev
apt-get -qq install iasl libbz2-dev e2fslibs-dev git-core uuid-dev ocaml ocaml-findlib ocamlbuild libx11-dev bison flex xz-utils libyajl-dev
apt-get -qq install gettext libpixman-1-dev libaio-dev markdown pandoc iasl cmake figlet
 
apt-get -qq install libc6-dev-i386
apt-get -qq install lzma lzma-dev liblzma-dev
apt-get -qq install libsystemd-dev
 
apt-get -qq install libzstd-dev
apt-get -qq install ninja-build

For Ubuntu 18.04:

apt-get -qq install build-essential
apt-get -qq install bcc bin86 gawk bridge-utils iproute2 libcurl4 libcurl4-openssl-dev bzip2 module-init-tools transfig tgif
apt-get -qq install texinfo texlive-latex-base texlive-latex-recommended texlive-fonts-extra texlive-fonts-recommended pciutils-dev mercurial
apt-get -qq install make gcc libc6-dev zlib1g-dev python python-dev python-twisted libncurses5-dev patch libvncserver-dev libsdl-dev libjpeg-dev
apt-get -qq install python3-dev
apt-get -qq install libnl-3-dev libnl-cli-3-dev libnl-genl-3-dev libnl-route-3-dev libnl-idiag-3-dev libnl-xfrm-3-dev
apt-get -qq install iasl libbz2-dev e2fslibs-dev git-core uuid-dev ocaml ocaml-findlib libx11-dev bison flex xz-utils libyajl-dev
apt-get -qq install gettext libpixman-1-dev libaio-dev markdown pandoc iasl cmake figlet
 
apt-get -qq install libc6-dev-i386
apt-get -qq install lzma lzma-dev liblzma-dev
apt-get -qq install libsystemd-dev
 
apt-get -qq install libzstd1-dev
apt-get -qq install ninja-build

Download and prepare and make

We use the latest stable for 4.16

git clone git://xenbits.xen.org/xen.git
cd xen
git checkout origin/stable-4.16

Configure and make

Ubuntu uses systemd:

./configure --enable-systemd

For first make use:

make dist

For new make use make world (same like make clean && make dist).

Get a coffee now.

Install

The install-files are in /dist/install. And you will find an install-script in dist/install.sh. Dont use this script! It will breaks your /var/run-folder.

You can copy the files via cp -a or rsync in your system. Or you may use make debball and install the package from file (I didnt try).

Post-Install

After copying the files you will do some changes in your system:

Reload dynamic libraries:

/sbin/ldconfig

Grub-Settings:

mkdir -p /etc/default/grub.d

Create /etc/default/grub.d/xen.cfg:

vi /etc/default/grub.d/xen.cfg
GRUB_DISABLE_OS_PROBER=true
GRUB_CMDLINE_XEN_DEFAULT="dom0_mem=2560M,max:2560M"
GRUB_DEFAULT="Ubuntu GNU/Linux, mit Xen-Hypervisor"

Be careful! The last settings depends on your system-language! For english use: "Ubuntu GNU/Linux, with Xen hypervisor" - Ubuntu 18.04 does not use the german translation!

You have to update grub:

update-grub

Enable systemd-files:

In the current version is a bug and xendomains.service and /etc/init.d/xendomains are created both. To use systemd you have to remove /etc/init.d/xendomains

rm /etc/init.d/xendomains

 

systemctl enable xen-qemu-dom0-disk-backend.service
systemctl enable xen-init-dom0.service
systemctl enable xenconsoled.service
systemctl enable xenstored.service
systemctl enable xendomains.service

Optional you can enable xen-watchdog.service

systemctl enable xen-watchdog.service

Configure xen

Configure xen for your needs.

xen-tools

For creating new VMs you can use xen-tools. Unfortunately you cannot use the ubuntu-package because it requires xen-hypervisor. So we build from source.

Install requirements for build

apt install lvm2 debootstrap libconfig-inifiles-perl libdata-validate-domain-perl libdata-validate-ip-perl libdata-validate-uri-perl libfile-slurp-perl libfile-which-perl libsort-versions-perl libterm-ui-perl libtext-template-perl openssh-client perl debian-archive-keyring rinse libtest-notabs-perl

Download and prepare and make

git clone https://github.com/xen-tools/xen-tools.git
cd xen-tools
make install

If you want only the install-files (e.g. for build you own package), you can edit the Makefile and manually set the variable DESTDIR before make install.

Adaptions for Ubuntu newer versions incl. 22.02

For newer versions the symlink to artful is missing. Just create symlinks and add the distri to distributions.conf

cd usr/share/xen-tools/
ln -s artful.d bionic.d
ln -s artful.d focal.d
ln -s artful.d jammy.d
echo "bionic      = ubuntu     pygrub" >> etc/xen-tools/distributions.conf
echo "focal       = ubuntu     pygrub" >> etc/xen-tools/distributions.conf
echo "jammy       = ubuntu     pygrub" >> etc/xen-tools/distributions.conf

Ubuntu 22.04 and Grub

Ubuntu 22.04 contains no Grub-1 anymore. So we just add a /boot/grub/menu.lst manually so pygrub can boot.

cat << EO2 > usr/share/xen-tools/artful.d/99-pseudogrub
 
#!/bin/sh
#
#  This script enable boot via pygrub without grub-1.
#

 
prefix=$1
 
#
#  Source our common functions
#
if [ -e /usr/share/xen-tools/common.sh ]; then
    . /usr/share/xen-tools/common.sh
else
    . ./hooks/common.sh
fi
 
#
# Log our start
#
logMessage Script $0 starting
 
mkdir -p ${prefix}/boot/grub
cat << EOF > ${prefix}/boot/grub/menu.lst
 
default         0
timeout         2
 
title           Ubuntu 22.04 LTS
root            (hd0,0)
kernel          /boot/vmlinuz root=/dev/xvda2 ro elevator=noop
initrd          /boot/initrd.img
 
title           Ubuntu 22.04 LTS (Single-User)
root            (hd0,0)
kernel          /boot/vmlinuz root=/dev/xvda2 ro single elevator=noop
initrd          /boot/initrd.img
 
title           Ubuntu 22.04 LTS (Old)
root            (hd0,0)
kernel          /boot/vmlinuz.old root=/dev/xvda2 ro elevator=noop
initrd          /boot/initrd.img.old
 
title           Ubuntu 22.04 LTS (Old, Single-User)
root            (hd0,0)
kernel          /boot/vmlinuz.old root=/dev/xvda2 ro single elevator=noop
initrd          /boot/initrd.img.old
 
EOF
 
#
# Log our finish
#
logMessage Script $0 finished
 
EO2
 
chmod +x usr/share/xen-tools/artful.d/99-pseudogrub 

 

 

 

Configure xen-tools

Configure xen-tools for your needs.

 

Reboot

After reboot you have your Ubuntu on xen-hypervisor.

Test:

xentop

Settings for PVH

For PVH you have to use Linux 4.11 or newer (e.g. HWE-Kernel) in guest:

apt install linux-virtual-hwe-16.04 linux-tools-virtual-hwe-16.04

Then you can use:

bootloader = '/usr/local/bin/pygrub'
type="pvh"

If you have an old kernel in your guest-system, you have to boot from dom0-kernel with this settings:

type="pvh"
kernel='/vmlinuz'
ramdisk="/initrd.img"

 

Systems
Server