Installing and Configuring Xen Hypervisor on Debian/Ubuntu: Type-1 Virtualization with XL Toolstack and Dom0

Virtualization tutorial - IT technology blog
Virtualization tutorial - IT technology blog

Why Try Xen When You Already Have KVM and Proxmox?

I run a homelab on Proxmox VE managing 12 VMs and containers — it’s my playground for testing everything before pushing to production. Proxmox is great, the web UI is convenient, but sometimes I need a deeper understanding of “real” virtualization architecture — and that’s where Xen Hypervisor comes in.

Architecturally, Xen runs directly on hardware as a Type-1 hypervisor — no Linux kernel needed as a host. Your Linux kernel instead runs inside Dom0, a privileged domain with hardware access that coordinates all other VMs. AWS EC2 built its entire first generation (2006–2017) on Xen before migrating to Nitro — so this isolation model is anything but theoretical.

Core Concepts to Understand First

Dom0, DomU, and the Xen Hypervisor

  • Xen Hypervisor: A thin layer sitting between the hardware and all domains — this is the “real hypervisor”
  • Dom0 (Domain-0): The privileged VM running a Xen-enabled Linux kernel, managing hardware drivers and coordinating DomUs
  • DomU (Domain-U): Regular virtual machines running alongside Dom0, with no direct hardware access

PV, HVM, and PVH

  • PV (Paravirtualization): Guest kernel is patched to communicate directly with Xen — high performance, but requires a supported kernel
  • HVM (Hardware Virtual Machine): Uses Intel VT-x/AMD-V like KVM, runs unpatched operating systems
  • PVH: The most modern mode, combining the best of both — recommended for new Linux guests

XL Toolstack

XL is the default toolstack since Xen 4.x, replacing the older xm. It uses libxl and xenstore as its backend — simple syntax, no background daemon like xend required.

Installing Xen on Debian/Ubuntu

Check Prerequisites First

Verify three things before starting: whether your CPU has Intel VT-x or AMD-V, whether you have at least 4GB of RAM (8GB+ is more comfortable since Dom0 needs ~2GB on its own), and whether you’re running Debian 11/12 or Ubuntu 22.04/24.04.

# Check CPU virtualization support
egrep -c '(vmx|svm)' /proc/cpuinfo
# A result greater than 0 means your CPU qualifies

Install Xen Hypervisor and Dom0 Kernel

sudo apt update && sudo apt upgrade -y

# This package installs everything at once: hypervisor + Dom0 kernel + xl toolstack
sudo apt install -y xen-system-amd64

# After reboot, confirm Xen is running
xl info | grep xen_version

A single command pulls in all three components: xen-hypervisor-* is the main hypervisor, linux-image-*-amd64-xen is the special Dom0 kernel, and xen-utils-* bundles the xl toolstack along with supporting tools. No need to install each package manually.

Make Sure GRUB Boots into Xen

# Check Xen entries in GRUB — note the exact entry name
grep -i xen /boot/grub/grub.cfg | grep menuentry

# Set Xen as default (replace the entry name to match the output above)
sudo sed -i 's/GRUB_DEFAULT=.*/GRUB_DEFAULT="Xen 4.17-amd64"/' /etc/default/grub
sudo update-grub
sudo reboot

Configuring Dom0 and Creating Your First VM

Limit Dom0 RAM — An Important Tip

This is something many newcomers overlook: by default, Dom0 will consume all available RAM, leaving nothing for DomUs. You need to cap it:

sudo nano /etc/default/grub
# Add this line to the file
GRUB_CMDLINE_XEN_DEFAULT="dom0_mem=2048M,max:2048M"
sudo update-grub
sudo reboot

# Confirm Dom0 is only using 2GB
xl info | grep free_memory

Configure a Network Bridge for DomU

sudo apt install -y bridge-utils
sudo nano /etc/network/interfaces
auto lo
iface lo inet loopback

auto eth0
iface eth0 inet manual

