Ubuntu // the debootstrap guest flavor (preferred)

You need to do that on an ubuntu host, and you will then be able to migrate the guest to some other XEN dom0s.

Note. the kernel has to be either a freaking custom domU kernel or official Ubuntu XEN kernel. In both cases, NO RAMDISK IS NEEDED.

mkdir -p /data/guests/ubuntu/
cd /data/guests/ubuntu/

dd if=/dev/zero of=ubuntu.ext4 bs=1024k count=0 seek=10240
#mkfs.xfs ubuntu.xfs
mkfs.ext4 ubuntu.ext4
#dd if=/dev/zero of=ubuntu.swap bs=1024k count=0 seek=1024
#mkswap ubuntu.swap
mkdir /tmp/xenloop
mount -o loop ubuntu.ext4 /tmp/xenloop

apt install debootstrap

#dist=xenial
dist=artful
debootstrap $dist /tmp/xenloop
du -sh /tmp/xenloop # artful 302M, 307M - xenial 248M
unset dist

chroot /tmp/xenloop /usr/bin/passwd
echo ubuntu > /tmp/xenloop/etc/hostname
vi /tmp/xenloop/etc/fstab

# <file system> <mount point>   <type>  <options>       <dump>  <pass>
proc            /proc           proc    defaults        0       0
/dev/xvda1       /               xfs    defaults        0       1
#/dev/xvdb1       none            swap    sw             0       0

umount /tmp/xenloop

vi ubuntu

kernel = "/data/kernels/17vmlinuz"
#kernel = "/data/kernels/vmlinuz.4.4.88.domu"
root = "/dev/xvda ro netcfg/do_not_use_netplan=true"
memory = 512
name = "ubuntu"
vcpus = 2
disk = ['tap:tapdisk:aio:/data/guests/ubuntu/ubuntu.ext4,xvda1,w']
vif = [ 'bridge=xenbr0, vifname=ubuntu.0' ]

xl create ubuntu -c

Note. using xvda1 instead of xvda so in case grub gets installed, it will not be able to override anything on any non-existing MBR.

And see Post-Installation section.

For further maintenance,

#xl des ubuntu
#xfs_repair ubuntu.xfs
fsck ubuntu.ext4
mount -o loop ubuntu.ext4 /tmp/xenloop
...
umount /tmp/xenloop

Refs.

Debian/Ubuntu // xen-tools & debootstrap & LVM2

apt install lvm2 xen-tools
pvcreate /dev/sdaX
vgcreate guestsvg /dev/sdaX
vi /etc/xen-tools/xen-tools.conf

lvm = guestsvg
install-method = debootstrap
size = 10Gb
memory = 2Gb
swap = 1Gb
fs = ext4
ext4_options = noatime,nodiratime,errors=remount-ro
dist = `xt-guess-suite-and-mirror --suite`
image = sparse
kernel = /boot/vmlinuz-`uname -r`
initrd = /boot/initrd.img-`uname -r`
pygrub = 1
mirror = `xt-guess-suite-and-mirror --mirror`

ready to build a guest,

guest=GUEST-NAME

xen-create-image --hostname $guest --ip x.x.x.x --netmask x.x.x.x --gateway x.x.x.x --vcpus 2 --dist stretch

vi /etc/xen/$guest.cfg

vif = [ 'script=vif-bridge, bridge=xenbr0' ]

xl create /etc/xen/$guest.cfg -c

Ubuntu guest // the classical full disk guest flavor

Fetch the latest Ubuntu Server XEN guest installer,

rel=artful
mkdir -p /data/kernels/
cd /data/kernels/
wget http://ru.archive.ubuntu.com/ubuntu/dists/$rel/main/installer-amd64/current/images/netboot/xen/vmlinuz
wget http://ru.archive.ubuntu.com/ubuntu/dists/$rel/main/installer-amd64/current/images/netboot/xen/initrd.gz
wget http://ru.archive.ubuntu.com/ubuntu/dists/$rel/main/installer-amd64/current/images/netboot/xen/xm-debian.cfg
mv vmlinuz vmlinuz.$rel
mv initrd.gz initrd.gz.$rel
mv xm-debian.cfg xm-debian.cfg.$rel

target=dbprecise
mkdir -p /data/guests/$target/
cd /data/guests/$target/
dd if=/dev/zero of=$target.disk bs=1024k count=0 seek=10240
cat > $target <<-EOF
kernel = "/data/kernels/vmlinuz.$rel"
ramdisk = "/data/kernels/initrd.gz.$rel"
#root = "/dev/xvda1 ro netcfg/do_not_use_netplan=true"
#kernel = "/usr/local/bin/pygrub"
#kernel = "/usr/lib/xen-4.9/bin/pygrub"
memory = 1024
name = "$target"
vcpus = 4
disk = [ 'tap:aio:/data/guests/$target/$target.disk,xvda,w' ]
vif = [ 'bridge=xenbr0, vifname=$target.0' ]
EOF

xl create $target -c

Provide the right repo on your network as described in the PXEing Ubuntu guide, and use it as a proxy right after defining your nearest official mirror,

proxy URL: http://x.x.x.x:3142

server mode install options e.g.,

install security updates auto
openssh
basic ubuntu server

back to the guest setup (once rebooted after successful installation),

xl destroy $target
cd /data/guests/$target/
vi $target

kernel = "/data/kernels/1710vmlinuz"
#ramdisk = "/data/kernels/1710initrd.gz"
root = "/dev/xvda1 ro netcfg/do_not_use_netplan=true"

xl create $target -c

Ref. https://help.ubuntu.com/community/Xen

Post-Installation

vi /etc/hosts
vi /etc/network/interfaces

auto lo
iface lo inet loopback

auto eth0
iface eth0 inet static
       address x.x.x.x/xx
       gateway x.x.x.x

#xenial only
#systemctl stop resolvconf.service
#systemctl disable resolvconf.service
systemctl stop systemd-resolved.service
systemctl disable systemd-resolved.service
mv /etc/resolv.conf /etc/resolv.conf.dist
vi /etc/resolv.conf

#systemctl stop proc-sys-fs-binfmt_misc.automount
#systemctl disable proc-sys-fs-binfmt_misc.automount
#systemctl status systemd-modules-load.service

apt install ifupdown net-tools openssh-server openssh-client language-pack-en
vi /etc/ssh/sshd_config

Port 2222
AllowGroups root
PermitRootLogin without-password
PasswordAuthentication no
X11Forwarding no

systemctl restart ssh
mkdir ~/.ssh
vi ~/.ssh/authorized_keys
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys

vi /etc/apt/sources.list

deb http://ru.archive.ubuntu.com/ubuntu/ artful main restricted universe multiverse
deb http://ru.archive.ubuntu.com/ubuntu/ artful-updates main restricted universe multiverse
deb http://ru.archive.ubuntu.com/ubuntu/ artful-backports main restricted universe multiverse
deb http://security.ubuntu.com/ubuntu artful-security main restricted universe multiverse

vi /etc/apt/apt.conf.d/02proxy

Acquire::http { Proxy "http://x.x.x.x:3142"; };

Also in case you are using the Ubuntu provided kernel for your XEN guest and scped it to the host system, you might like to avoid updates on its modules (this is NOT SAFE but ok for fast testing),

dpkg -l | grep linux-
dpkg -l | grep 4.13.0
apt-mark hold linux-image-generic linux-image-lowlatency linux-headers-generic

In case you fucked-up your hostname and you need clean SSH keys,

#systemctl stop ssh
#rm -fv /etc/ssh/ssh_import_id /etc/ssh/ssh_host_*
#dpkg-reconfigure openssh-server