Solved Upgrade RootOnZFS from FreeBSD 12.1 to 12.2

After running the zpool upgrade zroot command the following message is printed:

Code:
If you boot from pool 'zroot', 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
but my system is running in UEFI, the above message is wrong.
Code:
# sysctl machdep.bootmethod
machdep.bootmethod: UEFI
The disks layout is:
Code:
# gpart show
=>        40  7814037088  ada0  GPT  (3.6T)
          40      409600     1  efi  (200M)
      409640        1024     2  freebsd-boot  (512K)
      410664         984        - free -  (492K)
      411648     4194304     3  freebsd-swap  (2.0G)
     4605952  7809429504     4  freebsd-zfs  (3.6T)
  7814035456        1672        - free -  (836K)

=>        40  7814037088  ada1  GPT  (3.6T)
          40      409600     1  efi  (200M)
      409640        1024     2  freebsd-boot  (512K)
      410664         984        - free -  (492K)
      411648     4194304     3  freebsd-swap  (2.0G)
     4605952  7809429504     4  freebsd-zfs  (3.6T)
  7814035456        1672        - free -  (836K)

=>        40  7814037088  ada2  GPT  (3.6T)
          40      409600     1  efi  (200M)
      409640        1024     2  freebsd-boot  (512K)
      410664         984        - free -  (492K)
      411648     4194304     3  freebsd-swap  (2.0G)
     4605952  7809429504     4  freebsd-zfs  (3.6T)
  7814035456        1672        - free -  (836K)

To upgrade the boot code is better to use these commands :
Code:
# mount -t msdosfs /dev/ada0p1 /mnt/efi
# cp /boot/loader.efi /mnt/efi/efi/boot/BOOTX64.EFI
# umount /mnt/efi
# mount -t msdosfs /dev/ada1p1 /mnt/efi
# cp /boot/loader.efi /mnt/efi/efi/boot/BOOTX64.EFI
# umount /mnt/efi
# mount -t msdosfs /dev/ada2p1 /mnt/efi
# cp /boot/loader.efi  /mnt/efi/efi/boot/BOOTX64.EFI
# umount /mnt/efi
or these ones ?
Code:
# gpart bootcode -p /boot/boot1.efifat -i 1 ada0
# gpart bootcode -p /boot/boot1.efifat -i 1 ada1
# gpart bootcode -p /boot/boot1.efifat -i 1 ada2


Thanks in advance
Maurizio
 
boot1.efi is deprecated (and therefore, boot1.efifat as well – seems it was removed in 13).
The *.efifat isn't being created anymore, yes. boot1.efi is still there:
Code:
root@molly:~ # ll /boot/boot1.efi
-r-xr-xr-x  1 root  wheel  114176 Mar  6 17:08 /boot/boot1.efi*
root@molly:~ # uname -a
FreeBSD molly.dicelan.home 13.0-STABLE FreeBSD 13.0-STABLE #20 stable/13-n244796-99e1b2d7986: Sat Mar  6 16:08:11 CET 2021     root@molly.dicelan.home:/usr/obj/usr/src/amd64.amd64/sys/MOLLY  amd64

The *.efifat image was removed because it ultimately overwrites everything in the efi partition. Which is problematic if you dual-boot for example and have multiple EFI loaders.
 
In addition, using boot1.efifat creates a filesystem exactly the size of the loader, so you wont be able to append any data even though your EFI partition has sufficient space. As your disks have both, ESP and freebsd-boot partitions, you should update both bootloaders to retain the ability to boot in either UEFI or legacy BIOS mode.
 
In any case, the best way to fix it is to mount the efi partition and copy loader.efi to it. Not sure if the installer is already fixed for this but it should get mounted on /boot/efi. You can add this to fstab if it doesn't get mounted:
Code:
/dev/gpt/efiboot0       /boot/efi       msdosfs rw              0       0
 
Thank you for your answers.
I have written a script for updating the boot code either for UEFI and the legacy BIOS mode, for this server:
Bash:
#!/bin/sh
#
set -xu
mkdir -p /mnt/efi
mount -t msdosfs /dev/ada0p1 /mnt/efi
cp /boot/loader.efi /mnt/efi/efi/boot/BOOTX64.EFI
umount /mnt/efi
mount -t msdosfs /dev/ada1p1 /mnt/efi
cp /boot/loader.efi /mnt/efi/efi/boot/BOOTX64.EFI
umount /mnt/efi
mount -t msdosfs /dev/ada2p1 /mnt/efi
cp /boot/loader.efi /mnt/efi/efi/boot/BOOTX64.EFI
umount /mnt/efi
gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 2 ada0
gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 2 ada1
gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 2 ada2
set +xu
# EOF

After running the script I have successfully rebooted the server.
 
The old efifat image was with FAT size of 800KB so you may need to reformat the EFI partition first to it's full 200MB in case you need more space for bigger efi loader or other tools in that partition.

To check the FAT size just mount the partition and use " df -h"
When you have more space on the EFI you can keep the old BOOTx64.efi (loader.efi) under different name and switch between different loaders from Startup.nsh file which is called by default (if found) by the UEFI.
 
The old efifat image was with FAT size of 800KB so you may need to reformat the EFI partition first to it's full 200MB in case you need more space for bigger efi loader or other tools in that partition.

To check the FAT size just mount the partition and use " df -h"
When you have more space on the EFI you can keep the old BOOTx64.efi (loader.efi) under different name and switch between different loaders from Startup.nsh file which is called by default (if found) by the UEFI.
Thank you for the explanation, the EFI partition is already 200MB, the next time I need to upgrade the boot code I will make a backup of the old BOOTx64.efi file.
 
In any case, the best way to fix it is to mount the efi partition and copy loader.efi to it. Not sure if the installer is already fixed for this but it should get mounted on /boot/efi. You can add this to fstab if it doesn't get mounted:
Code:
/dev/gpt/efiboot0       /boot/efi       msdosfs rw              0       0
sed s/rw/rw,noauto/ < @SirDice/fstab >> /etc/fstab
 
The EFI partition is 200MB but if you previously apply an efifat image you end up with FAT32 filesystem with size of 800KB so you are not using the entire 200MB of that partition and when you try to copy new files you will end up with error of out of space.
 
Back
Top