# FreeBSD accessed via grub2



## b7j0c (Jul 31, 2009)

Hi.

i have a box that has both debian (sid) and freebsd-8-beta2. I let Debian own the bootsector and use grub to access either system. with grub1, this works fine

Debian has updated to grub2 and I am having some problems getting FreeBSD to work with it. I use this entry:


```
menuentry "freebsd 8.0" {
	set root=(hd0,2,a)
       freebsd	/boot/loader 
}
```
but I always see an error that the partition cannot be found. I have read inconclusive comments elsewhere that grub2 cannot (yet) BSD partitions. 

Any ideas?


----------



## SirDice (Jul 31, 2009)

It looks like they're not using savanna anymore to track bugs. I can't find any reference to what bug tracking they're currently using though.

So you may want to drop the developers a note, they can probably point you in the right direction.


----------



## Bobarino (Aug 7, 2009)

Have  you tried dropping the 'a' and using chainloader +1?


```
menuentry "freebsd 8.0" {
	set root=(hd0,2)
       chainloader +1
}
```

I haven't used Grub2 yet, so I don't know if it works, but the Archwiki example makes use of it for booting Windows.


----------



## hedwards (Aug 9, 2009)

b7j0c said:
			
		

> any ideas?


Yes, the partition numbering apparently changed from grub1 to grub2, it's apparently no longer indexed to 0, so that partition probably doesn't exist at all as far as grub is concerned. I'd try changing it to read:

```
menuentry "freebsd 8.0" {
	set root=(hd0,3,a)
       freebsd	/boot/loader 
}
```

and see if that does anything for you. Unless of course you've already done that and neglected to mention that.


----------



## nelligan (Dec 1, 2009)

There's no "freebsd" command counterpart to the "linux" command used only for loading a Linux kernel, not a BSD one. So you have to chainload FreeBSD's bootloader.

The correct form's as following:


```
menuentry "freebsd 8.0" {
	set root=(hd0,2,a)
	chainloader +1
}
```


----------



## ArcherSeven (Dec 3, 2009)

Ok, I've just downloaded and not yet installed FreeBSD; but one thing is: in grub2 default (and I'm assuming debian but not sure) drive numbering starts on 1.  so your /dev/sda2  [(hd0,2) in grub legacy] will be (hd1,2) now.  Thought that may be it.


----------



## zeiz (Dec 3, 2009)

Not quite right.
In Grub2 drives are still counted from 0 but partitions from 1.
So if hd0,5 in Grub1 was for partition#6 (sda6 in linux) that is hd0,6 (sda6) now in Grub2.


----------



## favor (Dec 7, 2009)

Hi,

Have you boot your FreeBSD right now using grub2? if you make it, please let me know. I am struggling with the same problem as you 

And any howtos are welcome.


----------



## zeiz (Dec 8, 2009)

What problem? I boot FreeBSD (and OpenBSD) from grub2 having beautiful splash 1280x1024.
This is absolutely correct:

```
menuentry "FreeBSD 8.0" {
	set root=(hd0,1,a)
	chainloader +1
}
```
The only thing that could be wrong is what partition do you use for FreeBSD. I use 1st partition (as shown above) just change it for what you have ("a" is essential). As I wrote in this thread disk numbering starts from "0" same like in legacy grub but partition numbering now starts from "1" in grub2 (it was "0" in legacy grub). 
I assume you run `sudo update-grub` after inserting the menuentry in /etc/grub.d/40_custom


----------



## babel17 (Dec 18, 2009)

Grub2 (1.97~beta4) works fine with BSD.  You can do two things:

1) do the traditional BSD 2nd stage loader:

```
menuentry "FreeBSD ad4, via /boot/loader" {
        	insmod ufs2
        	set root=(hd0,1,a)
        	freebsd /boot/loader
	}
```
or you can boot the FreeBSD kernel directly.  In order to boot the kernel directly, it is best to run grub-probe to get the fs_uuid.  I don't know if you can run grub-probe against a FreeBSD filesystem from Linux, I've only ever done it from FreeBSD.


