what is installed on freebsd-boot partition?

Hi guys,
I'm running amd64 GENERIC kernel and the root fs is ZFS. I'm curious which boot exectable is installed on the boot partition. I've tried comparing the boot partition with gptzfsboot, find that they are just partially matched. I also tried gptboot. So what exactly is installed on my boot partition? Many thanks!
dhex /dev/da0p1 /boot/gptzfsboot
1701156799594.png

1701156840269.png
 
Is /boot/gptzfsboot from your installation?

/usr/libexec/bsdinstall/zfsboot
GPART_ADD_ALIGN_LABEL_WITH_SIZE='gpart add %s -l %s -t %s -s %s "%s"'
GPART_BOOTCODE_PART='gpart bootcode -b "%s" -p "%s" -i %s "%s"'

if [ "$ZFSBOOT_BOOT_TYPE" = "BIOS" -o \
"$ZFSBOOT_BOOT_TYPE" = "BIOS+UEFI" ]
then
f_eval_catch $funcname gpart \
"$GPART_ADD_ALIGN_LABEL_WITH_SIZE" \
"$align_small" gptboot$index \
freebsd-boot 512k $disk || return $FAILURE
if [ "$ZFSBOOT_BOOT_TYPE" = "BIOS" ]; then
f_eval_catch $funcname gpart \
"$GPART_BOOTCODE_PART" \
/boot/pmbr /boot/gptzfsboot 1 \
$disk || return $FAILURE
else
/usr/src/lib/geom/part/geom_part.c
gpart_write_partcode(struct gctl_req *req, int idx, void *code, ssize_t size)

/*
* When writing to a disk device, the write must be
* sector aligned and not write to any partial sectors,
* so round up the buffer size to the next sector and zero it.
*/
bsize = (size + pp->lg_sectorsize - 1) /
pp->lg_sectorsize * pp->lg_sectorsize;
buf = calloc(1, bsize);
if (buf == NULL)
err(EXIT_FAILURE, "%s", dsf);
bcopy(code, buf, size);
if (write(fd, buf, bsize) != bsize)
err(EXIT_FAILURE, "%s", dsf);
 
Well, the second stage bootcode for booting with BIOS/CSM from GPT with ZFS is /boot/gptzfsboot. Wild guess, you upgraded your system to a newer release since installation? Bootcode is never upgraded automatically.
 
This is not an executable, it's raw data that's written directly to the partition.
And last portion of the partition which exceeds the written boot code is completely untouched. gpart is unaware of the contents.
To be precise, the boot codes in pmbr and freebsd-boot partition are executables, but not FreeBSD executables. They are for BIOS.

The very first boot code is at the top of PMBR (protective master boot record) located at the top of disk drive. The structure of PMBR is completely the same as MBR, and the difference is that the boot code in it looks for boot partition using GPT type partition table and has only one effective partition which occupies whole drive. The boot code in it is limited, only 446 bytes of i8086 real mode binary and usually insufficient to support multiple partitioning scheme. As of FreeBSD pmbr boot code, it just load the whole partition of freebsd-boot type and pass control to it.
 
[...] To be precise, the boot codes in pmbr and freebsd-boot partition are executables, but not FreeBSD executables. They are for BIOS.

Indeed.

The very first boot code is at the top of PMBR (protective master boot record) located at the top of disk drive. The structure of PMBR is completely the same as MBR, and the difference is that the boot code in it looks for boot partition using GPT type partition table and has only one effective partition which occupies whole drive.

Hence protecting the disk from stupid OSes (no name needed) that may otherwise think they can have their wicked way with it.

The boot code in it is limited, only 446 bytes of i8086 real mode binary and usually insufficient to support multiple partitioning scheme.

However boot0cfg(8) manages the unusual nicely, supporting 4 bootable OSes with MBR scheme.

[ gratuitous plug, lest it be lost to history <&^}= ]

As of FreeBSD pmbr boot code, it just load the whole partition of freebsd-boot type and pass control to it.

Nice description, thanks.
 
Well, the second stage bootcode for booting with BIOS/CSM from GPT with ZFS is /boot/gptzfsboot. Wild guess, you upgraded your system to a newer release since installation? Bootcode is never upgraded automatically.
zirias@ thank you. this is very helpful. My system is indeed upgraded from 12.0.
 
Hence protecting the disk from stupid OSes (no name needed) that may otherwise think they can have their wicked way with it.
And from stupid partitioning tools, including ones by third parties.
All old partitioning tools before GPT appears are surey stupid.
 
Also (not FreeBSD in isolation), here's an interesting answer about EFI system partition sizes: <https://askubuntu.com/a/1313158/25036>.
Interesting page. Thanks for the info!

An additional page to introduce, EFI system partition in ArchWiki.
In section 2 "Create the partition", at least 300MiB is recommended.
And in the "Note" of the section,
To ensure the partition can be formatted to FAT32, it should be at least 36 MiB on drives with 512 byte logical sector size and 260 MiB on drives with 4096 logical sector size.
is described.
 
Back
Top