Skip to content

Instantly share code, notes, and snippets.

@MatiasVara
Last active December 9, 2022 13:16
Show Gist options
  • Save MatiasVara/000cfd836ac4413379493e9c0837407b to your computer and use it in GitHub Desktop.
Save MatiasVara/000cfd836ac4413379493e9c0837407b to your computer and use it in GitHub Desktop.
This gist explains how to build Linux and deploy it as a Xen HVM guest by using xl

Introduction

This gist aims at building Linux from source-code and deploying it as HVM guest in Xen by using xl.

Building Linux

We use v5.10.17 tag (13b6016). We first build .config by issuing:

make localmodconfig

To enable debug symbols, you can set:

CONFIG_DEBUG_INFO_NONE=y

We have to create a minimal initramfs, we do it by following https://landley.net/writing/rootfs-howto.html. The initramfs_list is:

dir /dev 755 0 0
nod /dev/console 644 0 0 c 5 1
nod /dev/tty0 644 0 0 c 4 0
nod /dev/hvc0 644 0 0 c 229 0
file /init usr/hello 755 0 0

This creates a initramfs that includes a simple Hello World (It must be statically compiled!). We compile by using:

make vmlinux

Deploy it as a HVM guest

To deploy as a guest, we copy vmlinux (uncompressed linux image) and the following cfg in Xen:

extra="console=hvc0 earlyprintk=xen initcall_debug debug"
kernel="/home/pepo/vmlinux"
memory=1024
vcpus=1
name="myguest"
# store dump if crash or poweroff
# in /var/lib/xen/dump/NAME 
on_crash="coredump-destroy"
on_poweroff="coredump-destroy"

To create the guest, we issue:

xl create -f linux.cfg -c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment