Xen on Debian – how to set it up

  linux, xcp-ng
# Install Xen:

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install xen-system


# Edit interfaces
sudo nano /etc/network/interfaces

# and add the xen bridge:


# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

source /etc/network/interfaces.d/*

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
allow-hotplug eno1

# iface eno1 inet dhcp

#
# XEN setup maybe
#
iface eno1 inet manual
auto xenbr0
iface xenbr0 inet dhcp
   bridge_ports eno1



# Restart networking
/etc/init.d/networking restart
sudo ifconfig

# test that you have internet
ping google.com

# edit grub
sudo nano /etc/default/grub

# add:

# Xen boot parameters for all Xen boots
GRUB_CMDLINE_XEN="dom0_mem=2048M,max:2048M"

# update grub
sudo update-grub

# Edit the xen config:
sudo nano /etc/xen/xend-config.sxp

# add:

(dom0-min-mem 2048)
(enable-dom0-ballooning no)

# then:
sudo nano /etc/xen/xl.conf

# and under:
#autoballoon="auto"

# add this to disable memory balooning
autoballoon="0"


# Next, alocate 1 core to dom0
sudo nano /etc/default/grub

# add:

# alocate 1 cpu core to dom0
dom0_max_vcpus=1 dom0_vcpus_pin

# and

sudo nano /etc/xen/xend-config.sxp

# add:
(dom0-cpus 1)

# update grub
sudo update-grub


# Next install xen tools:

sudo apt-get install xen-tools

# 		Processing triggers for initramfs-tools (0.133) ...
# 		update-initramfs: Generating /boot/initrd.img-4.19.0-5-amd64
# 		W: Possible missing firmware /lib/firmware/bnx2/bnx2-rv2p-09ax-6.0.17.fw for module bnx2
# 		W: Possible missing firmware /lib/firmware/bnx2/bnx2-rv2p-06-6.0.15.fw for module bnx2
# 		W: Possible missing firmware /lib/firmware/bnx2/bnx2-mips-06-6.2.3.fw for module bnx2


# To use a different path where domU images are saved:
sudo nano /etc/xen-tools/xen-tools.conf

# add:

dir = /home/xen/
passwd = 1


# Enable the Xen network bridge by editing

sudo nano /etc/xen/xend-config.sxp
# add this line:
(network-script network-bridge)


# By executing the below command we are moving the hypervisor to a higher 
# priority than default Linux so that it gets the first position in the boot menu.
# per: https://wiki.xenproject.org/wiki/Xen_Project_Beginners_Guide

sudo dpkg-divert --divert /etc/grub.d/08_linux_xen --rename /etc/grub.d/20_linux_xen
sudo update-grub

# if you don't do the above, you should get this error when trying to start an image, ex:
# sudo xl create /etc/xen/registrypublic.cfg
# ERROR:  Can't find hypervisor information in sysfs!



# Restart the server
sudo shutdown -r now

# create your first image
sudo xen-create-image
sudo xen-create-image --hostname registrypublic --ip 10.1.10.101 -vcpus 2 --memory 4096mb --pygrub --dist buster

# Wait a while to create the image, and when you get prompted, enter a root password for the new image.


# start the image:
sudo xl create /etc/xen/registrypublic.cfg



# Then after the reboot try starting the image again:
sudo xl create /etc/xen/registrypublic.cfg

# List your running images:
sudo xen-list-images

# Check the status
sudo xen list

# see everything
sudo xen top

# Get into the image:
sudo xen console registrypublic

# stop the image
sudo xen shutdown registrypublic

# see that it's gone
sudo xen list

# remove it
sudo xen-delete-image registrypublic