Skip to content

Instantly share code, notes, and snippets.

@sigwinch28
Created February 27, 2020 03:06
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sigwinch28/b3419573cb8bc006ffc4b6b563642eb1 to your computer and use it in GitHub Desktop.
Save sigwinch28/b3419573cb8bc006ffc4b6b563642eb1 to your computer and use it in GitHub Desktop.
Installing FreeBSD using a separate boot device (SD card for booting SSD in ODD bay on HP Microserver, for example)

Assumptions

  1. You will be using the FreeBSD installer's automatic ZFS partitioning scheme
  2. Your boot filesystem is zfs:zroot/ROOT/default (the default with the installer)
  3. Your SD card is device da0

Instructions

  1. Install FreeBSD using the automatic installer, choosing ZFS auto partitioning
  2. Drop into a shell after finishing the installer
  3. Create a GPT partition table on da0:
gpart create -s GPT da0
  1. Create a freebsd-boot partition:
gpart add -b 40 -s 472	-t freebsd-boot	da0
  1. Install the loader and a protective MBR on this drive:
gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 1 da0
  1. Create a ZFS partition on the device
gpart add -t freebsd-zfs da0
  1. Create a ZFS pool using this partition (da0p2) and mount it somewhere like /mnt/sd:
zpool create -o altroot=/mnt/sd zboot /dev/da0p2
  1. put the following in /mnt/sd/boot.config (or wherever you mounted the ZFS partition from the SD card):
zfs:zroot/ROOT/default:
  1. You're done!

Explanation

The gptzfsboot loader will first look for ZFS partitions on the same disk it is run from, which in this case will be the SD card. If no ZFS partition is found, it will look through other disks in BIOS boot order. If you have zfs partitions on any other disk in the microserver, then FreeBSD will attempt to boot from these instead, breaking the boot process as it attempts to find the kernel in that filesystem.

By placing /boot.config in a ZFS partition on the same device we're booting from (the SD card), we're instructing gptzfsboot to read options from it, in this case telling it to boot from the zroot/ROOT/default ZFS filesystem.

See https://www.freebsd.org/cgi/man.cgi?query=gptzfsboot for more information about why this works:

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