Skip to content

Instantly share code, notes, and snippets.

Created January 23, 2015 17:12
Show Gist options
  • Save mpasternacki/974e29d1e3865e940c53 to your computer and use it in GitHub Desktop.
Save mpasternacki/974e29d1e3865e940c53 to your computer and use it in GitHub Desktop.
FreeBSD on a MacBook Pro

FreeBSD on a MacBook Pro

Since 2008 or 2009 I work on Apple hardware and OS: back then I grew tired of Linux desktop (which is going to be MASSIVE NEXT YEAR, at least since 2001), and switched to something that Just Works. Six years later, it less and less Just Works, started turning into spyware and nagware, and doesn't need much less maintenance than Linux desktop — at least for my work, which is system administration and software development, probably it is better for the mythical End User person. Work needed to get software I need running is not less obscure than work I'd need to do on Linux or othe Unix-like system. I am finding myself turning away from GUI programs that I used to appreciate, and most of the time I use OSX to just run a terminal, Firefox, and Emacs. GUI that used to be nice and unintrusive, got annoying. Either I came full circle in the last 15 years of my computer usage, or the OSX experience degraded in last 5 years. Again, this is from a sysadmin/developer kind of power user perspective; power user, whose definition of "fun" includes spending 6 hours in the middle of the night figuring how to get dual boot working with UEFI.

Next reason is that I am working a lot on FreeBSD software, Jetpack being the most visible. I want to try out custom kernel options (VIMAGE and RACCT), and using a custom kernel seems tricky in a VMWare/VirtualBox VM. Skipping VM overhead would be nice too. And the final push was when I saw the Terminology demo, ran it on an old laptop that's already got FreeBSD installed, and found it working as advertised. XXIst CENTURY IS HERE, GRAPHICAL TERMINALS REALIZED THEY CAN DISPLAY PICTURES. I want this, and I want this integrated with Mutt, Irssi, Ekg2, Elinks…

I'm not switching (yet), it is an ongoing experiment to see how much I can get running. It is a challenge to take hardware developed for OSX in particular, without much thought given to other operating systems, and designed NOT to make interoperability easy — and to get an open OS running. To see how much of a tradeoff will it be. I want to try running an open operating system where I can safely expect that software won't insist on phoning home, syncing my data with a cloud, and won't nag me to enable features that require that if I choose to skip it. There's also a practical side: this is hardware that I have. I don't plan to get a new workstation soon.

