Bootstrap XEN/PVH FreeBSD guests on ZFS from GNU/Linux

tested on a Slackware current dom0 (Sep 2020)


We are considering FOUR way to deploy FreeBSD as a XEN/PVH guest:


The current guide is about for forth and brutal way. First, we need a kernel with ZFS built-in because we don’t have a loader here and we cannot load deliver the zfs and opensolaris modules. We then bootstrap the guest system from the XEN host/dom0, similarly to what we did with NetBSD and Slackware.


on the Lignux dom0

See Setup ZFS on GNU/Linux


mkdir -p /data/kernels/freebsd-current/
cd /data/kernels/freebsd-current/
tar xJf kernel.txz

Disk & file-system

on the Lignux dom0

mkdir -p /data2/guests/$guest/
cd /data2/guests/$guest/

dd if=/dev/zero of=$guest.zfsdisk bs=1G count=0 seek=10

the kernel wants a GPT partition (GUID a504)

cgdisk $guest.zfsdisk

Part. #     Size        Partition Type            Partition Name
        1007.0 KiB  free space
   1        10.0 GiB    FreeBSD ZFS               zfs0

losetup -a
losetup --find --partscan --show $guest.zfsdisk

#cannot work - kernel won't find it
#zpool create tank `pwd`/$guest.zfsdisk

ls -lF /dev/loop*
zpool create tank /dev/loop0p1
zpool list
zpool status

zfs set compression=lz4 tank
zfs get compression
zfs create -o mountpoint=`pwd`/lala/ tank/root
zfs list
zfs mount


tar xJf /data/kernels/freebsd-current/base.txz -C lala/

no need unless you have swap, but still it’s good to have one, even empty, to avoid complains at system startup

vi lala/etc/fstab

# Device                Mountpoint      FStype  Options         Dump    Pass#
#/dev/xbd0p2             none    swap    sw              0       0

vi lala/etc/ttys

#ttyv0  "/usr/libexec/getty Pc"         xterm   onifexists secure
xc0     "/usr/libexec/getty Pc"         xterm   onifexists secure

zfs unmount `pwd`/lala/
zfs unmount /tank/
zfs mount
rmdir lala/

zpool export tank
zpool list


ls -lF /data/kernels/kernel-zfs
vi $guest

kernel = "/data/kernels/kernel-zfs"
extra = "vfs.root.mountfrom=zfs:tank/root"
memory = 7168
name = "freebsdzfs"
vcpus = 3
maxvcpus = 8
disk = ['tap:tapdisk:aio:/data2/guests/freebsdzfs/freebsdzfs.zfsdisk,xvda,w']
vif = [ 'bridge=br0, vifname=freebsdzfs.0' ]
type = "pvh"

Ready to go

Now that you got fstab and ttys alright

xl create freebsdzfs -c




Chapter 19. The Z File System (ZFS)

19.8. ZFS Features and Terminology

ZFS Tutorials : Creating ZFS pools and file systems

How to Create ZFS File Systems

sparse zfs

Creating a degraded raidz via sparse files

Mount RAW Pool Image with ZFS on Linux

Unmounting ZFS File Systems

13.5. zfs mount/umount

import pools

Managing Devices in ZFS Storage Pools


Custom Kernel build and ZFS prefetch

ZFS module parameters in Linux (OR kernel parameter in FreeBSD or zfs-in-kernel OS)

Make ZFS depend on xdr.ko only. It doesn’t need kernel RPC.

12.2. FreeBSD Boot Process

loader – kernel bootstrapping final stage