ZFS boot pool selection

Andrey V. Elsukov bu7cher at yandex.ru
Thu Jun 5 16:31:12 UTC 2014


On 05.06.2014 12:32, Aristedes Maniatis wrote:
> A. BIOS is able to execute some code placed in a special partition on
> a GPT formatted disk. This code is 40kB of hand crafted code and
> installed using:
> 
> gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 1 ada0
> 
> The partition itself must be created as
> 
> gpart add -s 222 -a 4k -t freebsd-boot -l boot0 ada0
> 
> 
> B. For older BIOS systems without knowledge of GPT, the pmbr is
> installed in some other special location on the disk, outside any
> partitions. This is 512 bytes of code and does nothing other than
> pretend to be MBR to tell the old BIOS (or Windows?) to not mess with
> this disk.

No. BIOS starts bootcode from PMBR. Then it starts bootcode from
freebsd-boot partition. Then it starts loader or kernel.
This method also called as legacy boot. UEFI doesn't use bootcode on the
freebsd-boot partition.

> C. Once gptzfsboot is executing on the CPU, it is able to mount a ZFS
> pool in read only mode. Enough to read the kernel and get a full ZFS
> implementation in place.

gptzfsboot is able to find needed partition and ZFS pool, then it search
the zfsloader or kernel and without mounting loads and starts it.

http://www.freebsd.org/cgi/man.cgi?gpart#BOOTSTRAPPING


> Questions
> 
> 1. If I have two zpools on this machine, how does gptzfsboot know
> which one to boot the kernel from? Does it just start by iterating
> through all zfs partitions until it finds the zpool metadata cache
> which give it enough information to mount some zpool? In other words,
> does it pick a random pool from what it can access?

AFAIK, it will try to boot from the first ZFS pool that it can find.

> 2. How does it know where to find the kernel once it mounts the ZFS
> pool, or is the /boot/kernel location hardcoded into the gptzfsboot
> code?

/boot/kernel/kernel is hardcoded. But when zfsloader is used, it has
some environment variables and you are able to change the kernel location.

> 3. Once the kernel is booted, then it can read /boot/loader.conf. In
> there we can see vfs.root.mountfrom="zfs:tank" but isn't this a bit
> late? We've already mounted this pool and loaded the kernel from it.

Kernel doesn't read loader.conf. The loader/zfsloader does that.

> Can we omit vfs.root.mountfrom entirely?

Yes.

-- 
WBR, Andrey V. Elsukov


More information about the freebsd-stable mailing list