Install FreeBSD 13.0 alongside with other OS's on UEFI system via GRUB2 (Multiboot)

Hi there,
Nowadays, UEFI boot and multiboot is a matter for all of us. We have more storage, GPT let us have many primary partitions and after all, with a boot loader like GRUB you will do it, Have a system with a few OS for Gaming, Developing, Testing, Work, etc.

Most setups end like this:
1. Windows installed
2. A Linux installation that setup grub for multiboot
3. Installing the next OS(s)

Well, I was in 3rd step and installed a FreeBSD 13.0 as my first experience.

With this setup you already have an EFI partition:
How to know which one?
[Linux shell]
Bash:
# fdisk -l
/dev/sda1       2048   1085439   1083392  529M Windows recovery environment
/dev/sda2    1085440   1290239    204800  100M EFI System    <<<<<<<-----This one
/dev/sda3    1290240   1323007     32768   16M Microsoft reserved
/dev/sda4    1323008 148125695 146802688   70G Microsoft basic data
/dev/sda5  148125696 221526015  73400320   35G Linux filesystem
/dev/sda6  221526016 255080447  33554432   16G Linux swap
/dev/sda7  255082496 458174463 203091968 96.9G Linux filesystem
/dev/sda8  458174464 500117503  41943040   20G Linux filesystem <<<<<And here I was instelled FreeBSD
[BSD shell](this is not actual gpart output, but for to be light instead of picture I just typed it)
Bash:
# 
# gpart show 
ada0 GPT (238G)
   -    free - (1.@M)
   1    ms-recovery (529M)
   2    efi (100M)  <<<<<<---- EFI
   3    ms-reserved (16M)
   4    ms-basic-data (78G)
   5    linux-data (35G)
   6    linux-swap (16G)
   -    free - (1.8M) 
   7    linux-data (97G) 
   8    linux-data (206) <<<<<----- Installation Partition

and finally GRUB:
reboot system, wait for GRUB menu hit the Esc key that brings the GRUB shell and follows:

Bash:
grub> ls
(hd0) (hd0,gpt8) (hd0,gpt7) (hd0,gpt6) (hd0,gpt5) (hd0,gpt4) (hd0,gpt3) (hd0,gpt2) (hd0,gpt1)

