Installing FreeBSD 8.2 on a MacBookPro7,1

Motivation

Motivation: you want to install FreeBSD 8.2 on a "recent" (2010/2011) MacBook and the official installer doesn't work because the kernel doesn't detect the CD/DVD drive or the actual disk.

Avoid: if you have any later release, including 9.X after March 2011, this page probably isn't for you, and could be dangerous.

Warning

What we would like to do is install FreeBSD and be done. The FreeBSD installer should modify its partition table entry in ways which suit it and leave everything else alone. Unfortunately, it ALSO "helpfully" changes details of Apple's EFI and HFS+ partitions, which makes Steve Jobs very angry, and OS X won't boot. So we need to partition the disk using Apple's tool, record critical information about the partition table, run the FreeBSD installer, and then carefully undo the damage it does.

This process is dangerous. Read it carefully before you start, and before that go and acquire at least a few weeks' worth of experience installing FreeBSD in less-challenging situations.

Ingredients

Partitioning

Run Boot Camp Assistant to partition your disk. I chose: "Divide Equally", then hit "Partition"

CAREFULLY WRITE DOWN HOW YOUR DISK IS PARTITIONED, both GPT and MBR. If you don't write down this information, you will end up unable to boot OS X. Really!

One way to do this: while the Boot Camp Assistant window is still showing you the "Start Installation" button, open up a Terminal window. Run these commands and write down/print out the output:

sudo gpt -r show disk0
sudo fdisk /dev/disk0

Stick in the FreeBSD CD/DVD and also the "memstick" USB flash drive. When OS X tells you it doesn't grok the flash drive, tell it "Ignore".

Now you can hit "Start Installation".

Booting the installer

When the BTX loader starts spinning its cursor on a line near the middle of the screen, hit '6' once. Wait for 30 seconds or so while we load an unusable kernel off of the CD, then you should get an "OK" prompt.

Running the installer

Pick a country.

Before you forget, go down to "Options", hit return, go down to "Media Type", hit the spacebar, go down to "USB", hit return. It should find your USB device. Ok!

Hit "Q" to get out of the Options Editor.

Go up and start a Standard installation. It will give you a message about fdisk and then show you some disks, in my case ad4 and da1. Select ad4 and hit the spacebar.

Agree to use the current (non-legacy) geometry.

On the "FDISK Partition Editor" screen, move the blue bar down to ad4p3, hit "T", and enter 165. You should now see that the "ad4p3" line says "Desc: freebsd" and "Subtype: 165". Hit "Q" to finish.

On the "Install Boot Manager?" screen, choose "None".

You will get a "Disk slicing warning" about chunks not starting on a track boundary. Ok!

Now you'll be back to "Select Drive(s)". There will be an "X" next to "ad4". Hit the tab key, which should move the cursor to "OK", then hit return.

You will get a message about BSD partitions. Ok!

With the blue bar highlighting the "Disk: ad4" line at the top of the screen, hit "A" for "Auto Defaults". Adjust as necessary (I made /tmp 2G instead of 1G by deleting /usr and /tmp and adding them back). Again, "Q" to finish.

Choose which "distribution set" to install (I picked "Developer", English documentation, and agreed to the "ports" collection). Then hit Tab for Ok.

You will get a "Last Chance!" window. I guess this is your last chance.

During the post-configuration, tell it that the CMOS clock is set to UTC.

Now hit Alt-F4 for the "Emergency Holographic Shell".

First, you need my kernel.

# cd /boot
# mv kernel kernel.GENERIC
# cp -pir /dist/boot/kernel .

Second, we need to fix up the MBR. If you "fdisk -p ad4" you will see that FreeBSD has "helpfully" adjusted the start, size, and type of the EFI partition and also the type of the HFS+ partition (these are not friendly actions to have taken).

Before we begin: for some reason we need to tell the kernel it's ok to edit the MBR partition table.
sysctl kern.geom.debugflags=16

Now, you will need to "fdisk -u ad4" and laboriously put everything back (including, I suggest, the CHS values, which you get to by answering "y" to the "Explicitly specify beg/end address?" question). When it asks you about automatically correcting something, don't. You may find this "decoder ring" handy: 0xEE == 238, 0xAF=175. Note that you do NOT want to set the "type" of the FreeBSD partition back to 0B--leave it at 0xA5/165.

When you write the partition table, it will probably say "fdisk: Class not found". THAT IS OK. If it also says "fdisk: Failed to write sector zero" then I sure hope you forgot the sysctl command above--otherwise I have no idea what bad situation you are in.

Alt-F1 back to the installer, hit Tab to get to "Exit Install".

When the screen goes black before the "bong", hold down the Option key. When you get the slick icon-based boot menu, you can press the eject button at the top right of the keyboard to spit out the FreeBSD CD/DVD. Hopefully if you choose "Windows" you will completely automatically boot into FreeBSD.

Undo?

If Boot Camp Assistant won't let you delete the FreeBSD partition, boot FreeBSD and use gpart to delete the FreeBSD entry from the GPT. Then go back to OS X and use Disk Utility to expand the HFS+ partition to cover the entire disk, and you're back to your starting conditions.


Open issues (2011-03-11)

  1. On my machine, the bge0 wired Ethernet driver doesn't really work: transmit interrupts aren't delivered. The next thing to try is finding a loader.conf incantation to tell that driver not to use MSI's, but I haven't tracked that down yet (I have a USB wired Ethernet interface that works fine).
  2. You don't want to hit "caps lock", because it takes the keyboard driver several seconds (!!) to turn the LED on or off.
  3. Once in a while it crashes instead of booting (an infinite stream of fault messages scrolls by on the console).
  4. Amusingly enough, sometimes when you try to halt the system, after everything is quiet some ACPI event kicks off a round of USB device enumeration and everything gets weird.
  5. ACPI suspend doesn't work. Well, it's actually resume that doesn't work, but you know what I mean. I'll try disabling the second core to see if that helps.

Good luck!


[Back]