1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

FreeBSD accessed via grub2

Discussion in 'General' started by b7j0c, Jul 31, 2009.

  1. b7j0c

    b7j0c New Member

    Messages:
    47
    Thanks Received:
    4
    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:
    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?
     
  2. SirDice

    SirDice Moderator Staff Member Moderator

    Messages:
    17,622
    Thanks Received:
    2,384
    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.
     
  3. Bobarino

    Bobarino New Member

    Messages:
    4
    Thanks Received:
    0
    Have you tried dropping the 'a' and using chainloader +1?

    Code:
    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.
     
  4. hedwards

    hedwards New Member

    Messages:
    189
    Thanks Received:
    19
    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:
    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.
     
  5. nelligan

    nelligan New Member

    Messages:
    2
    Thanks Received:
    0
    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:
    menuentry "freebsd 8.0" {
    	set root=(hd0,2,a)
    	chainloader +1
    }
    
     
  6. ArcherSeven

    ArcherSeven New Member

    Messages:
    1
    Thanks Received:
    0
    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.
     
  7. zeiz

    zeiz New Member

    Messages:
    691
    Thanks Received:
    54
    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.
     
  8. favor

    favor New Member

    Messages:
    15
    Thanks Received:
    0
    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.
     
  9. zeiz

    zeiz New Member

    Messages:
    691
    Thanks Received:
    54
    What problem? I boot FreeBSD (and OpenBSD) from grub2 having beautiful splash 1280x1024.
    This is absolutely correct:
    Code:
    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
     
  10. babel17

    babel17 New Member

    Messages:
    29
    Thanks Received:
    0
    Grub2 (1.97~beta4) works fine with BSD. You can do two things:

    1) do the traditional BSD 2nd stage loader:
    Code:
    	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:
    badtrip# /usr/local/sbin/grub-probe -d /dev/ad4s1 -t fs_uuid
    4b22f9090565ab77
    


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

    Zeniff New Member

    Messages:
    7
    Thanks Received:
    0
    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:
    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.
     
  12. aragon

    aragon New Member

    Messages:
    2,031
    Thanks Received:
    252
    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.
     
  13. phoenix

    phoenix Moderator Staff Member Moderator

    Messages:
    3,446
    Thanks Received:
    769
    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).
     
  14. jafrey

    jafrey New Member

    Messages:
    2
    Thanks Received:
    2
    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.
     
    Grey_Ash and fronclynne thanked for this.
  15. jafrey

    jafrey New Member

    Messages:
    2
    Thanks Received:
    2
    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:
    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:
      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);
     
  16. tux_errante

    tux_errante New Member

    Messages:
    1
    Thanks Received:
    0
    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.
    :\
     
  17. micder

    micder New Member

    Messages:
    3
    Thanks Received:
    0
    Still using lilo (Slackware) to boot FreeBSD:
    Code:
    # FreeBSD
      other = /dev/sda3
      label = FreeBSD
      table = /dev/sda
     
  18. Goette

    Goette New Member

    Messages:
    9
    Thanks Received:
    1
    How to boot FreeBSD 8.0 or PC-BSD 8.0 with grub2:

    Code:
    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)
     
    Elwood thanks for this.
  19. Goette

    Goette New Member

    Messages:
    9
    Thanks Received:
    1
    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:
    #!/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:
    sudo chmod u+x /etc/grub.d/filename


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

    dav New Member

    Messages:
    6
    Thanks Received:
    0
    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.
     
  21. DavidMarec

    DavidMarec New Member

    Messages:
    31
    Thanks Received:
    2

    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./
     
  22. nelligan

    nelligan New Member

    Messages:
    2
    Thanks Received:
    0
    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:

    Code:
    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.
     
  23. Vjetar

    Vjetar New Member

    Messages:
    4
    Thanks Received:
    0
    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:

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


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

    DavidMarec New Member

    Messages:
    31
    Thanks Received:
    2
    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:
    #!/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
    }
    
     
    olivier thanks for this.
  25. cd

    cd New Member

    Messages:
    7
    Thanks Received:
    0
    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.