Solved Bootloader problem

I spent months trying to build a multiboot disk which would load up FreeBSD's GRUB and display a number of bootable OSes. Recently I installed Debian on a second disk in my laptop and it seems to have touched the multiboot disk in some way which I cannot figure out. Now when I try booting my multiboot disk, it no longer comes up with the GRUB menu but immediately EFI boots FreeBSD from /dev/(a)da0p2 depending on whether the disk is attached internally or externally.

gpart show:-
Code:
=>       40  625142368  da0  GPT  (298G)
         40     409600    1  efi  (200M)
     409640  104857600    2  freebsd-ufs  (50G)
  105267240    2097152    3  freebsd-swap  (1.0G)
  107364392   10485760    4  freebsd-ufs  (5.0G)
  117850152    4194304    5  freebsd-ufs  (2.0G)
  122044456   62914560    6  ms-basic-data  (30G)
  184959016       2048    7  linux-data  (1.0M)
  184961064    4194304    8  ms-basic-data  (2.0G)
  189155368    4194304    9  freebsd-ufs  (2.0G)
  193349672    6291456   10  freebsd-ufs  (3.0G)
  199641128   20971520   11  ms-basic-data  (10G)
  220612648   10485760   12  freebsd-swap  (5.0G)
  231098408  209715200   13  freebsd-ufs  (100G)
  440813608   20971520   14  linux-data  (10G)
  461785128   10485760   15  linux-data  (5.0G)
  472270888   12582912   16  linux-data  (6.0G)
  484853800   20971520   17  freebsd-ufs  (10G)
  505825320  119317088       - free -  (57G)

What could have changed?
 
From my understanding I should compare /boot/pmbr with the first sector of the disk to see if it has changed.

Comments?
 
The Debian installer has probably installed another EFI loader to the partition da0p1 and updated the UEFI nvram variable BootOrder to boot with its own loader. The new loader seems to boots by default from the first partition after the EFI one.

The EFI boot sequence does not use the MBR, instead it loads the boot loader from the first partition on the disk. In which partition was the grub2-efi installed? It might be possible to reset the default boot loader via UEFI/BIOS menu.
 
The Debian installer has probably installed another EFI loader to the partition da0p1 and updated the UEFI nvram variable BootOrder to boot with its own loader. The new loader seems to boots by default from the first partition after the EFI one.

The EFI boot sequence does not use the MBR, instead it loads the boot loader from the first partition on the disk. In which partition was the grub2-efi installed? It might be possible to reset the default boot loader via UEFI/BIOS menu.

I didn't see any options in any BIOS menu. Here's the disk layout:-
Code:
root@Test:~ # gpart show -p da1
=>       40  625142368     da1  GPT  (298G)
         40     409600   da1p1  efi  (200M)
     409640  104857600   da1p2  freebsd-ufs  (50G)
  105267240    2097152   da1p3  freebsd-swap  (1.0G)
  107364392   10485760   da1p4  freebsd-ufs  (5.0G)
  117850152    4194304   da1p5  freebsd-ufs  (2.0G)
  122044456   62914560   da1p6  ms-basic-data  (30G)
  184959016       2048   da1p7  linux-data  (1.0M)
  184961064    4194304   da1p8  ms-basic-data  (2.0G)
  189155368    4194304   da1p9  freebsd-ufs  (2.0G)
  193349672    6291456  da1p10  freebsd-ufs  (3.0G)
  199641128   20971520  da1p11  ms-basic-data  (10G)
  220612648   10485760  da1p12  freebsd-swap  (5.0G)
  231098408  209715200  da1p13  freebsd-ufs  (100G)
  440813608   20971520  da1p14  linux-data  (10G)
  461785128   10485760  da1p15  linux-data  (5.0G)
  472270888   12582912  da1p16  linux-data  (6.0G)
  484853800   20971520  da1p17  freebsd-ufs  (10G)
  505825320  119317088          - free -  (57G)

I can't say I've ever heard of 'UEFI nvram variable BootOrder ', in fact UEFI is still a big mystery to me, but are you suggesting that Debian has made some changes to the disk itself? Getting the initial Grub configuration took some doing and it is still in da1p2/boot/grub/grub.cfg but the system no longer boots into grub but starts the FreeBSD efi boot.

I probably need to run something like gpart bootcode -b /boot/pmbr -p /boot/gptboot -i 1 da1 but am worried that I may break something...
 
