Skip to content

Instantly share code, notes, and snippets.

@kaimingguo
Created February 28, 2026 06:05
Show Gist options
  • Select an option

  • Save kaimingguo/319c3fd00f48ddfb84270e9eb9abfa57 to your computer and use it in GitHub Desktop.

Select an option

Save kaimingguo/319c3fd00f48ddfb84270e9eb9abfa57 to your computer and use it in GitHub Desktop.
Installing FreeBSD Root on ZFS

Installing FreeBSD Root on ZFS

Manually Installing FreeBSD on ZFS

This guide assumes you want to manually creating the pool, to change default settings, or to not use the entire disk. If you just want to setup ZFS on the entire disk, use the 'ZFS' option in the bsdinstall partitioning menu.

Create Partitions

Add some partitions for FreeBSD to use: a freebsd-swap partition and a freebsd-zfs partition.

  • -a <number>: controls alignment.
  • -s <size>: sets the size of the partition; if not set, it will default to the remaining space on the disk.
  • -l <name>: sets the label for the partition.

Create the swap and zfs partitions

gpart add -a 4K -s 4G -t freebsd-swap -l swap0 nvd0
gpart add -a 4K -t freebsd-zfs -l zfs0 nvd0

Standard practice these days, 4k align everything even if it's not a 4k-native disk.

Create a mountpoint and the initial zpool.

kldload zfs
sysctl vfs.zfs.min_auto_ashift=12

Create the Pool

Mount a tmpfs to /mnt

mount -t tmpfs tmpfs /mnt

Create the ZFS Pool

zpool create -f -o altroot=/mnt -O compress=lz4 -O atime=off -m none zroot /dev/gpt/zfs0

Create a Boot Environment hierarchy

zfs create -o mountpoint=none zroot/ROOT
zfs create -o mountpoint=none zroot/ROOT/default
mount -t zfs zroot/ROOT/default /mnt

Create the rest of the filesystems.

# zfs set mountpoint=/zroot zroot
zfs create -o mountpoint=/tmp -o exec=on -o setuid=off zroot/tmp
zfs create -o mountpoint=/usr -o canmount=off zroot/usr
zfs create zroot/usr/home
zfs create -o setuid=off zroot/usr/ports
zfs create -o exec=off -o setuid=off zroot/usr/src
zfs create -o mountpoint=/var -o canmount=off zroot/var
zfs create -o exec=off -o setuid=off zroot/var/audit
zfs create -o exec=off -o setuid=off zroot/var/crash
zfs create -o exec=off -o setuid=off zroot/var/log
zfs create -o atime=on -o exec=off -o setuid=off zroot/var/mail
zfs create -o exec=on -o setuid=off zroot/var/tmp

Links and Permission

cd /mnt
ln -s usr/home home
chmod 1777 /mnt/tmp
chmod 1777 /mnt/var/tmp

Configure Boot Environment

zpool set bootfs=zroot/ROOT/default zroot

Finish Install

printf "# Device\tMountpoint\tFStype\tOptions\tDump\tPass #\n/dev/gpt/swap0\tnone\t\tswap\tsw\t0\t0\n" > /tmp/bsdinstall_etc/fstab

Exit Shell Partitioning mode, bsdinstall will continue and complete the installation.

exit

n the post installation step, when asked if you would like to drop into the installed system, choose yes and run the following commands.

sysrc zfs_enable="YES"
sysrc powerd_enable="YES"
# echo 'zfs_load="YES"' >> /boot/loader.conf

Install refind (optional)

cd /tmp
fetch http://downloads.sourceforge.net/project/refind/0.10.3/refind-bin-0.10.3.zip
unzip refind-bin-0.10.3.zip
rm refind-bin-0.10.3.zip
mkdir /tmp/efi
mount_msdosfs /dev/gpt/EFI%20system%20partition /tmp/efi/
cd /tmp/efi/EFI/Boot
mv bootx64.efi bootx64-windows-10.efi
cp /boot/boot1.efi bootx64-freebsd.efi
cp -a /tmp/refind-bin-0.10.3/refind/icons .
cp -a /tmp/refind-bin-0.10.3/refind/refind_x64.efi bootx64.efi
cp /tmp/refind-bin-0.10.3/refind/refind.conf-sample refind.conf

Configure refind and add menu entries

# FreeBSD
menuentry "FreeBSD" {
    loader /EFI/Boot/bootx64-freebsd.efi
    icon /efi/refind/icons/os_freebsd.png
}

Install GRUB (optional)

Configure GRUB

menuentry "FreeBSD" {
    insmod part_gpt
    insmod fat
    set root=(hd0,gpt1)
    chainloader /efi/freebsd/loader.efi
}

Reference

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment