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

tested on a Slackware current dom0 (Sep 2020)

Introduction

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

Warning

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.

OpenZFS

on the Lignux dom0

See Setup ZFS on GNU/Linux

Requirements

mkdir -p /data/kernels/freebsd-current/
cd /data/kernels/freebsd-current/
wget http://ftp.free.fr/mirrors/ftp.freebsd.org/snapshots/amd64/13.0-CURRENT/kernel.txz
wget http://ftp.free.fr/mirrors/ftp.freebsd.org/snapshots/amd64/13.0-CURRENT/base.txz
tar xJf kernel.txz

Disk & file-system

on the Lignux dom0

guest=freebsdzfs
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

System

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

Skeleton

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

TODO

Resources

zfs

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

boot

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

12.2. FreeBSD Boot Process https://www.freebsd.org/doc/handbook/boot-introduction.html

loader – kernel bootstrapping final stage https://www.freebsd.org/cgi/man.cgi?query=loader


HOME | GUIDES | BENCHMARKS | html