ZFS Update bootcode (zpool + UEFI)

Hi all, I'm not trusting my judgement today. With help from you I hope to regain it :) I upgraded my system zpool and need to update the boot code.

Zpool upgrade
Code:
# zpool upgrade system
This system supports ZFS pool feature flags.

Enabled the following features on 'system':
  allocation_classes

If you boot from pool 'system', don't forget to update boot code.
Assuming you use GPT partitioning and da0 is your boot disk
the following command will do it:

    gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 1 da0

System zpool looks like this:
Code:
# zpool status system
  pool: system
state: ONLINE
  scan: scrub repaired 0 in 0 days 00:11:14 with 0 errors on Sun Mar  7 22:34:36 2021
config:

    NAME            STATE     READ WRITE CKSUM
    system          ONLINE       0     0     0
      mirror-0      ONLINE       0     0     0
        ada1p3.eli  ONLINE       0     0     0
        ada0p3.eli  ONLINE       0     0     0

..and drives are partitioned like this:
Code:
# gpart show
=>       40  488397088  ada0  GPT  (233G)
         40     409600     1  efi  (200M)
     409640       2008        - free -  (1.0M)
     411648    4194304     2  freebsd-swap  (2.0G)
    4605952  483790848     3  freebsd-zfs  (231G)
  488396800        328        - free -  (164K)

=>       40  488397088  ada1  GPT  (233G)
         40     409600     1  efi  (200M)
     409640       2008        - free -  (1.0M)
     411648    4194304     2  freebsd-swap  (2.0G)
    4605952  483790848     3  freebsd-zfs  (231G)
  488396800        328        - free -  (164K)

System is booting using UEFI
Code:
# sysctl machdep.bootmethod
machdep.bootmethod: UEFI

Question
Can I update the UEFI boot code like outlined below?

Code:
gpart bootcode -p /boot/boot1.efi -i 1 ada0
gpart bootcode -p /boot/boot1.efi -i 1 ada1

Thank you.

edit:
I removed GELI from the post title. It doesn't have any relevance to the boot process, as the efi partition is unencrypted.
 
Question
Can I update the UEFI boot code like outlined below?

Code:
gpart bootcode -p /boot/boot1.efi -i 1 ada0
gpart bootcode -p /boot/boot1.efi -i 1 ada1

Thank you.
gpart bootcode -p /boot/boot1.efifat -i 1 ada0

/boot/boot1.efifat is partition image in FAT format to be written into EFI boot partition. 200M is more than enough, totally OK.
 
Argentum:

From the uefi(8) manual it seems that boot1.efifat is for use with bsdinstall(8). Is this really the one I want to use?

Code:
...
     /boot/boot1.efi
                   First stage UEFI bootstrap
     /boot/boot1.efifat
                   msdosfs(5) FAT file system image containing boot1.efi for
                   use by bsdinstall(8) and the bootcode argument to gpart(8).
...
 

Mount your EFI partition, rename your old BOOTX64.efi to BOOTX64.bak and then copy /boot/loader.efi over BOOTX64.efi . Do this for both ada0/ada1 in case you have some issue you can always boot back using LiveCD/USB mount the EFI and restore your original BOOTX64.bak -> BOOTX64.efi

When you are dealing with update/upgrades it's always good idea to have a backup in case you mess up the things.
 
Argentum:

From the uefi(8) manual it seems that boot1.efifat is for use with bsdinstall(8). Is this really the one I want to use?
Yes. The command I gave is exactly what you need. Another way is to mount the EFI partition and coy bootcode, but there are more steps. The result is exactly the same.

And also, because you have a mirror. Do it on one drive only and see if it works. You can also mount that partition later and see that the boot loader is there.

mount -t msdosfs /dev/ada0p1 /mnt
ls -l /mnt/efi/boot/
 
I'm getting a bit confused.
From my understanding what gpart bootcode -p /boot/boot1.efifat -i 1 ada0 does is essentially the same as mount -t msdosfs /dev/ada0p1 /mnt && cp /boot/loader.efifat /mnt/efi/boot/BOOTx64.efi?
However, according to the statement VladiBG posted a link to it seems like /boot/boot1.efifat shouldn't be used anymore? But the /boot/boot1.efi is an executable and doesn't seem to be interchangeable with /boot/boot1.efifat (which is a filesystem).
 
Do NOT copy the efifat image over /mnt/efi/boot/BOOTx64.efi This will make your system unbootable.
Please follow the official WIKI, Handbook and man pages examples.

The file boot1.efifat is no longer used. The code that generate that fat image was removed: https://github.com/freebsd/freebsd-...65246a78bc5aa7baf3237aa5b8919ba0aebf5f96be2ba

If you download the new FreeBSD-13.0-RC1-amd64-bootonly.iso and check the /boot you will not see anymore the boot1.efifat image so that image file (boot1.efifat) that you have on your system do not contain the latest version of loader.efi (BOOTx64.efi)
 
Duly noted. I've looked around in the documentation. /boot/boot1.efifat is still mentioned in some places both in wiki and man pages, gpart bootcode -p /boot/gptzfsboot .. is also something mentioned in the man page.
UEFI article on the FreeBSD wiki states the same as you did, that is copying /boot/loader.efi to your EFI boot file. In a different context, but basically does the same thing that I want to do (assuming that loader.efi is being updated by freebsd-update(8))
Anyway. This worked, thank you! I find it a bit counter-intuitive as I'm requested to use gpart(8) to update the boot code.
It's clear I need to study this a little but more though. I'm still a bit confused about the when's, why's and how's of these different loaders.
 
