Dual Booting OS X and FreeBSD 9

Many (outdated) blogs outline different ways in which one can dual-boot
Mac OS X and FreeBSD using many different hackish methods. All of the blogs I’ve seen
that illustrate how to accomplish this are for very old Apple hardware, or very old
versions of FreeBSD. With the upcoming release of FreeBSD 9.0, here is my attempt to
document the necessary steps to dual-boot OS X and FreeBSD 9.0.

As FreeBSD 9.0 is not yet released, I used the 9.0-RC1 snapshot, which I don’t
expect the necessary steps to change much, but if they do, I will be sure to
update this accordingly.

Before beginning, I’ve resized my Mac OS X partition using Disk Utility, to
allocate available free space to contain my FreeBSD installation. Rather than
using the BootCamp utility, I opted to using rEFIt. I don’t expect the core
components of this procedure to differ much, but if they do, I’ll be happy to
document the differences accordingly. Please send an email to
www@ at my domain with what you’ve found, and I’ll
gladly document the differences, and credit those who report them accordingly.

The majority of the installation is as simple as following the FreeBSD Handbook
installation instructions for FreeBSD 9.0. There are really only two key
areas in which caution needs to be taken:

  • Partitioning
  • Post-installation steps

During the partitioning stage, as outlined in the Allocating
Disk Space
section of the FreeBSD Handbook, you should choose the “Manual”
partitioning option, as you will need to remove the “Linux Data” partition Mac
OS X has created. In my case, the relevant partition is ada0p3.
Press D to delete the partition, then press ENTER to
create a new partition. You may opt to install FreeBSD all within one large
“/” partition if you like — I disagree with doing so for various
administrative reasons, though that is not relevant to this post. After
allocating space for a “/” (top-level root) directory, you will be prompted to
create a boot partition ‐ select YES, and a 64k partition
will be created.

Allocate the remaining space as necessary.

Continue through the remaining installation steps as outlined in the FreeBSD
Handbook until you reach the point where bsdinstall prompts to
reboot into the new system. Do not reboot yet. There is one
more change to make.

As Mac OS X uses the GPT partitioning scheme, the boot partition
created when creating the “/” partition will need to be modified, as the
default is to use the MBR scheme.

When you are prompted to reboot the system, you are given two options —
Reboot and Live CD. Select Live CD.

You will be dropped into a shell from within you will have access to the
pre-mounted filesystem of your new installation. You will need to write
GPT bootcode to the new installation in order for rEFIt (and
presumably BootCamp) to recognize the partition as bootable.

From within the Live CD shell, double-check the GPT partition
that is labeled as "freebsd-boot" — this can be accomplished
by typing:

# gpart list | less

Assuming the freebsd-boot partition is ada0p3, as is on my
MacBook at the time of writing this, the "p3" part is the important
part — that is where the GPT bootcode needs to be written.

To write the bootcode to this partition, type:

# gpart bootcode -b /boot/pmbr -p /boot/gptboot -i 3 ada0

You should see a message:

Bootcode written to ada0

after which, you should be able to reboot the system, and boot into your new
FreeBSD 9.0 installation on your Mac.