auto xenbr0
iface xenbr0 inet dhcp
    bridge_ports eth0
    bridge_stp off
    bridge_fd 0
sudo systemctl restart networking
brctl show    # Confirm the xenbr0 bridge was created

Create Your First DomU with an XL Config File

sudo mkdir -p /etc/xen/vms /var/lib/xen/images

# Create a 20GB disk image (sparse, saves actual disk space)
sudo apt install -y qemu-utils
sudo qemu-img create -f raw /var/lib/xen/images/debian-test.img 20G

# Write the DomU configuration file
sudo nano /etc/xen/vms/debian-test.cfg
# /etc/xen/vms/debian-test.cfg
name        = "debian-test"
type        = "pvh"           # PVH mode — the most modern and efficient
memory      = 1024            # MB
vcpus       = 2
disk        = ['file:/var/lib/xen/images/debian-test.img,xvda,w']
vif         = ['bridge=xenbr0']
kernel      = "/boot/vmlinuz"
ramdisk     = "/boot/initrd.img"
extra       = "root=/dev/xvda1 ro console=hvc0"
on_poweroff = 'destroy'
on_reboot   = 'restart'
on_crash    = 'restart'

Two things to keep in mind when using PVH/PV mode: First, the kernel and ramdisk paths point to files on Dom0, not inside the guest image. I spent over an hour debugging this the first time. Second, the disk image needs an OS installed beforehand (use debootstrap or copy from an existing image) — this .cfg file is for booting an already-installed guest, not for performing a fresh installation.

Day-to-Day VM Management with XL

# Boot a DomU from its config file
xl create /etc/xen/vms/debian-test.cfg

# List all running domains (Dom0 is always domain 0)
xl list

# Connect to the DomU console — exit with Ctrl+]
xl console debian-test

# Real-time stats (like top but for Xen domains)
xl top

# Graceful shutdown (sends ACPI signal)
xl shutdown debian-test

# Force kill immediately
xl destroy debian-test

Hot-Plug CPU and Memory — One of Xen’s Best Features

Change resources for a running DomU without rebooting — this is my favorite thing about Xen:

# Scale vCPUs from 2 to 4 for a running domain
xl vcpu-set debian-test 4

# Increase memory to 2GB (guest must have balloon driver installed)
xl mem-set debian-test 2048

# View current vCPU allocation
xl vcpu-list

Use LVM Instead of Raw Images — Best Practice for Production

Raw images are fine for a lab. But if you need snapshots — and in production you always do — switch to LVM:

# Create a 20GB Logical Volume for the DomU
sudo lvcreate -L 20G -n debian-test vg0

# Update the disk line in the .cfg file
# disk = ['phy:/dev/vg0/debian-test,xvda,w']

# Snapshot the LV before a system update
sudo lvcreate -L 2G -s -n debian-test-snap /dev/vg0/debian-test

Basic Troubleshooting

# View Xen hypervisor log
sudo xl dmesg | tail -50

# Inspect xenstore
sudo xenstore-ls /local/domain/

# Check free memory available for DomUs
xl info | grep free_memory

# systemd log for the xendomains service
sudo journalctl -u xendomains --since "1 hour ago"

Conclusion: Is Xen Worth Learning?

Honest take: I still use Proxmox every day. When managing 12 VMs, nothing beats its web UI. But one week with Xen taught me more than months of clicking around the Proxmox dashboard. There are clear use cases where Xen still wins:

  • Security research and strict isolation: Dom0/DomU separation is the standard in much of the security research community
  • Cloud infrastructure: Understanding Xen helps you understand how cloud providers build their infrastructure
  • Deterministic latency: A thinner hypervisor layer than the Linux kernel — important for latency-sensitive workloads

Going from zero to a running DomU takes about 30–60 minutes on Debian 12. The XL toolstack covers most use cases. Add LVM snapshots and it’s production-ready. If you’re learning virtualization from an architectural perspective — not just using a tool — Xen is worth spending a weekend on.

Share: