Solved Adding FreeBSD on GRUB boot menu

In a typical Debian install, /dev/sda1 is created and fat(fat32) partitioned by Debian. Debian creates and hosts the /etc/fstab entry and the supporting configuration files in /etc/grub.d/. I've never tried it, but potentially, one could create a mount point in OpenBSD/FreeBSD and mount the slice containing /boot/efi.
Your statement is perfectly correct, but the issue here I am trying to communicate is that GRUB doesn't boot from Debian or any other OS.
Conceptually, there is a misunderstanding about "root" It is not the location of the FreeBSD installation but the location of OS, in this case Debian, that contains Grub. This is the first stage of the boot process where a boot menu is presented and you are booting Debian. [...] Debian passes the second stage of the boot process to FreeBSD.
The GRUB boot loader (on BIOS or UEFI) is loaded independently of Debian or other operating systems, in fact, no operating system is needed to be booted for GRUB loader to be loaded.

Debian (or any other Linux distribution, or Operating system) has no participation in booting the GRUB loader.

The GRUB loader is stored on BIOS MBR between MBR and first partition.

On BIOS GPT and UEFI GRUB embeds its core images on a unformated "bios-grub" flagged partition. It can be a standalone installation without any OS at all.

Usually the operating system next to the GRUB loader provides within its directory structure stored configuration files, fonts, background images at most. But those can be stored in a non-OS file system, a fat32 formatted EFI partiton, or any other file system GRUB is capable to read from.

Below you will find instructions for reproducing a GRUB installation on a dedicated partition, no Linux (or other OS) installed beside:

BIOS MBR: https://forums.freebsd.org/threads/mount-error.89083/#post-610435

For BIOS GPT create a "bios-grub" partition as described below, continue GRUB installation as instructed in the above link.

UEFI: Assuming sda as the "GRUB on dedicated partition" disk.
  1. Boot Linux Live system (or installation). Partition sda,
  2. create 1MB partition (or minimum permited by a partition manager) unformated
  3. set bios-grub flag for 1MB partition
  4. rest of the disk format fat32
  5. mount fat32 partiton on /mnt
  6. execute
Code:
sudo grub-install --root-directory=/mnt    /dev/sda   --verbose

sudo cp /boot/grub/grub.cfg /mnt/boot/grub
umount /mnt

The grub-install command creates a EFI boot entry, when sda disk is moved to another machine, the GRUB efi loaders path does not match most likely.

On target machine, boot a Live system (Linux, or FreeBSD), delete the EFI menue entry, create a new one for GRUB, ie from Linux live:
Code:
mount -t vfat /dev/sda2 /mnt
efibootmgr -c -L GRUB -l /mnt/EFI/<linux distribution name>/grubx64.efi
efibootmgr -a -b <menue entry number>

Power down machine, remove Live system, power up machine.

Some background image and font might not be found because they are not on the EFI partition, just hit enter until the GRUB menu appears.
 
I think this is splitting hairs and is tangential to the OP question. It essentially applies to any bootloader
Arch Linux Bootloader Wiki

My initial point was the path to loader.efi starts on Debian and needed to be referenced as such in the 40-custom file. This is within the context of the thread where FreeBSD was being added to a /etc/grub.d/40-custom file
 
I think this is splitting hairs and is tangential to the OP question.
With all due respect, don't give me splitting hairs and tangential to the OP question.

You have started making false claims and referencing to loader.efi, which has no role in OPs issue.

My initial point was the path to loader.efi starts on Debian and needed to be referenced as such in the 40-custom file.
There it is again. Although I have clearly pointed this out repeatedly, you insist on a close interaction between loader.efi and Debian where there is none to the OPs issue.

Besides that, your initial point was:
The FreeBSD "root" file system disk identifier is [B]hd0[/B],gpt2 , not [B]hda[/B].
Conceptually, there is a misunderstanding about "root" It is not the location of the FreeBSD installation but the location of OS, in this case Debian, that contains Grub.
The "root" variable doesn't define the location of GRUB, stored inside the OS (which is not the case anyway), it defines the location where to look for files by following GRUB commands in the menu entry, in the case of this thread, the location of /boot/loader within the FreeBSD installation by "kfreebsd" command. In other words, in the location of the FreeBSD installation.

In GPT booting, typically the BOOTX64.EFI (FreeBSD names this loader.efi) code will search for the partition where FreeBSD is installed and start the second stage where FreeBSD loads. Restated; Debian passes the second stage of the boot process to FreeBSD.
A "GPT boot" under UEFI requires an installed BOOTX64.EFI (loader.efi), but not BIOS GPT, neither of which OP's FreeBSD installation has. And again, Debian (or any other OS) has no participation in passing any stage of the boot process to FreeBSD.

You have to place a copy of loader.efi in the Debian directory /boot/efi/ and reconfigure grub in Debian (update-grub) in a virtual terminal (ctl-alt-F3).
Besides the fact that the OPs FreeBSD installation is on BIOS MBR, so loader.efi is useless, why place a extra copy of it in a random place when a copy already exists in the OS's directory structure or ESP created by FreeBSD. That's what the "root" variable is for: Pointing to that location of the loader for the following GRUB command to find.

I am trying to point out statements and procedures to you that are clearly wrong and unnecessary, to make you aware of them so that you can correct your position, in friendly interaction I believe, but you obviously don't want to acknowledge them and prefer to ignore them.

My last comment on this subject.
 
This problem is now officially solved!

The problem was that the WattOS partition table was in MBR and FreeBSD was in GPT. I tried really hard to reinstall WattOS as a GPT partition, but with no success maybe it is automatically installed that way.

So i decided to switch to Fedora LXQT and luckily i installed itself in a GPT table. (i wiped the disk and put the disk in GPT partition table before Fedora installation, just in case it installs it in MBR)

Pro tip for GRUB users, when uncertain how the menuentry should look like, boot Super Grub2 disk, choose menu entry, press "e" for edit mode, copy variables.

View attachment 18941 View attachment 18942

UEFI

View attachment 18946 View attachment 18947

I followed this step that T-Daemon mentioned and copied the FreeBSD (default boot loader) menu entry from Super Grub2 disk, that I installed on my USB, into my /etc/grub.d/40-custom file

menuentry "FreeBSD" "hda1,gpt2" "6624db7610b66841" {
set root="$2"
kfreebsd /boot/loader
}

and updated grub

And FreeBSD menu entry shows up on grub and it boots in to FreeBSD no problem :D
 
There is probably a typo: "hda1,gpt2" should probably be "hd1,gpt2" because grub naming for disk is hd0, hd1 and so on, while Linux naming is hda, hdb and so on.
 
Last edited:
Back
Top