That gpart command is used to install bootcode to a freebsd-boot partition. But since you have no such partition, your system boots the FreeBSD efi loader da1p1/EFI/boot/bootx64.efi directly from the efi partition. Which in turn uses da1p2 as the root filesystem without loading grub.

Actually, I think the boot order has not changed, but the loader bootx64.efi is currently the FreeBSD default efi loader boot1.efi. You will have to replace it with the grub loader:
cp /efi/grub/grubx64.efi /efi/boot/bootx64.efi
 
That gpart command is used to install bootcode to a freebsd-boot partition. But since you have no such partition, your system boots the FreeBSD efi loader da1p1/EFI/boot/bootx64.efi directly from the efi partition. Which in turn uses da1p2 as the root filesystem without loading grub.

Actually, I think the boot order has not changed, but the loader bootx64.efi is currently the FreeBSD default efi loader boot1.efi. You will have to replace it with the grub loader:
cp /efi/grub/grubx64.efi /efi/boot/bootx64.efi

I'm not sure what you are referring to by cp /efi/grub/grubx64.ef....

By /efi/ do you mean da1p1? I thought that was a DOS partition and I'm sure I was able to mount it before, but now I get
Code:
root@Test:~ # mount -t msdofs /dev/da1p1 /mnt/dos
mount: /dev/da1p1: Operation not supported by device
There is no /efi/ directory under /dev/da1p2. Grub was installed originally using sysutils/grub2-efi
 
Inside the efi partition da1p1 should be a directory named /efi/.

Try fstyp /dev/da1p1 to find out what the file system is. It should be msdosfs (fat32) or else the efi partition is broken.

Your command has a slight typo, it should be:
mount -t msdo[B]s[/B]fs /dev/da1p1 /mnt/dos
 
Inside the efi partition da1p1 should be a directory named /efi/.

Try fstyp /dev/da1p1 to find out what the file system is. It should be msdosfs (fat32) or else the efi partition is broken.

Your command has a slight typo, it should be:
mount -t msdo[B]s[/B]fs /dev/da1p1 /mnt/dos

Sorry about the typo - should have spotted it...

I remember creating the efi partition /dev/da0p1 - I did it using this code:-
Code:
dd if=/boot/boot1.efifat of=/dev/da0p1
mount -t msdosfs /dev/da0p1 /mnt
#grub-install --boot-directory=/boot --bootloader-id=grub --efi-directory=/mnt/e
grub-install --boot-directory=/boot --bootloader-id=grub --efi-directory=/mnt --

but I note that /boot/boot1.efifat no longer exists in 11.1-RELEASE, so I wouldn't know how to create the efi partition.

I copied the file you mentioned and now the GRUB menu does come up, but only on x32 systems. I tried it on my ThinkPad X220 but it would not boot at all.
 
That file should not affect x32 systems. The x32 efi loader /efi/boot/bootia32.efi was already in place and works correctly. Maybe you should try to reinstall grub to the efi partition (no need to recreate it) like before in this post: Error While Installing GRUB2-EFI
 
FWIW, Linux usually has the efibootmgr command, which allows you to view and change the EFI boot order. The syntax for changing boot order is ... demanding, but it works.
Also, if you can get to an UEFI shell from the UEFI / BIOS menu on your machine, you can start a different bootloader (for example grub, to boot Linux) manually.
 
I get completely lost when I see the efi shell. Is there a handy guide?

After installing TrueOS the other day it presents a graphical efi boot manager. I'd like to know how this is installed... Since TrueOS is based on FreeBSD it should be possible to do it from native FreeBSD.
 
Unfortunately, there isn't a handy guide for EFI shells (at least I haven't found one yet). If you google "EFI shell" and "EFI commands" you will get several articles with info. Some of them are useful. I used that and some experimentation to get working knowledge on how to operate in an EFI shell.
The problem with (U)EFI today is that is about as mature as BIOS was 20 - 25 years ago, implementations vary a lot in functionality and usability.
 
I finally did this correctly and it restored my GRUB, so many thanks.

Well it seemed to work, but I never tested it properly. None of the FreeBSD options work, I just get a horizontal white bar in the top left hand corner.

Linux Mint and Ubuntu do start but they produce an error msg first:-
Code:
error: no suitable video mode found
Booting in blind mode

but after a few seconds you can see the boot msgs.

I have tried the same disk in other x64 laptops and get the same response.

I can't imagine what is going on here.
 
Back
Top