Dual Boot (FreeBSD+Gentoo) on MBR

Hello,

I recently installed FreeBSD 9.2 and now I have the issue of adding it to GRUB2. The partition scheme is MBR and the hard drive tree is like this:
  • /dev/sda1 (FreeBSD slice containing / UFS2 and swap) Primary MBR partition
  • /dev/sda2 (Gentoo -- ext4 -- / partition) Primary MBR partition
  • /dev/sda3 (Gentoo -- ext4 -- /boot partition) Primary MBR partition
  • /dev/sda4 Extended partition
    • /dev/sda5 Linux swap
    • /dev/sda6 NTFS
    • /dev/sda7 NTFS
    • /dev/sda8 NTFS

Code:
fdisk -l /dev/sda

Disk /dev/sda: 1000.2 GB, 1000204886016 bytes
255 heads, 63 sectors/track, 121601 cylinders, total 1953525168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk identifier: 0x000ab15f

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *         126   245366792   122683333+  a5  FreeBSD
Partition 1 does not start on physical sector boundary.
/dev/sda2       245762048   655362047   204800000   83  Linux
/dev/sda3       655362048   659458047     2048000   83  Linux
/dev/sda4       659458048  1953523711   647032832    5  Extended
/dev/sda5       659460096   667652095     4096000   82  Linux swap
/dev/sda6       667654144  1077254143   204800000    7  HPFS/NTFS/exFAT
/dev/sda7      1077256192  1486856191   204800000    7  HPFS/NTFS/exFAT
/dev/sda8      1486858240  1953523711   233332736    7  HPFS/NTFS/exFAT

In Gentoo which has the latest GRUB2, os-prober reports that Unknown Linux OS has been found on /dev/sda1 but by doing rub2-mkconfig -o /boot/grub/grub.cfg and then rebooting I go[ ] to the GRUB2 command line and not the GRUB OS list.

Long story short: how could I dualboot these two together?
 
Dear @krax,

in Debian you can achieve this by adding the FreeBSD sections in 40_custom. I assume that Gentoo is not too different in terms of grub2. Please correct me if I am wrong. You have one FreeBSD installation, therefore chain loading is the most simple approach. See the code below which has to be added to 40_custom. The comment should be the source where I have had the information from. The example starts the first FreeBSD installation.
Code:
# https://help.ubuntu.com/community/Grub2 Other Os
menuentry "FreeBSD-9.2 Chainloader" {
       set root='(hd0,1)'
       chainloader +1
}
The code above calls the FreeBSD boot loader. It is also possible to boot the kernel without the FreeBSD boot loader. This requires to add provide information to the grub2 boot loader. See the example below which allows to boot two different FreeBSD installations. In the comment lines include the links I have collected the information from. On my hard disk Linux is installed on the second slice.
Code:
#http://unix.stackexchange.com/questions/49293/how-do-you-dual-boot-debian-and-freebsd-using-grub2
#Append the following to your /etc/grub.d/40_custom replacing UUID with the UUID of the disk discovered with grub-probe -d /dev/sda2 -t fs_uuid
#Note that for other distros and/or GRUB versions, kfreebsd might have to be changed to just freebsd.
#Reference:
#http://wiki.debian.org/Debian_GNU/kFreeBSD_FAQ
#http://oliver.net.au/?p=195
#Root spec found in
#https://help.ubuntu.com/community/Grub2%20Other%20Os

menuentry 'FreeBSD #1' {
        insmod ufs2
        insmod bsd
        set root='(/dev/ad0,msdos1)'

        search --fs-uuid --no-floppy --set=root 52bc81cede7d3e4f
        kfreebsd /boot/kernel/kernel
        kfreebsd_loadenv /boot/device.hints

        set kFreeBSD.vfs.root.mountfrom=ufs:/dev/ufsid/52bc81cede7d3e4f
        set FreeBSD.vfs.root.mountfrom.options=rw
}

menuentry 'FreeBSD #3' {
        insmod ufs2
        insmod bsd
        set root='(/dev/ad0,msdos3)'

        search --fs-uuid --no-floppy --set=root 5287b2c6fc8b1fed
        kfreebsd /boot/kernel/kernel
        kfreebsd_loadenv /boot/device.hints

        set kFreeBSD.vfs.root.mountfrom=ufs:/dev/ufsid/5287b2c6fc8b1fed
        set kFreeBSD.vfs.root.mountfrom.options=rw
}

There is an issue with grub2 used from a Linux installation. grub2 needs files which are usually in /boot/grub. If the files can not be accessed grub2 fails. You can reproduce this by renaming /boot/grub to something different. I have not yet managed to run grub2 of FreeBSD so far. The priority for myself is not that high because this would also mean that the boot manager would depend on the sanity of one file system.

Since my main installation is FreeBSD I have changed to boot0 not to have to rely on the Linux installation. I can still boot Linux by a emergency installation via an USB stick.

By the way, but does anybody now if it is possible to boot Linux from the FreeBSD boot manager boot0? I really like software like boot0 because it just does what it is supposed to do without any unnecessary glamor. I think grub2 is very powerful but it provides much more that I currently need.
 
Last edited by a moderator:
Back
Top