Re: bootcode update after zpool upgrade

From: Miroslav Lachman <000.fbsd_at_quip.cz>
Date: Thu, 24 Feb 2022 22:21:20 UTC
On 24/02/2022 20:00, Warner Losh wrote:
> 
> 
> On Thu, Feb 24, 2022 at 11:51 AM Miroslav Lachman <000.fbsd@quip.cz 
> <mailto:000.fbsd@quip.cz>> wrote:
> 
>     On 24/02/2022 17:55, Warner Losh wrote:
>      >
>      >
>      > On Thu, Feb 24, 2022 at 4:49 AM Miroslav Lachman
>     <000.fbsd@quip.cz <mailto:000.fbsd@quip.cz>
>      > <mailto:000.fbsd@quip.cz <mailto:000.fbsd@quip.cz>>> wrote:
>      >
>      >     On 24/02/2022 10:43, Alexander Leidinger wrote:
>      >      > Quoting Miroslav Lachman <000.fbsd@quip.cz
>     <mailto:000.fbsd@quip.cz>
>      >     <mailto:000.fbsd@quip.cz <mailto:000.fbsd@quip.cz>>> (from
>     Wed, 23 Feb 2022
>      >
>      >      >> I am not sure what I should update. This machine is EFI
>     boot only
>      >      >> (this is the only one EFI machine we have).
>      >      >
>      >      >> Should I run:
>      >      >> gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 2 nvd0
>      >      >> gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 2 nvd1
>      >      >
>      >      > This is the bootcode zpool upgrade talks about.
>      >      >
>      >      >> Or should I update EFI partitions? (if so, then how?)
>      >      >
>      >      > The EFI partition contains the loader, not the bootcode.
>      >      >
>      >      > While we are at it, I'm still looking for the place where
>     I can find
>      >      > which features the bootcode supports. Not all features are
>      >     supported for
>      >      > a root pool.
>      >
>      >     Thank you for the clarification!
>      >
>      >
>      > If you've updated your ZFS pool and have an old system, you do
>     need to
>      > update
>      > the EFI boot code. None of the mbr stuff is used for EFI booting.
>      >
>      > If you have an old installation, it may be small. So ideally,
>     you'd copy
>      > over /boot/loader.efi
>      > to ESP:efi/boot/bootx64.efi. However, it may be too big if you
>     have an
>      > ESP created by the
>      > old installer. In that case, you'll need to either create a new,
>     larger
>      > ESP, or copying /boot/boot1.efi
>      > instead.
> 
>     This machine was installed 2 years ago as FreeBSD 11.2 and then
>     upgraded
>     to 11.4 and 12.2. The last update was from 12.2-p9 to 12.2-p13 so the
>     machine was booting fine without modification of bootcode and with
>     FreeBSD 12.2-p9 but after the last update to -p13 I decided to run
>     "zpool upgrade".
> 
>     So the question is, do I need to update efi/boot/bootx64.efi?
> 
> 
> If you've done a zpool upgrade from before the switch to OpenZFS, then 
> yes. You do.

I think this is the case, zpool (and bootx64.efi) was created with 11.2 
and now upgraded under 12.2. I am not sure if 12.2 is OpenZFS based (I 
thought it is in 13.0)

>     I tried to look at it:
> 
>     # mount -t msdosfs /dev/nvd0p1 /media/
> 
>     # ll /media/efi/boot/
>     total 385
>     -rwxr-xr-x  1 root  wheel   384K Apr 16  2018 BOOTx64.efi*
>     -rwxr-xr-x  1 root  wheel    12B Apr 16  2018 startup.nsh*
> 
>     The BOOTx64.efi is old, from 11.2 install.
> 
>     The newer one in /boot/ looks bigger
> 
>     478K Mar 24  2021 loader.efi
> 
> 
> Yea. It is.
> 
> 
>     And the second question is back on bootcode. I already run gpart
>     bootcode:
>     gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 2 nvd0
>     gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 2 nvd1
> 
> 
> If you are booting with UEFI, this code never executes.
> 
>     But I found something in my notes from install time few years ago:
>     gpart bootcode -p /boot/boot1.efifat -i 2 /dev/nvd01
> 
>     What really should be installed on freebsd-boot partition?
>     /boot/gptzfsboot or /boot/boot1.efifat
> 
> 
> /boot/gptzfsboot, assuming that you are using legacy BIOS boot
> and not UEFI boot. If you are using UEFI boot, then the right answer
> is that it doesn't matter since it won't be used.

Yes, this machne boots with UEFI only.
As I ran
	gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 2 /dev/nvd01
am I right I must run
	gpart bootcode -p /boot/boot1.efifat -i 2 /dev/nvd01
to fix it now?

Or for what is boot1.efifat useful?

>     # gpart show
>     =>        40  1953525088  nvd0  GPT  (932G)
>                 40      409600     1  efi  (200M)
>             409640        1024     2  freebsd-boot  (512K)
>             410664      113624        - free -  (55M)
>             524288    20971520     3  freebsd-swap  (10G)
>           21495808  1932001280     4  freebsd-zfs  (921G)
>         1953497088       28040        - free -  (14M)
> 
>     I am sorry for asking this questions but this is the only machine with
>     EFI I had and never did "zpool upgrade" on it.
> 
> 
> Ah, if you've not done a zpool upgrade with the EFI machine, you needn't
> do anything to keep it working.

I did. I did "zpool upgrade" on other machines as well but they were 
legacy BIOS based with simple GPT and there were not any problem. That's 
why I run "zpool upgrade" on this UEFI based machine too and right after 
that I realized there can be some problem.

>     Is there a way to test if the machine will be bootable befor I try to
>     reboot it? The machine is not physically accessible to me so the
>     recovery from failed boot is very problematic.
> 
> 
> In that case, don't update the boot blocks, and don't do a zpool upgrade.

Yes, I think I will never zpool upgrade on this machine again.

Kind regards
Miroslav Lachman