Solved How do I configure Grub2 to boot FreeBSD 11.1

Thanatophobia

New Member


Messages: 6

I have a computer with a dual-core amd64 processor and a 500 GB hard drive which is labeled sda. Here are my partitions on the hard drive.
  • sda1 332.24 GB NTFS - Windows 7 Home Premium 32-bit Service Pack 1 + Master Boot Record and Grub2, labeled C:
  • sda2 9.5 GB NTFS - HP Windows Vista 32-bit factory image, labeled D:
  • sda3 56.92 GB ext3 - Ubuntu Linux Mint 18.3 "Sylvia" 64-bit Cinnamon edition
  • sda4 64 GB UFS - FreeBSD 11.1 64-bit (subpartitioned with 61 GB for freebsd-ufs and 3 GB for freebsd-swap)
  • 233 MB unallocated space
My installed bootloader is Grub2, which can recognize and boot Linux Mint and its boot options, Windows 7, and the Windows Vista factory image. But after I installed FreeBSD on sda4, it does not appear on Grub2. How do I configure Grub2 to recognize and boot into FreeBSD?
 

shepper

Aspiring Daemon

Reaction score: 324
Messages: 874

There are some confusing parts of your post that indicate that you do not fully comprehend what a Master Boot Record is. The MBR is usually at the very beginning of the disk space and contains the partition information. sda1 would start after the MBR. reference: https://en.wikipedia.org/wiki/Master_boot_record.

It is possible to install grub2 in windows but more likely, it is part of your Linux install.
If your are using grub2 from linux, many examples of using /etc/grub.d/40_custom to boot FreeBSD can be found searching this forum and the internet.
 

gnath

Active Member

Reaction score: 46
Messages: 187

If your are using grub2 from linux, many examples of using /etc/grub.d/40_custom to boot FreeBSD
You have to insert in /boot/grub/grub.cfg between start/end
Code:
menuentry "FreeBSD 11.1" {
set root= '(hd0,4)'                   #1st disk, 4th slice
chainloader (hd0,4)+1
}
Then update grub.
 
OP
T

Thanatophobia

New Member


Messages: 6

You have to insert in /boot/grub/grub.cfg between start/end
Code:
menuentry "FreeBSD 11.1" {
set root= '(hd0,4)'                   #1st disk, 4th slice
chainloader (hd0,4)+1
}
Then update grub.

How do I add the code into grub.cfg? I tied to edit the file directly, but it does not let me edit it.
 

shepper

Aspiring Daemon

Reaction score: 324
Messages: 874

I would not recommend editing /boot/grub/grub.cfg directly - it will be over-written every time update-grub is executed. update-grub reads the entries in /etc/grub.d/ when it is run and generates /boot/grub/grub.cfg. update-grub will read the /etc/grub.d/40_custom entry as I initially suggested.

My sense is that you also did not understand my prodding you to show some initiative and search the forums yourself:
Here is the search: Thread 60407
 
Last edited:

scottro

Daemon

Reaction score: 894
Messages: 2,043

