XEN // Bootstrap FreeBSD/EXT2FS from GNU/Linux

freebsd full | freebsd cloud | freebsd ext2fs | freebsd zfs

tested on debian and slack150

Requirements

we need a specific EXT2FS-enabled kernel

grab latest base tarball

    mkdir -p /data/kernels/freebsd132/
    cd /data/kernels/freebsd132/
    wget https://download.freebsd.org/releases/amd64/amd64/13.2-RELEASE/base.txz

for userland it’s better to use bsdtar

# ubuntu
    apt install libarchive-tools

# slackware
    slackpkg install libarchive

Guest vdisk

mkdir -p /data_local/guests/freebsd-ext2fs/lala/
cd /data_local/guests/freebsd-ext2fs/

dd if=/dev/zero of=freebsd-ext2fs.ext2 bs=1G count=0 seek=10
mkfs.ext2 freebsd-ext2fs.ext2
mount freebsd-ext2fs.ext2 lala/

Userland

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

right onto the slice w/o BSD partition a

vi lala/etc/fstab # new file

# need to install e2fsck, no fsck meanwhile
    /dev/xbd0 / ext2fs rw,noatime 0 0

xen guest tuning

fix the serial console

    mv -i lala/etc/ttys lala/etc/ttys.dist
    vi lala/etc/ttys

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

network

    vi lala/etc/rc.conf

    hostname="freebsd.localdomain"

# esp. required for the cloud image
    growfs_enable="YES"

    ifconfig_xn0="inet CIDR up"
    defaultrouter="GW-IP"
    sshd_enable=yes

    mv lala/etc/ssh/sshd_config lala/etc/ssh/sshd_config.dist
    grep -vE '^#|^$' lala/etc/ssh/sshd_config.dist > lala/etc/ssh/sshd_config
    echo permitrootlogin prohibit-password >> lala/etc/ssh/sshd_config

    mkdir lala/root/.ssh/
cat ~/.ssh/*pub
    vi lala/root/.ssh/authorized_keys

(paste your pub key)

    chmod 600 lala/root/.ssh/authorized_keys
    chmod 700 lala/root/.ssh/
    chmod 700 lala/root/

    mv -i lala/etc/hosts lala/etc/hosts.dist
    vi lala/etc/hosts

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

    10.1.0.9                freebsd.localdomain freebsd

    vi lala/etc/resolv.conf

    nameserver 10.1.255.19
    nameserver 10.1.255.20

environment

ls -lF lala/etc/localtime
ln -s ../usr/share/zoneinfo/Europe/Moscow lala/etc/localtime
umount lala/
rmdir lala/

Guest skeleton

mkdir -p /data/guests/freebsd-ext2fs/
cd /data/guests/freebsd-ext2fs/
vi freebsd-ext2fs

# +EXT2FS + PF
kernel = "/data/kernels/freebsd132/minimal-ext2fs"
extra = "vfs.root.mountfrom=ext2fs:/dev/xbd0"
type = "pvh"

name = "freebsd-ext2fs"
vcpus = 3
memory = 7168
disk = [ 'tap:tapdisk:aio:/data_local/guests/freebsd-ext2fs/freebsd-ext2fs.ext2,xvda,w' ]
#disk = [ 'phy:/dev/drbd/by-res/fcarp1/0,xvda,w' ]
vif = [ 'bridge=guestbr0, vifname=ext2fs.0',
    'bridge=guestbr0, vifname=ext2fs.1' ]

Ready to go

fsck.ext2 /data_local/guests/freebsd-ext2fs/freebsd-ext2fs.ext2 -f
xl create freebsd-ext2fs -c

Post-install fixup

ping -c1 opendns.com
    pkg install e2fsprogs
which fsck_ext2fs
    vi /etc/fstab

    /dev/xbd0 / ext2fs rw,noatime 0 1

Additional notes

one could otherwise consider making a partition on the vdisk

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

n p
ENTER ENTER ENTER
a
t a5
w

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

    /dev/xbd0s1 / ext2fs rw 0 0
    /dev/xbd0s1 / ext2fs rw 0 1

extra = "vfs.root.mountfrom=ext2fs:/dev/xbd0s1"

disk = ['tap:tapdisk:aio:/data_local/guests/freebsd-ext2fs/freebsd-ext2fs.img,xvda,w']

one could also consider loading the module from loader.conf (untested)

ext2fs_load=YES

Troubleshooting

fsck: exec fsck_ext2fs for /dev/xbd0s1 in /sbin:/usr/sbin: No such file or directory

==> install e2fsprogs

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 | HTML5 | CONTACT
Copyright © 2024 Pierre-Philipp Braun