• No products in the cart.

FreeBSD UEFI Root on ZFS and Windows Dual Boot by Kevin Bowling

Somehow I’ve managed to mostly not care about UEFI until now. On my new laptop, I decided I should give it a go. There are some small benefits, nothing life changing, but booting multiple OSes is a lot easier, especially if they are UEFI-native, and you can get a nice frame buffer the boot manager and the OS can use before starting graphically (and after, if you don’t have accelerated graphics drivers).

For reference, how I run FreeBSD desktop/laptop: digital-life*

Install Windows 10 or other UEFI OS

It’s easiest if you install any other co-habiting OS first. Most OS installers assume they own the entire computer, and don’t let you know much about what they are really doing, especially when manipulating booting.

Windows creates a large 100MB EFI partition, plenty of room for refind and other boot loaders.

Leave free space during the installer or shrink the partition using Windows Disk Manager.

Boot into a FreeBSD 11+ live environment

We just need a live FreeBSD environment to conduct our manual install. Make sure it is 11.0 or newer for UEFI boot1 ZFS support.

The USB images with FreeBSD 11.0 and later -CURRENT snapshots have UEFI support integrated so they are directly bootable on UEFI machines. You could also use a CD/DVD or netboot.

Enable sshd, if needed

If you want to copy/paste from this blog to the machine being installed, bring up SSH.

mkdir /tmp/etc /tmp/root
mount_unionfs /tmp/etc /etc
mount_unionfs /tmp/root /root
echo 'PermitRootLogin yes' >> /etc/ssh/sshd_config
service sshd onestart

Bring up a network interface

We’ll need to grab refind during the installation.
Get a dhcp lease on your NIC or see the handbook for wireless setup**:

dhclient em0

Partition the drive

Add a couple GPT partitions. I’m doing a non-ZFS swap so I can coredump the kernel when doing FreeBSD development.

Create a 4k aligned zpool

Standard practice these days, 4k align everything even if it’s not a 4k-native disk. Create a mountpoint and the inital zpool.

kldload zfs

sysctl vfs.zfs.min_auto_ashift=12
mkdir /tmp/zroot
zpool create -f -o altroot=/tmp/zroot -O compress=lz4 -O atime=off -m
none zroot /dev/gpt/zfs0
zpool export zroot

Boot environment compatible ZFS datasets

Nest the root dataset under ROOT so we can use boot environments in the future with beadm***:

Perform a manual install of the distribution

This is pretty easy.

cd /tmp/zroot
ln -s usr/home home
tar xvJpf /usr/freebsd-dist/base.txz
tar xvJpf /usr/freebsd-dist/lib32.txz
tar xvJpf /usr/freebsd-dist/kernel.txz
chmod 1777 /tmp/zroot/var/tmp

Set a few things up

Set some common configurations. You may also wish to set up networking, enable SSH, etc in the altroot rc.conf.

echo 'zfs_enable="YES"' >> /tmp/zroot/etc/rc.conf
echo 'dumpdev="AUTO"' >> /tmp/zroot/etc/rc.conf
echo 'powerd_enable="YES"' >> /tmp/zroot/etc/rc.conf
echo 'sendmail_enable="NONE"' >> /tmp/zroot/etc/rc.conf
echo 'zfs_load="YES"' >> /tmp/zroot/boot/loader.conf
echo 'kern.geom.label.disk_ident.enable="0"' >>
echo 'kern.geom.label.gptid.enable="0"'  >>
printf "/dev/gpt/swap0\tnone\tswap\tsw\t0\t0\n" >> /tmp/zroot/fstab
tzsetup -C /tmp/zroot
chroot /tmp/zroot/ passwd

Install refind

UEFI has lots of bells and whistles. We’re going to use the refind boot manager. I’m relying on the “fallback” efi loader, bootx64.efi. You may need to toggle things around in your system’s firmware for that to work, or teach the EFI NVRAM about refind****. See the refind site for more details.

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

As good hygiene, you might consider updating bootx64-freebsd.efi whenever a point release is done. You could also keep an eye out for refind updates. This is easily done since it’s just a DOS filesystem.

Configure refind and add menu entries

Set the values of timeout, and scanfor to manual to speed things up a bit in refind.conf. Then add a couple entries:

cat << EOF >> refind.conf
menuentry "FreeBSD/amd64 -CURRENT" {
    loader \EFI\Boot\bootx64-freebsd.efi
    icon \EFI\Boot\icons\os_freebsd.png


menuentry "Windows 10 Professional x64" {
    loader \EFI\Boot\bootx64-windows-10.efi
    icon \EFI\Boot\icons\os_win.png


Finish, reboot and enjoy!

That’s it. Unmount the efi partition and reboot.

umount /tmp/efi

You should be greeted by refind, otherwise take a look through your firmware boot order and make sure the firmware nvram for Windows Bootmanager isn’t first.


Keep an eye out for GELI full disk encryption***** on top of ZFS on root.
Don’t forget to do the swap partition as well. http://kev009.com/wp/2016/07/freebsd-uefi-root-on-zfs-and-windows-dual-boot/

Thanks to

Most of this was cribbed from the following sources:

  • Eric McCorkle, Steve Hart and others for adding ZFS boot and a ton of other improvements (GELI) to the FreeBSD UFI loader.
  • Trond Endrestøl’s blog, for mentioning refind and the overall UEFI landscape on FreeBSD.
  • Calomel, for a decent overview of manual ZFS on root installation.
  • /usr/src/usr.sbin/bsdinstall/scripts/zfsboot for some ZFS specifics.
  • An imaging script my colleague Jason Wolfe did for ZFS and boot envs at work.






 About the Author:

Kevin has been using FreeBSD professionally for a few years at Limelight Networks and has over a decade of both software development and high scale systems engineering experience on other UNIX variants.

Article comes from BSD Mag Vol.10 No.09 (85)

2 responses on "FreeBSD UEFI Root on ZFS and Windows Dual Boot by Kevin Bowling"

© HAKIN9 MEDIA SP. Z O.O. SP. K. 2013