Or just create a /boot/grub2/custom.cfg (depending upon distribution, that's for RH based systems.) Put it in the same directory that has grub.cfg.

The chainloader entry given by Thanatophobia works most of the time. Another option (again, assuming it was the 4th partition is
Code:
menuentry "FreeBSD" {
set root='(hd0,4)'
kfreebsd /boot/loader
}
 
OP
T

Thanatophobia

New Member


Messages: 6

I did what gnath and sheeper suggested me to do: I edited /etc/grub.d/40_custom on the terminal of Linux Mint using the GNU nano editor and wrote the code in there and saved it, and I updated grub2. When updating, grub reads FreeBSD as an "unknown Linux distribution". When I restarted my computer to get to the Grub2 bootloader, the entry for FreeBSD appears, but when I try to boot into it, it shows a "read error" message before restarting my computer.

I'll try what scottro suggested to see if that works.
 
OP
T

Thanatophobia

New Member


Messages: 6

I
Or just create a /boot/grub2/custom.cfg (depending upon distribution, that's for RH based systems.) Put it in the same directory that has grub.cfg.

The chainloader entry given by Thanatophobia works most of the time. Another option (again, assuming it was the 4th partition is
Code:
menuentry "FreeBSD" {
set root='(hd0,4)'
kfreebsd /boot/loader
}

I did what scottro suggested and it finally works! Thanks!
 

d-at-niel

New Member


Messages: 1

Since this is a popular google search result I wanted to add my experience. I added the following to my /etc/grub.d/40_custom and then ran the 'sudo update-grub'.
Code:
menuentry "FreeBSD 12.1" {
set root=(hd0,1)
chainloader (hd0,1)+1
}

Note that I did not use the single quotes around the root hd section. That was key.
 

Alain De Vos

Daemon

Reaction score: 642
Messages: 2,154

Even without any bsd bootloader you can use something like,
Code:
menuentry "FREEBSD_DIRECTBOOT" {
insmod part_gpt
insmod part_msdos
insmod ufs2
insmod bsd
set root=(hd1,gpt3)
kfreebsd /boot/kernel/kernel
kfreebsd_loadenv /boot/device.hints
set kFreeBSD.vfs.root.mountfrom=ufs:/dev/ada1p3
}
 
Last edited by a moderator:

mgp

Active Member

Reaction score: 13
Messages: 106

I was able to boot FreeBSD 12.1 via grub2 like this:
Add the following to /etc/grub.d/40_custom:
Code:
menuentry "FreeBSD" {
set root=(hd0,9)                      # in my case ada0p9
chainloader /boot/loader.efi
}
Then run: grub2-mkconfig -o /boot/grub2/grub.cfg
And reboot.

Enjoy.
 

scottro

Daemon

Reaction score: 894
Messages: 2,043

This thread, though several months old, seems to be one the first that comes up when I look for grub2 freebsd efi and similar terms. With
legacy BIOS boot, it is fine for me with
Code:
menuentry "FreeBSD" {
set root='(hd0,4)'
kfreebsd /boot/loader
}
as I posted above. However with Uefi, that doesn't work. So far, I have two choices. This is a Thinkpad and when I hit F12 after the Lenovo menu, I'm given a list of boot devices. One of them says FreeBSD, and I can select that and boot.

As for a grub2 entry, I made a custom.cfg in /boot/efi/EFI/fedora. I had the closest thing to success with mgp's choice, but it still gives errors. However, if I then hit e as if to edit, then hit ctl+c for a command prompt, I get a grub> prompt. If I then type exit, it boots into FreeBSD. I don't quite get what's happening, I've never made a huge study of grub, since it usually did what I wanted till I decided to forgo legacy and catch up with modern times, using Uefi. So, I can't call it a success, but at least it allows me to boot into FreeBSD from a machine with Uefi bios, with Linux also installed, and using that LInux's (Fedora in this case--if I add another Linux distribution to play with, Fedora's grub boots it) grub to boot it.
 

Russell Rinaldi

New Member

Reaction score: 6
Messages: 6

I had similar issues adding FreeBSD 13.0 Release to my Linux Mint grub2 menu. I found two things:

  • There was a BIOS setting on my ASUS x570, ("boot compatibility mode" approx) that was turned off. Once that was set on, the BIOS listed the FreeBSD drive in the boot menu (F8) which previously only showed the Win10 and Mint discs. Turning on this setting also removed an annoying keyboard ghosting/double entry that was preventing me from using the grub> command prompt to detect drives and settings.

  • I had specified syscons with a higher resolution (1920x1080) rather than vt(4), which caused efi boot errors. I removed lines for sc in /boot/loader.conf and allscreens_flags="MODE_334" in rc.conf, so that the default vt(4) is used for console.
I added the following to /etc/grub.d/40-custom on linux where hd3 (FreeBSD drive) is linux /dev/sdd and gpt2 is the second partition:

Code:
menuentry "FreeBSD-13.0 Release" {
set root='(hd3,gpt2)'
chainloader /boot/boot1.efi
}

Then ran
update-grub

On reboot, FreeBSD boots from grub at screen resolution of 1028x764. I think everyone's settings might be different, so your mileage may vary, hope this helps anyone else who is having a hard time getting grub2 to boot FreeBSD.
 

Alain De Vos

Daemon

Reaction score: 642
Messages: 2,154

There is
Code:
/boot/boot1.efi
/boot/gptboot.efi
/boot/loader.efi
/boot/loader_simp.efi
/boot/efi
 

Vull

Aspiring Daemon

Reaction score: 441
Messages: 733

Use loader.efi (uefi(8)). boot1.efi(8) has been deprecated and will be removed from a future release.
I've long used /boot/loader.efi for UEFI booting, however, earlier this year, discovered to my surprise that it no longer worked in Ubuntu 20.04, or in its derivative, Linux Mint 20.1. The Ubuntu branch of grub2 will still put the entries for FreeBSD in the boot menu, but selecting those entries doesn't do anything, neither booting FreeBSD, nor yielding any error messages.

Using /boot/loader.efi still works for the version of grub2 that comes with Debian 9.13 or Debian 10.9. I haven't tested any other Linux distributions.

More recently I discovered that using /boot/boot1.efi does work for the same Ubuntu versions mentioned above, successfully booting FreeBSD 13.0, but only after displaying a number of error messages in rapid succession. This method has the added limitation that it will only boot a single FreeBSD install on a given hard drive. I have several FreeBSD root partitions on my 1 TB hard drive, so this limited functionality is of little use to me. It will only boot the FreeBSD install on the lowest numbered GPT partition. Therefore I'll continue to use Debian for this purpose, and hope that the Ubuntu revisions to grub2 don't infect Debian.

In anticipation that this (the back-porting of Ubuntu's grub2 to Debian) could foreseeably happen in the near future, I've prepared to reinstall an older un-updated version of Debian 9, for the sole purpose of booting my FreeBSD partitions on this laptop.

I don't know exactly why Ubuntu's version of grub2 has been changed in this way. A clue or two might be gleaned from this article: https://ubuntu.com/blog/grub2-secure-boot-bypass-2021

In general, I've never been very much inclined to recommend grub2 as a reliable cross-platform booting method for any serious purposes, and I'm even less inclined to make such a recommendation now.
 

T-Daemon

Daemon

Reaction score: 875
Messages: 1,749

I've long used /boot/loader.efi for UEFI booting, however, earlier this year, discovered to my surprise that it no longer worked in Ubuntu 20.04, or in its derivative, Linux Mint 20.1.
Indeed, loader.efi is no good.

More recently I discovered that using /boot/boot1.efi does work for the same Ubuntu versions mentioned above, successfully booting FreeBSD 13.0, but only after displaying a number of error messages in rapid succession.
Have you tried loader_4th.efi? That works too. I had the impression it's faster than boot1.efi, but it is also deprecated. It was replaced by loader_lua.efi, which also doesn't play well with GRUB2 neither.

This method has the added limitation that it will only boot a single FreeBSD install on a given hard drive. I have several FreeBSD root partitions on my 1 TB hard drive, so this limited functionality is of little use to me. It will only boot the FreeBSD install on the lowest numbered GPT partition. Therefore I'll continue to use Debian for this purpose, and hope that the Ubuntu revisions to grub2 don't infect Debian.
No problem here on a test system: Grub 2.02, Mint 19.2, FreeBSD 12.2 (UFS2), Mint 20.1, FreeBSD 13 (UFS2). Menu entries for FreeBSD:
Code:
menuentry 'FreeBSD 12.2' {
           chainloader (hd1,gpt2)/boot/loader_4th.efi
}

menuentry 'FreeBSD 13' {
           chainloader (hd3,gpt2)/boot/loader_4th.efi
}

You could also check out rEFInd. Maybe it's more suitable for your situation. For testing it can be run from CD or USB.



Unfortunately, pointing grub at loader.efi doesn't work for me. When set up that way, the boot screen goes immedately back to grub when attempting to boot FreeBSD 13 REL.
Understood. I suggested vull rEFInd, maybe it might interest you too, for future releases, when boot1.efi and loader_4th.efi are gone and in case GRUB2 hasn't been patched until then. On a test system, other than the above mentioned, it works fine in a Linux/FreeBSD multi OS environment, booted from USB and after testing installed on disk .
 

Vull

Aspiring Daemon

Reaction score: 441
Messages: 733

Thanks T-Daemon. Your advice is much appreciated and informative. For now I'm content to just continue using Debian and /boot/loader.efi, which I've used for several years and has always been consistent. I like consistency and I like the fact that loader.efi doesn't seem so likely to be deprecated. If Debian ever fails me I'll look into using rEFInd.

For more serious purposes, I wouldn't even consider using grub to boot FreeBSD, but find it convenient and cost-effective to use a multi-boot system for a personal laptop, rather than purchasing multiple boxes, which would be much more expensive, and impractical to carry around from place to place.

There are many other benefits, as I'm sure you realize. One can more accurately gauge and compare the performance of different systems, or variations of the same system, if they're all running on exactly the same hardware. One can quickly try out new ideas at low risk, by installing small, temporary test systems. If it doesn't work as anticipated, the other working systems remain unaffected by the changes, and the test systems can be easily deleted. One can use a shared partition to share files between systems, instead of using slower USB drives, or transferring the files over a network. If a system hangs for any reason, one can boot a similar system and use it to mount and repair the hung partition. And so forth and so on.
 

Alain De Vos

Daemon

Reaction score: 642
Messages: 2,154

There is nothing wrong in chainloading freebsd using the grub loader. I use it and it is convenient.
 

Vull

Aspiring Daemon

Reaction score: 441
Messages: 733

There is nothing wrong in chainloading freebsd using the grub loader. I use it and it is convenient.
Did you read this article? https://ubuntu.com/blog/grub2-secure-boot-bypass-2021

As a rule I prefer to use native system tools for everything possible. Grub is not native to FreeBSD, and I'd never really want to have more than one OS on any production system in any case. What would be the point? Only one OS can be running at any one time, and most live systems in my experience are up and running full time, all the time. On such a system there's no reason not to just use the same bootloader that FreeBSD installs automatically.
 

scottro

Daemon

Reaction score: 894
Messages: 2,043

For me, and probably others, it's just a matter of liking to be able to play with a few different things, and one does get a better picture if it's on bare metal instead of in a VM. On my two main towers, plus my work workstation, I'm only running one O/S, but I have a couple of laptops to play with as well. I can even give a use case. I want FreeBSD to test various things I might want at work, but wireless and a few other programs, work far better on Linux, so for usual use, I'd want Linux on the laptop. (The workstations all use ethernet). But that's really going off topic, I guess, right now, in my multiboots, I'm using FreeBSD on a ZFS partition as per tutorials on this forum, and the grub entries that tutorial had work for me.
 
Top