What we got by now : ( this partitions ID's are important, for next steps)
Code:
        +------------------+-------------------+
        | EFI partition ID | Ins. partition ID |
+-------+------------------+-------------------+
| GRUB  |    (hd0,gpt2)    |    (hd0,gpt8)     |
+-------+------------------+-------------------+
| Linux |    /dev/sda2     |    /dev/sda8      | 
+-------+------------------+-------------------+
| F.BSD |   /dev/ada0p2    |   /dev/ada0p8     |
+-------+------------------+-------------------+

So for installation, I just downloaded the ISO and made a Bootable USB with dd:
[Linux shell]
Bash:
# dd if=FreeBSD13.0.iso of=/dev/sdc bs=4MB status=progress
Boot with it, and just installed it as normal installation.

after installation, keep an eye on buttons you chose after you see the installation progress, just hit Live CD not Reboot!
After entering the shell we must mount the EFI partition and copy BSD boot loader in it as follow:
[BSD shell]
Bash:
# mount -t msdosfs /dev/ada0p2 /mnt
# cd /mnt/EFI
# ls
Boot    Microsoft     ubuntu
# mkdir FreeBSD
#cp /boot/boot1.efi /mnt/EFI/FreeBSD/BOOTX64.efi
#umount /mnt

We are done on the BSD side, hit reboot and boot with your Linux OS.

LINUX SIDE
Open a terminal and find the UUID of EFI partition:
your UUID may differ by mine:
Look for /dev/sda2 as we found sn the previous steps as EFI partition.
Bash:
# sudo blkid
/dev/sda6: UUID="d55b4a8f-93e7-49ee-b7fa-4f0517b7fa05" TYPE="swap" PARTUUID="7e422d58-eea7-457e-8e92-478631b07b6f"
/dev/sda5: UUID="54b3dd90-9c15-428a-9339-0884a27d8b61" TYPE="ext4" PARTLABEL="LINUX" PARTUUID="cba6881d-0183-4b87-80d9-5559248fa9a9"
/dev/sda1: LABEL="Recovery" UUID="CED04DA8D04D981B" TYPE="ntfs" PARTLABEL="Basic data partition" PARTUUID="c81cc3ac-d71d-4d77-81e2-207045b0d5cc"
/dev/sda2: UUID="3850-560B" TYPE="vfat" PARTLABEL="EFI system partition" PARTUUID="f1a9a8a3-ef49-4abd-9d69-a9d3e542eae1"
/dev/sda4: UUID="DC822AEC822ACABA" TYPE="ntfs" PARTLABEL="Basic data partition" PARTUUID="d6efe4da-13ef-4e15-b686-ffdc9b1a1d41"
/dev/sda7: UUID="e1c27ed5-26b8-4a07-9d20-cbb8921c4561" TYPE="ext4" PARTLABEL="USER_SPACE" PARTUUID="e7459488-57fa-445a-bc5f-4300644ca30f"
/dev/sda8: UUID="9743a2ff-8ea6-4a1f-ad2e-40236cc812da" TYPE="ext4" PARTUUID="2bedb30a-ec3c-432e-b9d4-0d7aca00e538"
Here the UUID is 3850-560B that we need for next step
Open file /etc/grub.d/40_custom with root accoutn and just append these lines:
JUST APPEND LINES AFTER LAST COMMENT LINE, that starts with #
Code:
menuentry "FreeBSD" --class freebsd --class bsd --class os {
  insmod part_gpt 
  insmod ufs2
  insmod bsd
  set root='**GRUB EFI Partition ID**'
  if [ x$feature_platform_search_hint = xy ]; then
  search --no-floppy --fs-uuid --set=root --hint-bios=**GRUB EFI Partition ID** --hint-efi=**GRUB EFI Partition ID** *UUID HERE*
  else
  search --no-floppy --fs-uuid --set=root *UUID HERE*
  fi
  chainloader /EFI/BOOTX64.efi
}
For our example installation it must be look like this:
Code:
menuentry "FreeBSD" --class freebsd --class bsd --class os {
  insmod part_gpt 
  insmod ufs2
  insmod bsd
  set root='hd0,gpt2'
  if [ x$feature_platform_search_hint = xy ]; then
  search --no-floppy --fs-uuid --set=root --hint-bios=hd0,gpt2 --hint-efi=hd0,gpt2 3850-560B
  else
  search --no-floppy --fs-uuid --set=root 3850-560B
  fi
  chainloader /EFI/BOOTX64.efi
}


Final steps :
Bash:
# chmod +x /etc/grub.d/40_custom
# grub-mkconfig -o /boot/grub/grub.cfg

And done.

Footnotes:
Why /boot/boot1.efi? read the FreeBSD UEFI man page.
The idea about chainloader? Just enter the GRUB boot menu and locate the Windows menu item, then hit the "e" key to see the source of the menu entry, that's how GRUB tell the BIOS to boot other OS in UEFI matters...
Is this works for other versions of FreeBSD with UEFI and Multiboot setup?
This is about standards of FreeBSD UEFI, GRUB and how UEFI systems working, I say yes it will work in most cases.
 
You may or may not know this but FreeBSD 13.0 is not supported on this forum. Only official releases are supported. I say this in case people use this HOWTO and have questions.
 
Looks like useful so thanks for this tuto. But, yes... Why 13-CURRENT? You took the "last" version without knowing what this means and implies...

And please:
multiboot is a matter for all of us
This statement is... I don't know how to qualify it. TV advertising level?
 
Mamrezo your method really works with UEFI (no legacy option)
i was looking for a solution for a very long time before i found your post.

I am sending a big Thank You
 
Back
Top