Xen Hypervisor with Ubuntu
In the past, I ran all my VMs using KVM and libvirt but was never completely happy with it. So when a colleague told me about Xen I thought I needed to check it out.
I found out that Xen is way easier than KVM so to create VMs you just need a simple config file a the command line.
In this Post, I will describe how I run Xen on Ubuntu a what my setup looks like.
If you know nothing or not a lot about Xen, you should start with Xen Project Beginners Guide from the Xen Wiki. Nearly everything you need to know about Xen can be found there.
Before you can install Xen you need to setup Ubuntu. Just install Ubuntu as you know but at the partitioning step think or research how you want to run your VMs. Xen can use LVM Volumes as VM Disks which have the benefit of a better performance and features like snapshots. So if you want to use LVM, you need to setup Ubuntu with LVM. If you do not want to use LVM, Xen can also use Disk Images.
After Ubuntu is installed, you need to create a bridge interface that your VMs can use. Below you can see my netplan config. You need to disable dhcp4 (and maybe dhcp6) because the interface will be used in the bridge. Than add the bridge with the name of your interface.
# /etc/netplan/50-cloud-init.yaml
network:
ethernets:
enp3s0:
dhcp4: no
bridges:
xenbr0:
dhcp4: yes
interfaces: [enp3s0]
version: 2
After you have finished editing the file, the netplan config must be applied.
sudo netplan try
The next and also last step is to install Xen and ipxe-qemu if you want to run an HVM guest. Xen has ā2ā modes to run VMs, HVM are fully virtualized VMs and PV are paravirualized VMs that are more lightweight and faster. For more details about the differences look at Understanding the Virtualization Spectrum also from the Xen Wiki. I run PVH with Linux guests and PVHVM with OpenBSD guests.
sudo apt install xen-system-amd64 ipxe-qemu
sudo reboot
Xen creates its own Grub entry because it runs a microkernel that must be booted. Xen starts our Ubuntu installation as the Management VM or Domain0 or Dom0 which is a privileged VM that is needed to manage Xen.
I hope you now have a running Xen Hypervisor with Ubuntu. I plan to release more posts about Xen in the future. I already planned to write one about OpenBSD/Linux VMs and passing a GPU to a VM.
15 February 2025 - Philipp Keschl