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: 302
Messages: 846

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: 42
Messages: 171

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: 302
Messages: 846

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: 550
Messages: 1,530

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

Aspiring Daemon

Reaction score: 111
Messages: 530

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