upgrade to 25.7 -> bootloader too old

Started by mnaim, July 26, 2025, 01:52:07 AM

Previous topic - Next topic
Quote from: Patrick M. Hausen on July 28, 2025, 09:56:40 PMPlan some time for a reinstallation with ZFS and a reasonably large EFI partition ;-)

First of all, thanks for all your help! Just a question for the future - do I understand you correctly that if the boot partition is 512K it would be a good idea to plan for a repartitioning followed by a reinstall at some convenient point in the future? I run ZFS and my gpart output looks like this:
# gpart show -l
=>       40  234441568  ada0  GPT  (112G)
         40     532480     1  efiboot0  (260M)
     532520       1024     2  gptboot0  (512K)
     533544        984        - free -  (492K)
     534528   16777216     3  swap0  (8.0G)
   17311744  217128960     4  zfs0  (104G)
  234440704        904        - free -  (452K)
(I realise that the boot partition size is not a current issue but a theoretical future one.) I don't suppose there is a way to do a repartitioning in situ without a full reinstall?
OPNsense 25.7.2-amd64 on APU2E4 using ZFS

@beneix may I ask when you installed your system?

I thought that newer installer images create a bigger bootfs partition... If that's not the case, maybe there is a way to change that during install.

I first set up my OPNsense install in August 2022, which means 22.7, and it made a 260MB EFI partition at the time. I'm assuming that was done by the OPNsense installer, as I don't remember having the ability to change partition sizes.

July 29, 2025, 08:40:43 AM #48 Last Edit: July 29, 2025, 08:43:26 AM by beneix
Quote from: tessus on July 29, 2025, 07:47:34 AM@beneix may I ask when you installed your system?
The system was purchased in 2022 and I installed UFS. Then in 2024 I decided to take the leap and re-install with ZFS - I think it was when 24.7.1 was out. I don't recall giving any particular input to sizing, I think I just let the installer set the defaults, but I could be wrong.
OPNsense 25.7.2-amd64 on APU2E4 using ZFS

July 29, 2025, 09:00:19 AM #49 Last Edit: July 29, 2025, 10:34:54 AM by tessus
Thanks for the info.

Please ignore the next paragraph. (Keeping it for some laughs.) I must have been out of my mind...
The bootloader is not in the EFI partition but in the bootfs partition. When I installed OPNsense in 2021, the bootloader was less than 300KB and now it's 658432 bytes. I am a bit fuzzy as to why it says 512KB for my bootfs partition, because when I mount it, it's actually 779K. So I am really lucky, because otherwise the 658432 bytes wouldn't have fit. But according to most manuals, one should actually copy the loader twice and this will definitely not work with the current 512KB bootfs partition. So in a few years the bootloader is bigger than the partition and then it's over.

You cannot mount the legacy boot loader partition. It does not contain a file system. That's the partition you write with this command:

gpart bootcode -b /boot/pmbr -p /boot/gptboot -i 2 ada0

And if you look at /boot/gptboot or /boot/gptzfsboot they are way below 200k in size so a 512k partition is more than enough.

What you can mount is EFI partition which is FAT32 formatted. And 779k is too small for that nowadays. 260M as the OPNsense installer creates now, OTOH, is again more than enough.

Partition 2: legacy boot loader - 512k
Partition 1: EFI - 260M

"bootfs" is just a label, it does not in any way say that there is an actual file system on that one.

HTH,
Patrick
Deciso DEC750
People who think they know everything are a great annoyance to those of us who do. (Isaac Asimov)

Patrick, you told me to add the following to my fstab:

/dev/ada0p1    /boot/efi       msdosfs     rw,noauto             2       2

I did that and when I mounted it, df showed me the following:

Filesystem                   Size    Used   Avail Capacity  Mounted on
/dev/gpt/rootfs              100G     15G     77G    16%    /
devfs                        1.0K      0B    1.0K     0%    /dev
devfs                        1.0K      0B    1.0K     0%    /var/dhcpd/dev
devfs                        1.0K      0B    1.0K     0%    /var/unbound/dev
/usr/local/lib/python3.11    100G     15G     77G    16%    /var/unbound/usr/local/lib/python3.11
/lib                         100G     15G     77G    16%    /var/unbound/lib
/dev/ada0p1                  779K    644K    135K    83%    /boot/efi

So something is wrong with your last comment, because I mounted the legacy bootloader with the commands you gave me.

Th only other explanation is that my 200MB EFI partition has a 779K msdos filesystem on it, which makes no sense. Once again, here is my gpart output:

gpart show
=>       40  234441568  ada0  GPT  (112G)
         40     409600     1  efi  (200M)
     409640       1024     2  freebsd-boot  (512K)
     410664  215567272     3  freebsd-ufs  (103G)
  215977936   16777216     4  freebsd-swap  (8.0G)
  232755152    1686456        - free -  (823M)

That can well be the case, if the partition was installed with "dd" of a precreated FAT32 image as FreeBSD used to do some time ago.

To fix that, assuming you have the fstab entry in place:

newfs_msdos /dev/ada0p1
mount /boot/efi
mkdir -p /boot/efi/efi/boot /boot/efi/efi/freebsd
cp /boot/loader.efi /boot/efi/efi/boot/bootx64.efi
cp /boot/loader.efi /boot/efi/efi/freebsd/loader.efi
umount /boot/efi

HTH,
Patrick
Deciso DEC750
People who think they know everything are a great annoyance to those of us who do. (Isaac Asimov)

Ha, ok. This is interesting. I thought that I mounted the 2 partition for some reason, since the size was very close to the 512K. And who knows what weird byte calculations OSes do these days. e.g. I grew up with base-2 sizes and not using the i size notation. These days, it's a mess, especially because often the wrong units are used. Very annoying and confusing.