Do NOT copy the efifat image over /mnt/efi/boot/BOOTx64.efi This will make your system unbootable.
Please follow the official WIKI, Handbook and man pages examples.

The file boot1.efifat is no longer used. The code that generate that fat image was removed: https://github.com/freebsd/freebsd-...65246a78bc5aa7baf3237aa5b8919ba0aebf5f96be2ba

If you download the new FreeBSD-13.0-RC1-amd64-bootonly.iso and check the /boot you will not see anymore the boot1.efifat image so that image file (boot1.efifat) that you have on your system do not contain the latest version of loader.efi (BOOTx64.efi)
Are you talking about 12.2 or 13.0 pre-release? It is inculded an can be built in 12.2. And I have built it several times over and also included additional debug printouts sometimes.

It can be built by:
cd /usr/src/stand
make

And I just built it few minutes ago to be sure what I am writing here:

ls -l /usr/obj/usr/src/amd64.amd64/stand/efi/boot1/

Code:
-rw-r--r--  1 root  wheel     172 Jan 25 18:38 .depend
-rw-r--r--  1 root  wheel    2700 Mar 11 16:27 .depend.boot1.o
-rw-r--r--  1 root  wheel    2271 Mar 11 16:27 .depend.devpath.o
-rw-r--r--  1 root  wheel    2700 Mar 11 16:27 .depend.proto.o
-rw-r--r--  1 root  wheel     833 Mar 11 16:27 .depend.self_reloc.o
-rw-r--r--  1 root  wheel      54 Mar 11 16:27 .depend.start.o
-rw-r--r--  1 root  wheel    2673 Mar 11 16:27 .depend.ufs_module.o
-rw-r--r--  1 root  wheel    3323 Mar 11 16:27 .depend.zfs_module.o
-rwxr-xr-x  1 root  wheel   93696 Mar 11 16:27 boot1.efi*
-rw-r--r--  1 root  wheel  819200 Mar 11 16:27 boot1.efifat
-rw-r--r--  1 root  wheel   47200 Mar 11 16:27 boot1.o
-rwxr-xr-x  1 root  wheel  132624 Mar 11 16:27 boot1.sym*
-rwxr-xr-x  1 root  wheel  328504 Mar 11 16:27 boot1.sym.debug*
-rwxr-xr-x  1 root  wheel  445592 Mar 11 16:27 boot1.sym.full*
-rw-r--r--  1 root  wheel   60416 Mar 11 16:27 devpath.o
drwxr-xr-x  2 root  wheel       4 Mar 11 16:27 include/
-rw-r--r--  1 root  wheel   18664 Mar 11 16:27 proto.o
-rw-r--r--  1 root  wheel    4856 Mar 11 16:27 self_reloc.o
-rw-r--r--  1 root  wheel    2232 Mar 11 16:27 start.o
-rw-r--r--  1 root  wheel   43864 Mar 11 16:27 ufs_module.o
-rw-r--r--  1 root  wheel  307744 Mar 11 16:27 zfs_module.o

...and yes, it is in the manual: efi(8)
 
I'm talking in general how you should handle the upgrading for all versions. In the new man page from 2020 (current) it's removed. In the EFI partition you can have many diagnostic tools and replacing the entire partition with image will cause to lose any such tools.
 
Do NOT copy the efifat image over /mnt/efi/boot/BOOTx64.efi This will make your system unbootable.
Please follow the official WIKI, Handbook and man pages examples.

The file boot1.efifat is no longer used. The code that generate that fat image was removed: https://github.com/freebsd/freebsd-...65246a78bc5aa7baf3237aa5b8919ba0aebf5f96be2ba

If you download the new FreeBSD-13.0-RC1-amd64-bootonly.iso and check the /boot you will not see anymore the boot1.efifat image so that image file (boot1.efifat) that you have on your system do not contain the latest version of loader.efi (BOOTx64.efi)
Now, when I have RC2-13.0, I must confess that this is the case. No FAT image any more.
 
Tried this tonight after upgrading to current and upgrading my zpool and locked myself out of system thinking /boot/efi/efi/boot/bootx64.efi was all I had to update. Seems the loader.efi in freebsd folder is the one that needs updating. I managed to boot a live CD and fix it but I'll give you commands to use after a zpool upgrade on GPT+UEFI that should work on 13.1 and 14 current:

By default on 13.1 and 14 current efi directory is mounted at /boot/efi for you from /etc/fstab.
What really matters after zpool upgrade is your copy /boot/loader.efi to /boot/efi/efi/freebsd/loader.efi. Having a look at both
/boot/efi/efi/freebsd/loader.efi and /boot/efi/efi/boot/bootx64.efi they are exactly the same. I locked myself by not getting the loader in freebsd efi folder as that seems to be only one that matters on my tests at least on this Dell r720 machine, but since they are both copies of each other this should work for everyone:

cp /boot/efi/efi/freebsd/loader.efi /boot/efi/efi/freebsd/loader.efi.old cp /boot/efi/efi/boot/bootx64.efi /boot/efi/efi/boot/bootx64.efi.old cp /boot/loader.efi /boot/efi/efi/freebsd/loader.efi cp /boot/loader.efi /boot/efi/efi/boot/bootx64.efi

If you do screw it up can boot a normal FreeBSD USB stick and choose the live shell.
All I had to do is:

mount -t msdos /dev/mfisyspd0p1 /mnt

Of course use your own device name, but you should be able to go into /mnt after and fix it. Then just:

cd / umount /mnt sync shutdown -r now

Hope this helps someone....
 
Back
Top