XEN/PV guest bootstrapping // Ubuntu / Debian / Devuan

Debootstraping is the method we prefer.

The kernel has to be either a freaking custom domU kernel or official Ubuntu XEN kernel. In any case, NO INSTALL RAMDISK IS NEEDED.

Requirements

Ubuntu,

apt install debootstrap

Debian/Devuan,

apt install debootstrap
apt install ubuntu-archive-keyring

Slackware,

sbopkg -i debootstrap

Slackware // setup Ubuntu & Debian keys (draft),

cd /usr/share/
ls -lhF | grep key
rsync -avz --progress keyring.debian.org::keyrings/keyrings ./
ls -lhF /usr/share/keyrings/debian-archive-keyring.gpg

Virtual Partition & Debootstrap

dist=xenial
mirror=ru

mkdir -p /data/guests/$dist/
cd /data/guests/$dist/

dd if=/dev/zero of=$dist.ext4 bs=1G count=0 seek=10
mkfs.ext4 $dist.ext4
#dd if=/dev/zero of=ubuntu.swap bs=1G count=0 seek=1
#mkswap ubuntu.swap
mkdir lala
mount -o loop $dist.ext4 lala

debootstrap --arch=amd64 $dist lala/ http://$mirror.archive.ubuntu.com/ubuntu/
#debootstrap --arch=amd64 $dist lala/ http://ftp.$mirror.debian.org/debian/
#--print-debs
#--no-check-gpg
du -sh lala
# xenial 248M, 247M
# artful 302M, 307M

cat lala/etc/fstab # UNCONFIGURED FSTAB FOR BASE SYSTEM
cat > lala/etc/fstab <<-EOF
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
proc            /proc           proc    defaults        0       0
/dev/xvda1       /               ext4   defaults        0       1
EOF
#/dev/xvdb1       none            swap    sw             0       0
cat lala/etc/fstab

chroot lala/ passwd

umount lala
rmdir lala

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

Guest Configuration

cat > $dist <<-EOF
kernel = "/data/kernels/vmlinuz"
root = "/dev/xvda1 ro netcfg/do_not_use_netplan=true"
memory = 256
name = "$dist"
vcpus = 2
disk = ['tap:tapdisk:aio:/data/guests/$dist/$dist.ext4,xvda1,w']
vif = [ 'bridge=xenbr0, vifname=$dist.0' ]
EOF

Ready to go

xl create $dist -c
unset dist

Operations

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

Troubleshooting trusty

Note. trusty seems to have some old ext4 implementation, so build ext3 instead from the host,

#mkfs.ext3 ubuntu.ext3

also for trusty you need this for the serial port // xl console to work,

serial = "pty"

as a matter of fact the init Starting/Stopping seems to be failing too, so in case you just need to get it up and running in the most dirty possible way,

extra = "init=/bin/bash"

mount -o remount,rw /
mount proc /proc -t proc
mkdir /dev/pts
mount devpts /dev/pts -t devpts
export HOME=/root
export TERM=xterm
export PATH=/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin:$HOME/bin
apt update
apt install git build-essential

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

References