Destroyed bootloader, can it be fixed?

Summary: In trying to fix another boot problem, I used the
Code:
gpart bootcode
command incorrectly and now the drive doesn't show up in the bios menu anymore.

I had a problem that I now believe (but haven't been able to confirm for obvious reasons) to be the same as this: https://forums.freebsd.org/threads/...elease-p1_2023-08-04-and-zpool-upgrade.90680/

Before I saw this message, I thought that there was a problem with the bootcode, so tried to restore it. When I did so, it didn't work (of course, since the problem was different) but after one of my tests, the drive no longer shows up in the bios menu. The command that caused it to happen was, I believe, the following:
Code:
gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 2 ada0
(or maybe I used -i 1, I'm not sure).

I have an idea why that happened. The computer this is running on only supports UEFI boot (at least I don't find any options in the bios menu to change it) so now the drive is unbootable. I tried to restore it using
Code:
gpart bootcode -p /boot/boot1.efi
but the problem persists.

Is there a way in which I can restore this?
 
I've never used bootcode but if your FreeBSD installation is UEFI and you don't see FreeBSD's efi entry in BIOS, then you can try creating one. You can boot from live freebsd media and mount efi partition and then copy loader.efi to the efi partition and create a efi entry with efibootmgr.

To update old ESP partitions, users should stop using the gpart(8) utility. Instead, ESP partitions should be mounted asMS-DOS filesystems as /boot/efi, and/boot/loader.efi should be copied to/boot/efi/efi/boot/bootx64.efi if thedefault setup is used.
 
Thanks. Here's the output:

gpart show:

Code:
=>       40  976773088  nda0  GPT  (466G)
         40     532480     1  efi  (260M)
     532520       1024     2  freebsd-boot  (512K)
     533544        984        - free -  (492K)
     534528    4194304     3  freebsd-swap  (2.0G)
    4728832  972044288     4  freebsd-zfs  (464G)
  976773120          8        - free -  (4.0K)

=>       1  60125183  da0  MBR  (29G)
         1     66584    1  efi  (33M)
     66585   2589968    2  freebsd  [active]  (1.2G)
   2656553  57468631       - free -  (27G)

=>      0  2589968  da0s2  BSD  (1.2G)
        0       16         - free -  (8.0K)
       16  2589952      1  freebsd-ufs  (1.2G)

=>       40  976773088  diskid/DISK-32BA31CMK2T2  GPT  (466G)
         40     532480                         1  efi  (260M)
     532520       1024                         2  freebsd-boot  (512K)
     533544        984                            - free -  (492K)
     534528    4194304                         3  freebsd-swap  (2.0G)
    4728832  972044288                         4  freebsd-zfs  (464G)
  976773120          8                            - free -  (4.0K)

swapinfo:

Code:
Device          512-blocks     Used    Avail Capacity

fstyp /dev/nda0p1

Code:
fstyp: /dev/nda0: filesystem not recognized

fstyp /dev/nda0p2

Code:
fstyp: /dev/nda0p2: filesystem not recognized

It seems that I wiped the filesystem on the UEFI partition. Should I create a new msdosfs filesystem on /dev/nda0p1? I'm kinda worried I'm going to make things worse.
 
Do you remember the FreeBSD version that you had? If you know what version was then first create the same or newer bootable USB drive, so you can copy the loader.efi from the LiveCD which must be the newer or equal to the ZFS version that you have otherwise it won't recognize some ZFS features and it won't import the zfs pool. So if you were on FreeBSD 13.3 / 14 create the same version of the USB.

Then boot into LiveCD and format the ESP partition , mount it and copy the loader.efi to it.

As you ESP partition is big enought you can also use default cluster size and omit "-c 1" during newfs_msdos command, it was needed on smaller partitions where there was not enough space.
newfs_msdos -F 32 -c 1 /dev/nda0p1
mount -t msdosfs /dev/nda0p1 /mnt
mkdir -p /mnt/EFI/BOOT
cp /boot/loader.efi /mnt/EFI/BOOT/BOOTX64.efi

#Note: While you are still in LiveCD and your ESP is mounted under /mnt you may want to recreate the EFI boot entry using efibootmgr(8) like this

efibootmgr -a -c -l /mnt/EFI/BOOT/BOOTX64.efi -L FreeBSD

OR remove the old UEFI boot variables if there's multiple of them. Some Motherboards allow to create this exact same entry via the BIOS menu and modify/remove some entries which are not longer valid via the BIOS menu itself.

After that unmount the /dev/nda0p1 using:


umount /mnt


You also have a freebsd-boot partition which is used for legacy BIOS boot (CSM) you may want to recreate that also only if you use legacy BIOS if not you can completly ignore the existence of it (nda0p2 freebsd-boot)
 
Back
Top