I will surely miss some things. After first start of Xorg I already cringe at font rendering (maybe it's configurable somewhere, though). LibreOffice should be a good replacement for most of MS Office/iWork by now, but probably it doesn't match Keynote. Not sure about document viewers nowadays: Apple's Preview is nice and invisible. 1Password. OmniGraffle. F.Lux. Time Machine. Integrated address book. iBooks. Dash (the handy documentation browser). Papers. A couple of games. I'll probably have a hard time figuring out how to use some closed software I need for work or fan: Flash player, Skype, Google Hangouts… Still, this list doesn't seem that big after all — and as long as I have Apple hardware, I'll keep the dual boot. Won't hurt to try, worst case is I will learn something new and go back to OSX.


I've been asked on what hardware exactly do I do all of that. It is a MacBook Pro 13-inch, Late 2011 (MacBookPro8,1), 8GB RAM, optical drive exchanged to a second hard drive, attached to an Apple Thunderbolt Display (another reason not to get a new hardware), and with wireless Bluetooth Apple keyboard and touchpad. I hope to get all of that working at least on a basic level.

I have been installing FreeBSD 11-CURRENT snapshot 20150111 (there is a newer one already, but I've got mine already installed, and even managed to update it with a buildworld/installworld).

Act I. Preparing for Dual Boot

First, we need some disk space. This was already trickier than expected (not only because I had to delete some stuff to make space, but that was also time-consuming). The plan was to use ~80GB of my 250GB main hard disk for FreeBSD, and leave rest to OSX. After deleting and moving enough junk, I bumped into the first obstacle: resizing the system volume. OSX isn't smart enough to resize a running partition. Not something entirely unexpected, but it's also not smart enough to provide a meaningful error message. It just pushes a progress bar for an hour or two to fail with "couldn't unmount disk" message. Same thing when booted to a rescue mode (which is loaded from a hidden partition on the same disk, which is located right after main OSX system partition – so if Macintosh HD shrinks, recovery partition is relocated). Luckily, somebody already figured that one out. I made an installer SD card from the installer I still had on my disk since OSX upgrade (which is described at, started Disk Utility from the installer, and was able to successfully shrink the partition.

Now, we need a boot manager. It seems rEFInd is the way to go. I first booted it from an SD card to see if it starts, then installed it to disk. Finding out how to get to the configuration (which will be needed later) was not obvious, though: you need to start the Disk Utility, select EFI partition from your system disk, Mount it, and the boot manager is mounted at /Volumes/EFI/.

Act II. Installation

I have downloaded the FreeBSD-11.0-CURRENT-amd64-20150111-r276981-memstick installer image (when you read it, there will probably already be a more recent one), dd-ed it to an SD card, and booted from rEFInd. Booting card's MBR ("legacy" boot) didn't work, but when I rescanned by pressing Esc in the boot menu and selected "Rescue partition" of the card (which apparently meant card's EFI partition), installer managed to boot.

The installer itself boots fine. Important Thing: because boot1.efi loader (we'll get to it in a moment) can't read ZFS yet, /boot needs to be on an UFS partition. From what I found, it seems that work on ZFS-enabled boot1.efi is underway, and it should get into 11.0-RELEASE. I tried to achieve that the old Linux way (have /boot on a separate partition, mounted below ZFS root), but couldn't get it to work: kernel booted, but wasn't able to mount root directory. In the end, I used the following scheme:

  • ~7GB UFS partition at the end of the disk, for system root (big enough to hold the base system and couple kernels, plus some margin)
  • Large ZFS partition before the root dir, mounted at /tank — I wanted ZFS partition to be located before the UFS root to be able to shrink OSX partition and move/grow ZFS later on
  • A bunch of symlinks

I didn't let the installer touch the ZFS partition or create any "boot partitions" it tried to add.

At the end of installation, I selected the "open shell in the new system" button (don't remember the exact label now), created zpool, mounted it at /tank, created usr/ and var/ filesystems as described in the wiki (plus usr/doc), copied whole existing /home, /var and subdirectories of /usr there, and replaced the main filesystem's /home, /var, and /usr/{doc,ports,src,obj,local} with symlinks to tank/ filesystems. This way, the system partition won't grow much, and I get most of the ZFS benefits while being able to boot the system from EFI. I've also added zfs_enable="YES" to new system's /etc/rc.conf, and after booting into the new system had to manually zfs import the zpool. After that, everything has worked just fine.

Before finishing the installation, copy the installer's (or the new system's) /boot/boot1.efi file someplace safe, you're going to need it.

After finishing the installation, you won't see BSD in rEFInd's boot menu. No problem: boot into OSX, mount /Volumes/EFI from the Disk Utility, create a /Volumes/EFI/EFI/freebsd directory, and put the boot1.efi file in there. This should do the trick: if you unmount the EFI volume and reboot, you should see FreeBSD in the boot menu, and it should boot fine. You'll probably need to run zfs import tank on first boot, but besides that, everything should work fine.

The base system is up. Installing packages with pkg works. X Windows kind of work, but it's still quite far from a comfortable and optimal setup; this is what I'm working on right now. And I also need to have a disk volume for data I want to share between OSX and FreeBSD. Trying to decide between exFAT and ZFS (with OpenZFS On OSX on the Mac side). Will post once I find out which one works fine.

To Be Continued…

Copy link

@dch Sound worked OOTB for me (snd_hda driver, seems to be built into kernel by default, no module is loaded). Try dmesg|grep hda to see if it tries to configure anything (also cat /dev/sndstat to see if any cards are detected). I've got no custom entries in loader.conf or device.hints related to sound (tried some hints to get the headphone plug switch output automatically, but gave up, two separate outputs are good enough for me).

Copy link

albocc commented Feb 8, 2017

@mpasternacki I am working on a similar project, only that I am working with a MacBook Air. I tried the snd_hda driver too and without any changes, sound seems to work over the headphone jack. However, the speakers aren't working for me. Did you change some kind of setting to make those work? PS: What kind of panel tool are you using to control the volume? 😄

Copy link

Any updates for MacBook Pro 2016 w/ Touchbar?

Copy link

0xf10e commented Feb 8, 2018

@albocc how did it work out for you?
I'll try (probably not too hard though) to combine this with @jcs' Mac OS X FileVault encryption and OpenBSD encrypted softraid on a Macbook Air/Pro to get a tripleboot on a MacBookAir5,2 ; )

Copy link

qq-me commented Jul 22, 2023

congratulations for you have managed to become the owner of the most starred gist that contains the word "cringe"!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment