Dual Booting With FreeBSD 9

From SlackWiki
Revision as of 11:08, 25 October 2011 by Dive (talk | contribs) (→‎Custom Rule)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search


FreeBSD 9+ differs from older releases by using GPT (GUID Partition Table). This means that lilo and grub version 1 will no longer work. Grub version 2 however does work.

There are two way of doings this - either install grub2 in Slackware, or install it in FreeBSD. Grub2 in Slackware does not seem to be able to pick up the FreeBSD partition and Grub2 in FreeBSD doesn't seem to pick up the Linux partitions. You will need to manually add these to /usr/local/etc/grub.d/40_custom.

To pick up all your Slackware kernels it's probably best to install grub2 in Slackware and add the FreeBSD partition manually. I've shown both methods here though, for completeness.

For this howto we'll assume that Slackware / is on /dev/sda2 (with no separate /boot partition), and that FreeBSD is on /dev/sdb2 (/dev/ada1p2 in FreeBSD-speak). These correspond to (hd0,2) and (hd1,2) in Grub2.

To install Grub2 in Slackware

To install Grub2 in Slackware, you can use the slackbuild script here: http://slackbuilds.org/repository/13.37/system/grub2/ and its dependencies. Once installed, issue:

   # grub-install --modules=part_gpt /dev/sda

Edit /etc/grub.d/40_custom to add your FreeBSD partition (see mine below for an example). Once done:

   # grub-mkconfig -o /boot/grub/grub.cfg

grub-mkconfig will pickup all your Linux partitions and all kernels (hopefully).

To install in FreeBSD

To install Grub2 in FreeBSD, you need to use ports.

I won't give an extended howto on using ports but these are the steps:

Fire up your FreeBSD system and navigate your way to /usr/ports/sysutils/grub2 as root

   # make install && rm -rf work
   # grub-install --modules=part_gpt /dev/ad0

Edit /usr/local/etc/grub.d/40_custom to add your Slackware partition (see mine below for an example). Once done:

   # grub-mkconfig -o /boot/grub/grub.cfg

grub-mkconfig will pick up FreeBSD automatically. /usr/local/etc/grub.d/40_custom will contain the extra OS's and FreeBSD boot loader if req'd.

Custom Rule

This is my 40_custom:

     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 'Slackware' --class slackware --class gnu-linux --class os {
         insmod gzio
         insmod part_msdos
         insmod ext2
         set root='(hd0,2)'
         linux   /boot/vmlinuz root=/dev/sdb2 ro
     menuentry "FreeBSD" --class freebsd --class bsd --class os {
         insmod ufs2
         set root='(hd1,2)'
         kfreebsd                /boot/loader

(You choose which section you want to add - FreeBSD or Slackware - depending on where you installed Grub2.)

That's pretty much it.


The Slackware partition uses ext4 and the huge kernel with no initrd. For, say, xfs you should use 'insmod xfs'. For an initrd you need to look up the appropriate docs.

Caveat: This was tested on FreeBSD 9.0Beta3. I can't see that it wouldn't work when release is out but you never know.