# Procedure applied to multiple Raspberry Pi 4's each with 8 GiB RAM; # earliest approach used FreeBSD 13.2 and set up zpool(8) with 1/2 kiB blocks, # which worked with very poor performance # Partition the 'disk' with gpt gpart create -s gpt da0 # First free block for partitions will be either '34', '40', '48' or '64' # Size the efi partition to make the first block for the following partition # 131072 (64 MiB aligned); this calls for a size of '131038', '131032', # '131024' or '131008' # The SD card image uses 50 MB for efi, which is plenty for now; I've # dealt with many systems that have gone through so many release upgrades on # the same disk that starting boot partition becomes too small # This example matches the case where the first free block is '40' gpart add -t efi -s 131032 -l efi da0 gpart set -a bootme -i 1 da0 # If dedicating a swap partition, size (in multiples of x MiB) the # system partition to leave enough space for it; from skimming through reports # on zfs-swap, it looks adequate to be all swap since FreeBSD 11 or 12, so this # is technically optional, special case, cautious, or because only a swap # partition works as a dump device gpart add -t freebsd-zfs -s xxxxxxxxx -l freebsd da0 gpart add -t freebsd-swap -l swap da0 # Set zpool(8) to use 4kiB blocks (or larger, 12->4k, 13->8k, 14-> 16k); # write performance with the default 9 (1/2k) has been very poor with the SD # cards I've used sysctl vfs.zfs.min_auto_ashift=12 # Use geom to get the gptid (is there a better way to do this?) geom part list | grep -A6 da0p2 zpool create -R /mnt -O canmount=off zroot /dev/gptid/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx # Sources disagree about the specific options on the boot environment # container; such as 'noauto' vs 'off' for canmount zfs create -o canmount=noauto -o mountpoint=none zroot/ROOT # Filesystems based on an older ZFS example setup from the FreeBSD wiki # plus local common use cases zfs create -o canmount=noauto -o mountpoint=/ zroot/ROOT/default zpool set bootfs=zroot/ROOT/default zroot zfs mount zroot/ROOT/default zfs create -o mountpoint=/var zroot/var zfs create -o compression=on -o exec=off -o setuid=off zroot/var/crash zfs create -o exec=off -o setuid=off zroot/var/db zfs create -o exec=off -o setuid=off zroot/var/empty zfs create -o compression=on -o exec=off -o setuid=off zroot/var/log zfs create -o compression=gzip -o exec=off -o setuid=off zroot/var/mail zfs create -o exec=off -o setuid=off zroot/var/run zfs create -o exec=off -o setuid=off zroot/var/spool zfs create -o compression=on -o exec=on -o setuid=off zroot/var/tmp zfs create -o compression=on zroot/var/www zfs create -o compression=on -o exec=on -o setuid=off zroot/var/db/pkg zfs create -o mountpoint=/usr zroot/usr zfs create zroot/usr/local zfs create -o compression=on -o exec=off -o setuid=off zroot/usr/src zfs create zroot/usr/obj zfs create -o compression=on -o setuid=off zroot/usr/ports zfs create -o compression=off -o exec=off -o setuid=off zroot/usr/ports/distfiles zfs create -o compression=off -o exec=off -o setuid=off zroot/usr/ports/packages zfs create -o mountpoint=/home -o setuid=off zroot/home # Get the system from the default SD card image; the following shows the # case where mdconfig sets up md0 mdconfig -f /var/spool/img/freebsd/FreeBSD-14.0-RELEASE-arm64-aarch64-RPI.img cd /mnt dump -0af - /dev/md0s2a | restore -rf - rm restoresymtable # Copy the efi data from the SD card image newfs_msdos -F 32 -L EFI -c 1 /dev/da0p1 mount -t msdosfs -o noatime /dev/da0p1 /mnt/boot/efi mount -r -t msdosfs /dev/md0s1 /mnt/mnt cd /mnt/mnt pax -r -w -pe * /mnt/boot/efi/ # Done with the source image cd umount /mnt/mnt mdconfig -d -u 0 # Optional, configure /mnt/boot/efi/config.txt, such as setting monitor # resolution # Optional, add (more) swap zfs create -V xxG zroot/SWAP zfs set org.freebsd:swap=on zroot/SWAP zfs set checksum=off zroot/SWAP # Set access zfs set readonly=on zroot/var/empty # Add zfs to /mnt/boot/loader.conf; along with the 'zpool set bootfs' # line above, this enables mounting / during boot cat >>/mnt/boot/loader.conf </mnt/etc/fstab <>/mnt/etc/rc.conf <