```
badtrip# /usr/local/sbin/grub-probe -d /dev/ad4s1 -t fs_uuid
4b22f9090565ab77
```

Then use that to set up the direct boot:

```
menuentry "FreeBSD ad4, direct" {
		insmod ufs2
		set root=(hd0,1,a)
		search --no-floppy --fs-uuid --set 4b22f9090565ab77
		freebsd                 /boot/kernel/kernel
		freebsd_loadenv         /boot/device.hints
		set FreeBSD.vfs.root.mountfrom=ufs:/dev/ad4s1a
		set FreeBSD.vfs.root.mountfrom.options=rw
	}
```

It will actually work without search line, but that's the "canonnical" way to do it.


----------



## Zeniff (Jan 6, 2010)

I have a question.

With this thread having at least 3 correct ways to boot FreeBSD, I'm wondering, what's the difference between all of them?

I'm trying to boot FreeBSD too, and have tried the simpler-looking one mentioned above, which worked for me:

```
menuentry "FreeBSD 8.0" {
	set root=(hd0,1,a)
	chainloader +1
}
```

But, will my boot times or OS performance be different in any way if I try the other ways?

Sorry if it's a silly question. I'm new and don't even know what much of the syntax means, such as the "insmod ufs2" or other parts. I feel weird that there isn't just some simple table available online stating what to enter to boot each OS.


----------



## aragon (Jan 6, 2010)

Zeniff said:
			
		

> Will my boot times or OS performance be different in any way if I try the other ways?


Zero change to performance.  OS boot times will be unaffected, but the time taken for the boot loader to do its thing might be affected by its configuration.


----------



## phoenix (Jan 6, 2010)

chainloader is the shotgun approach, and will work with any OS that includes a boot loader in the first block of the root partition.  Grub doesn't do anything special, just loads the first block, and passes control over to whatever is stored there.  This could be boot0 (the FreeBSD boot manager with the F1, F2, F3 menu), /boot/loader (the nice ASCII boot menu), or something else.

The next method is more specific to FreeBSD, and tells GRUB to look into a specific filesystem for /boot/loader, and then run that program, bringing up the nice FreeBSD ASCII boot menu.

The last method is even more specific, and tells GRUB to look into a specific filesystem for /boot/kernel/kernel and boots directly into the FreeBSD kernel, by-passing /boot/loader completely.  All the extra entries are to pass information to the kernel that is normally done via /boot/loader.

Which you use depends on how FreeBSD-specific you want to be, and whether or not you want to see the FreeBSD boot menu(s).


----------



## jafrey (Jan 29, 2010)

This is the first hit for FreeBSD and grub2, so I thought I'd help out.
-
After fighting with grub2 constantly and trying to get my boot completed I finally figured out that the command has changed from freebsd to kfreebsd.

`freebsd /boot/kernel` should be
`kfreebsd /boot/kernel`

Who knows if it'll change again, grub2 documentation leaves A LOT to desired, I finally figured this out with a:
`strings bsd.mod`

Should this change in the future.


----------



## jafrey (Jan 30, 2010)

Can't really blame anyone but the Debian guys and their whole 'kernel of FreeBSD' side project .

The latest version released a few days ago 1.97.2 uses kfreebsd and it's not just a Debian Package thing.

From the changelog:

```
2009-10-14  Robert Millan  <rmh.grub@aybabtu.com>

	Refer to kernel of FreeBSD "kFreeBSD" to avoid confusion between
	the Operating System (FreeBSD) and its kernel (kernel of FreeBSD).

	* loader/i386/bsd.c (grub_freebsd_boot): Read kernel environment
	from "kFreeBSD" namespace (rather than "FreeBSD").  Update all
	users.

	(GRUB_MOD_INIT (bsd)): Rename "freebsd" command to "kfreebsd",
	"openbsd" to "kopenbsd", "netbsd" to "knetbsd", "freebsd_loadenv"
	to "kfreebsd_loadenv", "freebsd_module" to "kfreebsd_module",
	and "freebsd_module_elf" to "kfreebsd_module_elf".  Update all
	users.
```

