mkdir -p ~/mfsBSD-workdir/DIST
cd ~/mfsBSD-workdir
pkg install -y git
git clone https://github.com/mmatuska/mfsbsd.git
fetch -o - https://download.freebsd.org/ftp/releases/amd64/amd64/ISO-IMAGES/12.2/FreeBSD-12.2-RELEASE-amd64-memstick.img.xz | xz -d > DIST/FreeBSD.img
mkdir /mnt/md
mount -r /dev/`mdconfig -o readonly DIST/FreeBSD.img`s2a /mnt/md
#- If there is a work directory and an ISO from a previous build remove them
#- Edit Makefile 'MFSROOT_MAXSIZE?= 400m' # the ISO has ~300MB with kernel and base.
# # If there are more sets included increase the size
#cp rc.local conf/ # a rc.local from a installer image
#mkdir -p customfiles/usr/freebsd-dist/ # copy here MANIFEST, kernel.txz, base.txz, ...
#mkdir customfiles/etc/ # put here installerconfig
#make iso BASE=/dir/to/distfiles_kernel.txz_and_base.txz
cp /mnt/md/etc/rc.local mfsbsd/conf/
cp mfsbsd/conf/hosts.sample mfsbsd/conf/hosts
sed 's/#ifconfig_rl0/ifconfig_em0/' mfsbsd/conf/rc.conf.sample >mfsbsd/conf/rc.conf
sed -i '' '/MFSROOT_MAXSIZE?/s/120/400/' mfsbsd/Makefile
echo 'lfm' > mfsbsd/tools/packages.sample
mkdir -p mfsbsd/customfiles/usr/freebsd-dist/ # copy here MANIFEST, kernel.txz, base.txz, ...
cp /mnt/md/usr/freebsd-dist/base.txz mfsbsd/customfiles/usr/freebsd-dist
cp /mnt/md/usr/freebsd-dist/kernel.txz mfsbsd/customfiles/usr/freebsd-dist
mkdir mfsbsd/customfiles/etc/ # put here installerconfig
echo 'creating installerconfig script'
cat > mfsbsd/customfiles/etc/installerconfig <<__INSTALLERCONFIG_
# Installerconfig
PARTITIONS="ada0 gpt { 20G freebsd-ufs /, 4G freebsd-swap }"
DISTRIBUTIONS="kernel.txz base.txz"
#!/bin/sh
gpart bootcode -b /boot/pmbr -p /boot/gptboot -i 1 ada0
sysrc ifconfig_em0=DHCP
sysrc sshd_enable=YES
__INSTALLERCONFIG_
cd mfsbsd
make iso BASE=/mnt/md/usr/freebsd-dist