FreeBSD on ARM64 - NanoPi R6S

References

Dependency management

Installing Packages

pkg install fusefs-exfat exfat-utils fusefs-lkl

Working with the FreeBSD image

We obtain a customized FreeBSD disk image for the R6S from the PersonalBSD website: 14.0-RELEASE-NanoPi-R6S-20231209

# Mount points for img-file partitions
MEMIMG_PART1="/mnt/nano-uboot"
MEMIMG_PART2="/mnt/nano-efi"
MEMIMG_PART3="/mnt/nano-freebsd-ufs"

# Temp dir for rootfs extraction
FSROOT_EXTRACT="/tmp/extract"

# Builder dirs to hold generated partition files
IMG_BASE="/srv/rapids/base/nanopi-r6/boot-image-builder"
PARTFS_SOURCE="${IMG_BASE}/src_image"
PARTFS_UBOOT="${IMG_BASE}/base_uboot"
PARTFS_ROOT="${IMG_BASE}/base_root"
PARTFS_EFI="${IMG_BASE}/base_efi"
PARTFS_GENROOT="${IMG_BASE}/base_genroot"
PARTFS_FILES="${IMG_BASE}/partitions"

# Mount vars renamed
NANO_UBOOT=${MEMIMG_PART1}
NANO_EFI=${MEMIMG_PART2}
NANO_ROOT=${MEMIMG_PART3}

# Create directories
mkdir -p $NANO_UBOOT
mkdir -p $NANO_EFI
mkdir -p $NANO_ROOT

mkdir -p $PARTFS_UBOOT
mkdir -p $PARTFS_EFI
mkdir -p $PARTFS_ROOT
mkdir -p $EXTRACT


# Download the installer image + decompress
IMG_NAME="FreeBSD-aarch64-14.0-RELEASE-NanoPi-R6S-20231209.img"
IMG_URL="https://personalbsd.org/images/${IMG_NAME}.xz"
IMG_COMP="${PARTFS_SOURCE}/${IMG_NAME}.xz"
IMG_FILE="${PARTFS_SOURCE}/${IMG_NAME}"

cd ${PARTFS_SOURCE}
wget ${IMG_URL}
xz -d ${IMG_COMP}


# Mount the image to md0, mount the efi and rootfs partitions
mdconfig -a -t vnode -f ${IMG_FILE} -u 0
mount -t msdosfs /dev/md0p2 ${NANO_EFI}
mount -t ufs /dev/md0p3 ${NANO_ROOT}


# Extract rootfs partition
cp ${NANO_ROOT}/root.part.gz ${FSROOT_EXTRACT}/root.part.gz
cd ${FSROOT_EXTRACT}
gzip -d root.part.gz
mdconfig -a -t vnode -f root.part -u 1
mount -t ufs /dev/md1 ${PARTFS_ROOT}


# Combine the original image's root.part files + ufs uncompressed boot files (odd, but ok)
# - this must be run as sudo or root
sudo rsync -ai ${PARTFS_ROOT}/*  ${PARTFS_GENROOT}/
sudo rsync -ai ${NANO_ROOT}/boot  ${PARTFS_GENROOT}/


# Generate rootfs partition file
cd ${PARTFS_FILES}
makefs -B little -o label=rootfs -o version=2 -o softupdates=1 -D -s 12g rootfs.part ${PARTFS_GENROOT}
gzip rootfs.part


# Copy EFI loader to EFI partition
mkdir -p ${PARTFS_EFI}/efi/boot
rsync -ai ${NANO_EFI}/efi/boot/bootaa64.efi ${PARTFS_EFI}/efi/boot/bootaa64.efi


# Generate EFI partition file
cd ${PARTFS_FILES}
makefs -t msdos \
    -o fat_type=32 -o sectors_per_cluster=1 -o volume_label=EFISYS \
    -s 50m \
    efi.part $EFIDIR


# Generate IMG file from EFI and ROOTFS
mkimg -s gpt -f raw \
    -p efi/esp:=efi.part \
    -p freebsd-swap/swapfs::1G \
    -p freebsd-ufs/rootfs:=rootfs.part \
    -o selfbuilt.img






When finished with the md0

umount /mnt/r6s-root
umount /mnt/ufs
mdconfig -d -u 0
mdconfig -d -u 1

Command Notes

The following are referential…

Mounting ExFat via lklfuse

lklfuse -o type=exfat /dev/md0 /mnt/exfat

Install fuse dependencies