FreeBSD accessed via grub2

General questions about the FreeBSD operating system. Ask here if your question does not fit elsewhere.

FreeBSD accessed via grub2

Postby b7j0c » 31 Jul 2009, 03:58

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:

Code: Select all
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?
b7j0c
Junior Member
 
Posts: 43
Joined: 21 Mar 2009, 03:43

Postby SirDice » 31 Jul 2009, 07:35

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.
Senior UNIX Engineer at Unix Support Nederland
Experience is something you don't get until just after you need it.
User avatar
SirDice
Old Fart
 
Posts: 16185
Joined: 17 Nov 2008, 16:50
Location: Rotterdam, Netherlands

Postby Bobarino » 07 Aug 2009, 21:04

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

Code: Select all
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.
Bobarino
Junior Member
 
Posts: 4
Joined: 24 Nov 2008, 19:02
Location: Vermont, USA

Postby hedwards » 09 Aug 2009, 18:13

b7j0c wrote: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:
Code: Select all
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.
hedwards
Member
 
Posts: 189
Joined: 16 Nov 2008, 18:52

freebsd accessed via grub2

Postby nelligan » 01 Dec 2009, 19:44

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:

Code: Select all
menuentry "freebsd 8.0" {
   set root=(hd0,2,a)
   chainloader +1
}
nelligan
Junior Member
 
Posts: 2
Joined: 01 Dec 2009, 19:33

Postby ArcherSeven » 03 Dec 2009, 03:21

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.
ArcherSeven
Junior Member
 
Posts: 1
Joined: 03 Dec 2009, 03:12

Postby zeiz » 03 Dec 2009, 22:04

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.
User avatar
zeiz
Member
 
Posts: 691
Joined: 19 Nov 2008, 18:36
Location: Canada

Postby favor » 07 Dec 2009, 08:30

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.
favor
Junior Member
 
Posts: 15
Joined: 17 Oct 2009, 06:52

Postby zeiz » 08 Dec 2009, 05:26

What problem? I boot FreeBSD (and OpenBSD) from grub2 having beautiful splash 1280x1024.
This is absolutely correct:
Code: Select all
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
User avatar
zeiz
Member
 
Posts: 691
Joined: 19 Nov 2008, 18:36
Location: Canada

Postby babel17 » 18 Dec 2009, 19:23

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

1) do the traditional BSD 2nd stage loader:
Code: Select all
   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.

Code: Select all
badtrip# /usr/local/sbin/grub-probe -d /dev/ad4s1 -t fs_uuid
4b22f9090565ab77


Then use that to set up the direct boot:
Code: Select all
   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.
babel17
Junior Member
 
Posts: 29
Joined: 08 May 2009, 18:19
Location: I'm standing right behind you

Postby Zeniff » 06 Jan 2010, 09:53

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:
Code: Select all
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.
Zeniff
Junior Member
 
Posts: 7
Joined: 03 Jan 2010, 02:14

Postby aragon » 06 Jan 2010, 16:19

Zeniff wrote: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.
aragon
Giant Locked
 
Posts: 2031
Joined: 16 Nov 2008, 17:04
Location: Cape Town, South Africa

Postby phoenix » 06 Jan 2010, 17:10

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).
Freddie

Help for FreeBSD: Handbook, FAQ, man pages, mailing lists.
User avatar
phoenix
MFC'd
 
Posts: 3349
Joined: 17 Nov 2008, 05:43
Location: Kamloops, BC, Canada

Postby jafrey » 29 Jan 2010, 03:41

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
Junior Member
 
Posts: 2
Joined: 29 Jan 2010, 03:14

Postby jafrey » 30 Jan 2010, 16:40

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:
Code: Select all
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
Code: Select all
  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);
jafrey
Junior Member
 
Posts: 2
Joined: 29 Jan 2010, 03:14

Postby tux_errante » 13 Feb 2010, 14:27

Zeniff wrote: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:
Code: Select all
menuentry "FreeBSD 8.0" {
   set root=(hd0,1,a)
   chainloader +1
}



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.
:\
tux_errante
Junior Member
 
Posts: 1
Joined: 13 Feb 2010, 14:19
Location: latina (Italy)

Postby micder » 13 Feb 2010, 18:30

Still using lilo (Slackware) to boot FreeBSD:
Code: Select all
# FreeBSD
  other = /dev/sda3
  label = FreeBSD
  table = /dev/sda
micder
Junior Member
 
Posts: 3
Joined: 12 Feb 2010, 15:14
Location: Terneuzen, Netherlands

Postby Goette » 02 Mar 2010, 16:58

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

Code: Select all
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
Junior Member
 
Posts: 9
Joined: 02 Mar 2010, 16:53

Postby Goette » 02 Mar 2010, 17:10

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:

Code: Select all
#!/bin/bash

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

EOF


Code: Select all
sudo chmod u+x /etc/grub.d/filename


For more information:
https://wiki.ubuntu.com/Grub2
Goette
Junior Member
 
Posts: 9
Joined: 02 Mar 2010, 16:53

Postby dav » 05 Apr 2010, 02:42

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

1) do the traditional BSD 2nd stage loader:
Code: Select all
   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.

Code: Select all
badtrip# /usr/local/sbin/grub-probe -d /dev/ad4s1 -t fs_uuid
4b22f9090565ab77


Then use that to set up the direct boot:
Code: Select all
   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.


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.
dav
Junior Member
 
Posts: 6
Joined: 31 Mar 2010, 12:16

Postby DavidMarec » 09 May 2010, 15:19

babel17 wrote:Grub2 (1.97~beta4) works fine with BSD. <snip>
Then use that to set up the direct boot:
Code: Select all
   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
   }




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./
DavidMarec
Junior Member
 
Posts: 31
Joined: 08 Apr 2009, 13:18
Location: Toulouse

buggy syntax

Postby nelligan » 11 May 2010, 00:36

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

Code: Select all
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.
nelligan
Junior Member
 
Posts: 2
Joined: 01 Dec 2009, 19:33

Ubuntu 10.04 Grub2 & FreeBSD 8.0

Postby Vjetar » 29 May 2010, 02:45

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:

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


Code: Select all
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:
Code: Select all
ls (hd0,1)


Above two examples are slightly modified from one found in /usr/share/doc/grub-common/examples/grub.cfg
Vjetar
Junior Member
 
Posts: 4
Joined: 29 May 2010, 01:40

Postby DavidMarec » 29 May 2010, 15:04

Vjetar wrote:Just to add my two cents to this thread since its first hit on Google for "grub2 FreeBSD".
Code: Select all
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
}


Damn, kFreeBSD.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:

Code: Select all
#!/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
}
DavidMarec
Junior Member
 
Posts: 31
Joined: 08 Apr 2009, 13:18
Location: Toulouse

Postby cd » 13 Oct 2010, 23:32

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.
cd
Junior Member
 
Posts: 7
Joined: 13 Oct 2010, 23:28

Next

Return to General

Who is online

Users browsing this forum: No registered users and 0 guests