XEN // Bootstrap FreeBSD/EXT2FS from GNU/Linux

tested on ubuntu/jammy dom0

Requirements

we need a specific EXT2FS-enabled kernel

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

Userland

cd /data/guests/
mkdir -p freebsd-ext2fs/lala/
cd freebsd-ext2fs/
dd if=/dev/zero of=freebsd-ext2fs.img bs=1G count=0 seek=10
fdisk freebsd-ext2fs.img

n
ENTER ENTER ENTER
a
t a5
w

losetup --find --partscan --show freebsd-ext2fs.img
mkfs.ext2 /dev/loop0p1
mount /dev/loop0p1 lala/

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

right onto the slice w/o BSD partition a

vi lala/etc/fstab # new file

    /dev/xbd0s1 / ext2fs rw 1 1
umount lala/
rmdir lala/

Guest skeleton

ls -lF /data/kernels/freebsd130/minimal-ext2fs
vi freebsd-ext2fs

kernel = "/data/kernels/freebsd130/minimal-ext2fs"
extra = "vfs.root.mountfrom=ext2fs:/dev/xbd0s1"
memory = 1024
name = "freebsd-ext2fs"
vcpus = 2
maxvcpus = 2
disk = ['tap:tapdisk:aio:/data/guests/freebsd-ext2fs/freebsd-ext2fs.img,xvda,w']
vif = [ 'bridge=xenbr0, vifname=fbsd2fs.0',
    'bridge=xenbr0, vifname=fbsd2fs.1' ]
type = "pvh"

Ready to go

xl create freebsd-ext2fs -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 10.1.1.9 netmask 255.255.255.0 up"
defaultrouter="10.1.1.254"
hostname="freebsd.localdomain"

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

::1                     localhost localhost.localdomain
127.0.0.1               localhost localhost.localdomain

10.3.3.9                freebsd.localdomain freebsd
10.3.3.1                gw
62.210.16.6             dns1
62.210.16.7             dns2

vi /etc/resolv.conf

nameserver 62.210.16.6
nameserver 62.210.16.7

shutdown -r now

Acceptance & template

hostname
ping -c1 opendns.com

/usr/libexec/locate.updatedb
date
sync
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/

Troubleshooting

mountroot> ext2fs:/dev/xbd0
Trying to mount root from ext2fs:/dev/xbd0 []...
Mounting from ext2fs:/dev/xbd0 failed with error 2: unknown file system.

Resources

ext2fs – ext2/ext3/ext4 file system https://www.freebsd.org/cgi/man.cgi?query=ext2fs

https://wiki.freebsd.org/Ext2fs


https://www.freebsd.org/cgi/man.cgi?loader(8)

https://docs.freebsd.org/en/books/handbook/kernelconfig/

https://leaf.dragonflybsd.org/mailarchive/users/2010-07/msg00036.html –> initrd

https://freebsd-hackers.freebsd.narkive.com/tDfupi1J/use-loader-to-load-kernel-gz-and-mfsroot-gz-in-an-ext2-filesystem

https://www.unitedbsd.com/d/327-how-to-properly-mount-linux-partitions-on-zfs-root-of-ghostbsd/3


https://www.vcdx200.com/2013/12/freebsd-running-from-read-only-compact.html

https://docs.freebsd.org/en/books/handbook/serialcomms/

https://lists.freebsd.org/pipermail/freebsd-questions/2009-August/204350.html

https://vzaigrin.wordpress.com/2014/04/13/connecting-to-raspberry-pi-with-freebsd-using-a-console-cable/


HOME | GUIDES | LECTURES | LAB | SMTP HEALTH | NU | HTML5
Copyright © 2022 Pierre-Philipp Braun