XEN // Bootstrap FreeBSD/ZFS from GNU/Linux

tested on a Slackware current dom0 (Sep 2020)


for the guest, 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 was done with NetBSD and Slackware. therefore dom0 also needs to be ZFS-capable already

grab latest release tarballs

    mkdir -p /data/kernels/freebsd130/
    cd /data/kernels/freebsd130/
    wget https://download.freebsd.org/releases/amd64/amd64/13.0-RELEASE/kernel.txz
    wget https://download.freebsd.org/releases/amd64/amd64/13.0-RELEASE/base.txz

    rm -rf boot/ usr/
    tar xaf kernel.txz

for userland it’s better to use bsdtar

    # ubuntu
    apt install libarchive-tools

    # slackware
    slackpkg search libarchive

Guest vdisk

raw sparse file virtual disk

mkdir -p /root/guests/freebsd-zfs/lala/
cd /root/guests/freebsd-zfs/

dd if=/dev/zero of=freebsd-zfs.zfs bs=1G count=0 seek=10


the kernel wants a GPT partition (GUID a504)

cgdisk freebsd-zfs.zfs

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

losetup -a
losetup --find --partscan --show freebsd-zfs.zfs

#cannot work - kernel won't find it
#zpool create tank `pwd`/freebsd-zfs.zfs

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

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


bsdtar -xJ --numeric-owner -f /data/kernels/freebsd130/base.txz -C lala/
ls -lhF lala/

no need for a valid file-system table unless you have swap, but still it’s good to have one, even empty, to avoid complains at system startup

vi lala/etc/fstab # new file

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

cp -pi lala/etc/ttys lala/etc/ttys.dist
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

losetup -a
losetup -d /dev/loop0

Guest skeleton


ls -lhF /data/kernels/kernel-zfs
vi freebsd-zfs

kernel = "/data/kernels/kernel-zfs"
extra = "vfs.root.mountfrom=zfs:tank/root"
memory = 7168
name = "freebsd-zfs"
vcpus = 8
maxvcpus = 16
disk = ['tap:tapdisk:aio:/data/guests/freebsd-zfs/freebsd-zfs.zfs,xvda,w']
vif = [ 'bridge=xenbr0, vifname=fbsdzfs.0',
    'bridge=xenbr0, vifname=fbsdzfs.1' ]
type = "pvh"

Ready to go

Now that you got fstab and ttys alright

xl create freebsd-zfs -c

you can now proceed with casual sysprep as follows.

Timezone & network

ls -lF /etc/localtime
ln -s ../usr/share/zoneinfo/Europe/Moscow /etc/localtime
ln -s ../usr/share/zoneinfo/Europe/Paris /etc/localtime

vi /etc/rc.conf

ifconfig_xn0="inet netmask up"

mv /etc/hosts /etc/hosts.dist
vi /etc/hosts

::1                     localhost localhost.localdomain               localhost localhost.localdomain                freebsd.localdomain freebsd                gw             dns1             dns2

vi /etc/resolv.conf


shutdown -r now

Acceptance & template

ping -c1 opendns.com

history -c
rm -f .history
shutdown -p now

cd /data/guests/

xl des freebsd-ext2fs
tar cSf /data/templates/freebsd-ext2fs.tar freebsd-ext2fs/
rm -rf freebsd-ext2fs/

xl des freebsd-zfs
tar cSf /data/templates/freebsd-zfs.tar freebsd-zfs/
rm -rf freebsd-zfs/



boot zfs

Custom Kernel build and ZFS prefetch https://lists.freebsd.org/pipermail/freebsd-questions/2015-February/264111.html

ZFS module parameters in Linux (OR kernel parameter in FreeBSD or zfs-in-kernel OS) https://billtian.github.io/digoal.blog/2014/06/25/03.html

Make ZFS depend on xdr.ko only. It doesn’t need kernel RPC. https://github.com/freebsd/freebsd/commit/77755bd98c42004a010540bd9b6c171a557337a2


Chapter 19. The Z File System (ZFS) https://www.freebsd.org/doc/handbook/zfs.html

19.8. ZFS Features and Terminology https://www.freebsd.org/doc/handbook/zfs-term.html

ZFS Tutorials : Creating ZFS pools and file systems https://www.thegeekdiary.com/zfs-tutorials-creating-zfs-pools-and-file-systems/

How to Create ZFS File Systems https://docs.oracle.com/cd/E19253-01/819-5461/gayog/index.html

sparse zfs

Creating a degraded raidz via sparse files https://www.ixsystems.com/community/threads/creating-a-degraded-raidz-via-sparse-files.18276/

Mount RAW Pool Image with ZFS on Linux https://wiki.orzfly.com/topics/zfs-on-linux-mount-raw-pool-image

Unmounting ZFS File Systems https://docs.oracle.com/cd/E19253-01/819-5461/gamnr/index.html

13.5. zfs mount/umount http://www.netkiller.cn/freebsd/filesystem/zfs.mount.html

import pools

Managing Devices in ZFS Storage Pools https://docs.oracle.com/cd/E19253-01/819-5461/gayrd/index.html

Copyright © 2022 Pierre-Philipp Braun