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: 309
Messages: 852

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: 44
Messages: 174

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: 309
Messages: 852

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: 629
Messages: 1,667

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 [USER=55022]Thanatophobia[/USER] 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 [USER=55022]Thanatophobia[/USER] 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

Aspiring Daemon

Reaction score: 177
Messages: 687

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: 629
Messages: 1,667

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.
 
Top