Quote from: tessus on July 29, 2025, 09:59:41 AMPatrick, you told me to add the following to my fstab:

/dev/ada0p1    /boot/efi       msdosfs     rw,noauto             2       2

I did that and when I mounted it, df showed me the following:

Filesystem                   Size    Used   Avail Capacity  Mounted on
/dev/gpt/rootfs              100G     15G     77G    16%    /
devfs                        1.0K      0B    1.0K     0%    /dev
devfs                        1.0K      0B    1.0K     0%    /var/dhcpd/dev
devfs                        1.0K      0B    1.0K     0%    /var/unbound/dev
/usr/local/lib/python3.11    100G     15G     77G    16%    /var/unbound/usr/local/lib/python3.11
/lib                         100G     15G     77G    16%    /var/unbound/lib
/dev/ada0p1                  779K    644K    135K    83%    /boot/efi

So something is wrong with your last comment, because I mounted the legacy bootloader with the commands you gave me.

ada0p1 is the EFI partition, the legacy boot loader is ada0p2. You cannot mount the legacy boot loader. It's not a file system.
Deciso DEC750
People who think they know everything are a great annoyance to those of us who do. (Isaac Asimov)

Based upon this output:

root@OPNsense:~ # cat /etc/fstab
# Device                Mountpoint      FStype  Options         Dump    Pass#
/dev/gpt/efiboot0               /boot/efi       msdosfs rw              2       2
/dev/ada0p3             none    swap    sw              0       0
/dev/ada1p3             none    swap    sw              0       0


root@OPNsense:~ # gpart show
=>       40  937703008  ada0  GPT  (447G)
         40     532480     1  efi  (260M)
     532520       1024     2  freebsd-boot  (512K)
     533544        984        - free -  (492K)
     534528   16777216     3  freebsd-swap  (8.0G)
   17311744  920389632     4  freebsd-zfs  (439G)
  937701376       1672        - free -  (836K)

=>       40  937703008  ada1  GPT  (447G)
         40     532480     1  efi  (260M)
     532520       1024     2  freebsd-boot  (512K)
     533544        984        - free -  (492K)
     534528   16777216     3  freebsd-swap  (8.0G)
   17311744  920389632     4  freebsd-zfs  (439G)
  937701376       1672        - free -  (836K)

Is it safe (and correct) to run this:

mkdir -p /boot/efi/efi/boot /boot/efi/efi/freebsd
cp /boot/loader.efi /boot/efi/efi/boot/bootx64.efi
cp /boot/loader.efi /boot/efi/efi/freebsd/loader.efi

I don't plan on moving these drives to a new system, if I do, it'll be booting UEFI just like this one is. 

Quote from: bedub1 on August 05, 2025, 12:11:37 AMIs it safe (and correct) to run this:
[...]

Most probably so. It won't hurt. If it has the desired effect depends on two things:

1. Are you sure you are booting via UEFI?

Did you check

sysctl machdep.bootmethod

If the output is "BIOS" instead of "UEFI" you are not booting via UEFI and if you update the EFI loader or not is irrelevant.

2. You have two drives - probably in a redundant configuration? ZFS mirror?

If yes you want to be able to boot from the second drive if the first one fails. So even if everything is fine and you are indeed EFI booting your system, you need to update the boot partition on the second drive, too.

The OPNsense default setup assumes there is a single device and the /etc/fstab entry only mounts that.

To update the second drive you need to first check what device "/dev/gpt/efiboot0" really is. You can do this by:

gpart show -l

If the "efiboot0" partition is (reasonably so) on drive "ada0" then the easiest way is to perform the update first and then:

# unmount the EFI partition on ada0
umount /boot/efi
# replicate it to the second drive
dd if=/dev/ada0p1 of=/dev/ada1p1 bs=1m
# remount the EFI partition
mount /boot/efi

HTH,
Patrick
Deciso DEC750
People who think they know everything are a great annoyance to those of us who do. (Isaac Asimov)

August 05, 2025, 12:49:28 AM #58 Last Edit: August 05, 2025, 12:55:49 AM by bedub1
Yup, it's UEFI
root@OPNsense:~ # sysctl machdep.bootmethod
machdep.bootmethod: UEFI

Yes it's a mirror, but this command with the -l doesn't change the output
root@OPNsense:~ # gpart show -l
=>       40  937703008  ada0  GPT  (447G)
         40     532480     1  efiboot0  (260M)
     532520       1024     2  gptboot0  (512K)
     533544        984        - free -  (492K)
     534528   16777216     3  swap0  (8.0G)
   17311744  920389632     4  zfs0  (439G)
  937701376       1672        - free -  (836K)

=>       40  937703008  ada1  GPT  (447G)
         40     532480     1  efiboot1  (260M)
     532520       1024     2  gptboot1  (512K)
     533544        984        - free -  (492K)
     534528   16777216     3  swap1  (8.0G)
   17311744  920389632     4  zfs1  (439G)
  937701376       1672        - free -  (836K)

root@OPNsense:~ #
I ran all your commands and my boot loader is no longer too old.  Thanks!

Patrick, thanks again for your help.

Just for anyone who stumbled across this topic: My 200MB EFI partition had a 779K filesystem on it. The reason could be from previous methods of requisition from FreeBSD or OPNsense of said partition (e.g. via dd or other methods). I made the mistake of confusing this fact with the legacy partition that had a similar size. As mentioned before I am not a FreeBSD person, thus my experience with it is very limited. Patrick is clearly the person to ask, and in case my comments came across as rude or hostile I want to sincerely apologize. This was never my intention and I know very well that reading comments are conceived differently than listening to a face-to-face conversation.

I can't stress enough how impressed I am by OPNsense and its community. Thank you for all the help I have received so far.