Skip to content

Instantly share code, notes, and snippets.

@mpasternacki
Created January 23, 2015 17:12
Star You must be signed in to star a gist
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.

Materials

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 http://www.amsys.co.uk/2013/blog/creating-mavericks-bootable-install-disk/), 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…

@cavebatsofware
Copy link

I'm going to watch this out of curiosity, I have an interest in getting a workable system running under FBSD but know that certain things like Skype just don't work well or at all on FBSD. What I mean by a workable system is something usable for daily software development (web dev mostly) work that once setup won't require a great deal of maintenance to keep current and functional. Possibly it would be worth the added security to run Skype and some other closed software on a windows vm (snapshotted for freshness even) that is not allowed access to the host. I like the idea of being able to control every line of code that runs through my CPU on the main host at least. Even if I am not going to really inspect the kernel line by line along with everything else, that would obviously be impractical, I think its fair to say there is a great deal more transparency in a FBSD or other open system.

I do some game dev too though so I would need to keep mac os for some things of course.

@thunfischbrot
Copy link

Did you end up using FreeBSD as a desktop environment?
Every two years I try again to get FreeBSD up and running on a Macbook Air. The last three times I made progress each time, never reached a productive state in which I could start considering it as a replacement though.

@benmezger
Copy link

Any progress fully installing FreeBSD on a Macbook Pro? Did you end up having any trouble?

@markdean
Copy link

markdean commented Apr 2, 2016

It's funny, I run Linux (Fedora...since I support RHEL/CentOS servers in my day job) on my 13" Macbook Pro...and it "just works"-at least everything I use from a hardware/OS interaction. In fact, since my switch to Linux as my main desktop in 2002, it "just works". Of course I use mainstream hardware and I even purchased RHEL pre-loaded on my Dells in 2004 and 2006 (and it works just as fine on my HPs). Anyways, the "Linux on the desktop" thing was/is more about mainstream adoption and less about whether you can use Linux as a desktop computer to do stuff.

@cmanns
Copy link

cmanns commented Apr 15, 2016

FreeBSD and PC-BSD work on Apple's

@anicholson
Copy link

@mpasternacki can we get an update? How was the experience? Do you still use it? :)

@dch
Copy link

dch commented Sep 5, 2016

FWIW I switched my 2014 15" retina pro over to pure FreeBSD 10.0 and haven't looked back since. There are no comment notification facilities on gists, so I suggest you join the forums and discuss over there https://forums.freebsd.org/threads/51788 for example.

@kfatehi
Copy link

kfatehi commented Nov 24, 2016

As for Dash, check out Zeal: https://zealdocs.org/

@vinitkumar
Copy link

Screenshots?

@yarwelp
Copy link

yarwelp commented Nov 24, 2016

The link to terminology is not leading to the correct place. Probably it has changed since when the document was authored.

Here is a current link: https://www.enlightenment.org/about-terminology

@dmarcoux
Copy link

For an alternative to f.lux on Linux, check out Redshift

@dch
Copy link

dch commented Nov 24, 2016

@vinitkumar https://twitter.com/dch__/status/801335002000670720 FreeBSD 11.0R with i3wm using scfb driver. I also dualboot (yay zfs boot environments) with TrueOS. Very stable. See https://github.com/FreeBSDDesktop/freebsd-base-graphics for bleeding edge intel 4.7 & higher GPU drivers. these are very stable now but I get better power / battery life out of scfb.

@pirogoeth
Copy link

For an alternative to f.lux on Linux, check out Redshift

Or alternatively, there is Blueshift which is extremely configurable and just amazing.

@mpasternacki
Copy link
Author

Update: I still use it, as my primary system now. I run 12-CURRENT with drm-next-4.7 patches for new i915 DRM (HEAD kernel gets confused by the thunderbolt display; builtin or DVI external display work fine with vanilla, though). X11 works, Linux emulation layer runs mostly fine (notable "won't run yet": steam, chrome; notable "runs fine": factorio). Redshift and Zeal are cool, thanks for the tips. No drivers for builtin wi-fi, I'm mostly Ethernet-bound (it's a mostly stationary laptop anyway, just moved between home and office every now and then), and I use USB dongle when I really need wifi on this machine. I use Skype/Hangouts on phone or tablet, and need to boot into OSX only to access some old data or use some weird proprietary equipment (car GPS map update, I'm looking at you!). Don't use Terminology after all, though, it is (was when I tried it) too slow and unstable; plain old urxvt is perfect.

Also, builtin laptop speakers sound awful (way more awful than on OSX), but for proper speakers I use external USB card anyway, and headphone output works well. I couldn't get automatic switch between speakers and headfones to work, though – I see two separate OSS sound cards, one for builtin speakers, and one for headphones (and a third one for SPDIF, but I don't have any equipment to check it). Works for me, though, I'm either on external sound card with proper speakers or on headphones anyway.

I have to say I'm much happier with my setup now than in last weeks of using OSX. Wouldn't recommend to anybody who doesn't enjoy some problem solving every now and then, but when all's configured, it works surprisingly well.

@dch
Copy link

dch commented Nov 25, 2016

@mpasternacki I didn't get sound sorted, can you share any tips?

@mpasternacki
Copy link
Author

@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).

@albocc
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? 😄

@Borderliner
Copy link

Any updates for MacBook Pro 2016 w/ Touchbar?

@0xf10e
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 ; )

@stunlocked1
Copy link

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