Relevant lines to loader/i386/bsd.c

```
cmd_freebsd = grub_register_extcmd ("kfreebsd", grub_cmd_freebsd,
				      GRUB_COMMAND_FLAG_BOTH,
				      "kfreebsd FILE", "Load kernel of FreeBSD.",
				      freebsd_opts);
  cmd_openbsd = grub_register_extcmd ("kopenbsd", grub_cmd_openbsd,
				      GRUB_COMMAND_FLAG_BOTH,
				      "kopenbsd FILE", "Load kernel of OpenBSD.",
				      openbsd_opts);
  cmd_netbsd = grub_register_extcmd ("knetbsd", grub_cmd_netbsd,
				     GRUB_COMMAND_FLAG_BOTH,
				     "knetbsd FILE", "Load kernel of NetBSD.",
				     netbsd_opts);
```


----------



## tux_errante (Feb 13, 2010)

Zeniff said:
			
		

> I have a question.
> 
> With this thread having at least 3 correct ways to boot FreeBSD, I'm wondering, what's the difference between all of them?
> 
> ...



System: grub2, PCBSD 8 on /dev/sda1

I've tried this and others suggestions before, but I can't access to PCBSD 8.
The chainloader reload the grub2 !
It's the same if I change (hd0,1,a) with (hd0,0,a)

I've seen also this, and this but are too olds.
:\


----------



## micder (Feb 13, 2010)

Still using lilo (Slackware) to boot FreeBSD:

```
# FreeBSD
  other = /dev/sda3
  label = FreeBSD
  table = /dev/sda
```


----------



## Goette (Mar 2, 2010)

How to boot FreeBSD 8.0 or PC-BSD 8.0 with grub2:


```
menuentry "FreeBSD 8.0 (on /dev/ad0s2)" {
	set root=(hd0,2)
	chainloader +1
	boot
}
```

Considering that you have installed the FreeBSD bootloader at the beginning of the ad0s2 partition (not in MBR) an additional menu will display (at least for PC-BSD 8.0)


----------



## Goette (Mar 2, 2010)

To automatically add the entry when using update-grub don't just edit /boot/grub/grub.cfg but too the script that creates that file. Add to /etc/grub.d/filename this:


```
#!/bin/bash

echo "Adding Custom PC-BSD system" >&2
cat << EOF
menuentry "PC-BSD_Unix_KDE" {
        set root=(hd0,2)
   chainloader +1
   boot
         }

EOF
```


```
sudo chmod u+x /etc/grub.d/filename
```

For more information:
https://wiki.ubuntu.com/Grub2


----------



## dav (Apr 5, 2010)

babel17 said:
			
		

> Grub2 (1.97~beta4) works fine with BSD.  You can do two things:
> 
> 1) do the traditional BSD 2nd stage loader:
> 
> ...



This worked perfectly. I edited it to reflect my drives, and uuid.
Interestingly, I tried the "kfreebsd" trick mentioned below first, it hung and returned an error on the second line "kfreebsd_loadenv", but not the first. Maybe they changed that again.

With grub2, none of the other methods worked for me. With 0.97, almost any example listed here and elsewhere would work.


----------



## DavidMarec (May 9, 2010)

babel17 said:
			
		

> Grub2 (1.97~beta4) works fine with BSD.  <snip>
> Then use that to set up the direct boot:
> 
> ```
> ...




Trying this above, 
- changed freebsd to kfreebsd -
the booting process dropped into the "manual mount point entry" prompt.
where, typing "ufs:/dev/ad4s1a" runs fine.
- My FreeBSD box was installed in the same way than yours - 

/I took care about the uppercase letters./


----------



## nelligan (May 11, 2010)

*buggy syntax*

After reinstalling Xubuntu with the new 10.04 version and searching again to add FreeBSD to the boot menu, this syntax worked for me:


```
menuentry "FreeBSD"
{
insmod ufs2
set root='(hd2,1)'
chainloader +1
}
```

with a blank line at the end. I leave the { and } characters alone on their respective lines. Seems like the update-grub and update-grub2 scripts bug either on these characters or the ending blank line. Note that grub2 answers "error file not found" though FreeBSD boots, whether you specify the sub-partition '(hd2,1,a)' or not '(hd2,1)'. grub-probe returns the latter syntax.


----------



## Vjetar (May 29, 2010)

*Ubuntu 10.04 Grub2 & FreeBSD 8.0*

Just to add my two cents to this thread since its first hit on Google for "grub2 FreeBSD".

After hours of reading documentation, googleing, and experimenting with various "menuentry" options I finally discovered solution for my problem.

First of all, both ways (via /boot/loader or /boot/kernel) works fine with Ubuntu 10.04. Here are examples:


```
menuentry "FreeBSD 8.0 via /boot/loader" {
	insmod ufs2
	set root='(hd1,4,a)'
	search --no-floppy --fs-uuid --set 4c0029f407b3cd1d
	kfreebsd /boot/loader
}
```


```
menuentry "FreeBSD 8.0 direct" {
	insmod ufs2
	set root='(hd1,4,a)'
	search --no-floppy --fs-uuid --set 4c0029f407b3cd1d
	kfreebsd /boot/kernel/kernel
	kfreebsd_loadenv /boot/device.hints
	kfreebsd_module /boot/splash.bmp type=splash_image_data
	set kFreeBSD.vfs.root.mountfrom=ufs:ad6s4a
}
```

You need to replace UUID in both examples, "ad6s4a" with your FreeBSD root partition in second example  and of course edit entries to point to your rooot partition.

Problem which took me several hours to solve had simple solution (as it always seems simple when solved). Linux /dev/sdc was drive where FreeBSD was installed and I assumed Grub2 sees it as hd2. *Terminaly wrong!* Grub2 sees it as hd1 which I finally manage to find out in grub command prompt typing "ls (hd1)". hd0 is mapped in linux as /dev/sda and hd2 is mapped as /dev/sdb.

@babel17: You can get fs_uuid from Grub2 commad line typing:

```
ls (hd0,1)
```

Above two examples are slightly modified from one found in /usr/share/doc/grub-common/examples/grub.cfg


----------



## DavidMarec (May 29, 2010)

Vjetar said:
			
		

> Just to add my two cents to this thread since its first hit on Google for "grub2 FreeBSD".
> 
> ```
> menuentry "FreeBSD 8.0 direct" {
> ...


Damn, *k*FreeBSD.vfs* of course !

Okay, now this one is working better on my side.
But, there is still an issue: Most of the tunable knobs ( /boot/loader.conf) are not loaded at boot, doing this way.

Here is my /etc/grub.d/40_Custom, for the record:


```
#!/bin/sh
exec tail -n +3 $0
# This file provides an easy way to add custom menu entries.  Simply type the
# menu entries you want to add after this comment.  Be careful not to change
# the 'exec tail' line above.
menuentry "FreeBSD, way of shotgun" {
    set root=(hd0,1)
    chainloader +1
}


menuentry "FreeBSD, boot easy" {
	insmod ufs2
	set root=(hd0,1,a)
	kfreebsd /boot/loader
}


menuentry "FreeBSD, direct boot" {
    insmod ufs2
    set root=(hd0,1,a)
    search --no-floppy --fs-uuid --set 4a86db44195cac47
    kfreebsd /boot/kernel/kernel
    kfreebsd_loadenv /boot/device.hints
    set kFreeBSD.vfs.root.mountfrom=ufs:/dev/ad4s1a
    set kFreeBSD.vfs.root.mountfrom.options=rw
}
```


----------



## cd (Oct 14, 2010)

Yeah, besides changing configuration parse, structure and location, and shortcuts in grub2, I just wonder why they decided to change partition numbering but did not change the disk numbering - this is why I dont like Linux anymore - it has no standard at all.


----------



## Vjetar (Oct 14, 2010)

cd said:
			
		

> Yeah, besides changing configuration parse, structure and location, and shortcuts in grub2, I just wonder why they decided to change partition numbering but did not change the disk numbering - this is why I dont like Linux anymore - it has no standard at all.



It's not linux thing. You can always use some other bootloader.


----------



## cd (Oct 16, 2010)

Vjetar said:
			
		

> It's not linux thing. You can always use some other bootloader.



Well, okay, it's not only the Linux thing is to change everything all the time in a confusing way - when they changed to start counting from 1, it should impact all counting, I guess.

Unfortunately, I can also use Windows bootloader to boot the FreeBSD, as the BSD's loader cannot load Linux (grub2) and Win (>5) anymore..?


----------



## alantis13 (Oct 19, 2010)

I am having problems with grub2 as well.

I want to run FreeBSD on the 2nd partition and creating /boot/grub/grub.cfg with


```
menuentry "FreeBSD"{
    insmod ufs2
    set root=(hd0,2,a)
    kfreebsd /boot/loader
    chainloader +1
}
```
 does not work.

I tried the following commands:
[cmd=]grub-install hd0[/cmd]
[cmd=]grub-install /dev/ad4[/CMD] gives me errors on grub-probe.

However, 
[CMD=]grub-install --modules=part_gpt /dev/ad4[/CMD]
[CMD=]grub-mkconfig[/cmd] 
has no errors but get thrown in grub rescue with no way to read /boot from any slices or partitions.


----------



## Vjetar (Oct 19, 2010)

alantis13 said:
			
		

> I am having problems with grub2 as well.
> I want to run FreeBSD on the 2nd partition and creating /boot/grub/grub.cfg with



grub2 is not configured via grub.cfg any more. Here are some useful articles about grub2 configuring: 
	
	



```
https://wiki.ubuntu.com/Grub2
```


----------



## ahavatar (Oct 20, 2010)

alantis13 said:
			
		

> I am having problems with grub2 as well.
> 
> I want to run FreeBSD on the 2nd partition and creating /boot/grub/grub.cfg with
> 
> ...



My grub2 install on Ubuntu looks like:


```
menuentry "FreeBSD"{
    set root=(hd0,2)
    chainloader +1
}
```


It has chainload+1 and just the whole FreeBSD partition (not slice specific). Try it if it works.


----------



## alantis13 (Oct 20, 2010)

Sorry wrong thread, too many tabs open. My situation is grub related just that no flavor of Linux is involved, only Windows and FreeBSD. Yes I can boot FreeBSD via grub2 (installed through ports system) when it is on the 1st partition, however that is not what I want. Anyways, I appreciate your guys' time trying to help me.

No need to repond to this post.


----------



## Yampress (Dec 10, 2010)

easy


```
menuentry "FreeBSD 8-STABLE " {
	insmod ufs2
    	set root=(hd0,3) 
	chainloader +1
	}
```

change this set root=(hd0,3) and be okay.


----------



## user0 (Mar 25, 2014)

*Re:*



			
				zeiz said:
			
		

> Not quite right.
> In Grub2 drives are still counted from 0 *but partitions from 1*.
> So if hd0,5 in Grub1 was for partition#6 (sda6 in linux) that is hd0,6 (sda6) now in Grub2.


Wow, good to know! I knew grub2 developer had serious issues, but this is over the top.


----------

