DEV Community

Cover image for Linux on MacBook Pro 2016 / 2017
Cris πŸ‘¨πŸ»β€πŸ’»
Cris πŸ‘¨πŸ»β€πŸ’»

Posted on

Linux on MacBook Pro 2016 / 2017

Hi there! πŸ‘‹ This is my first post on dev.to. I didn't know what to write about so I just decided to talk about what I'm doing right now, installing Linux on my MacBook Pro 2016 (model 13,3 - dual gpu with touchbar). This might also help anyone trying to install Linux on any MacBook without T2 chip (2017 or older).


πŸ“– Context

It all started a few months ago when I became curious about tiling window managers and how I could increase my day to day productivity. I'm a software developer and I have A LOT of open windows and programs running at the same time, so I decided to give tiling window managers a shot. Unfortunately there are not a lot of choices available for macOS, I found yabai which is great! but as I started to tweak config files to be more comfortable working with my laptop I started to feel that it wasn't enough.

Alt Text

After a month or so of using yabai I met i3-wm, and fell in love with it. The only problem... it's only for linux. So I though, what the heck, let's install Linux on my MacBook... and so the journey began.


⚠️ Disclaimer

There are a lot of well written guides on GitHub on how to do this (I'll put the links below), so I'm just going to write down the steps I followed in my particular case and the problems I faced.

πŸ›’ What you'll need

  1. MacBook Pro 13,3 2016 (with touchbar - no T2 chip)
  2. USB stick of at least 8GB
  3. macOS. It doesn't really matter which version but it's important to keep it installed to make the touchbar and some other stuff work.

This MacBook has a few components that will make things a bit more complicated than usual, that is the Touchbar and the AMD dedicated GPU.

Some amazing people worked on drivers to make everything work the best way possible, so fear not, they got us covered πŸ’ͺ


🐧 Distro

I have an i7 CPU, 16 GB of RAM. I've tried Manjaro, Ubuntu and Linux Mint and stayed with the latter, it's much more stable in my opinion, but you can pick whatever you want as long as the kernel is 5.0.0 or greater, this is important because some stuff already work out of the box. Also, amdgpu seems not to be working on 5.6, read more here.


πŸ’Ώ Partitioning & Linux installation

1. Disable System Integrity Protection (SIP)

In order to perform some future steps required to install and boot Linux properly, we need to disable SIP (System Integrity Protection).

  • Reboot your Mac. When the startup screen shows up, press and hold the Command + R until the Apple logo appears on your screen.
  • Once it finishes loading and brings you to Recovery Mode, click β€œUtilities -> Terminal.”
  • In the Terminal window, type in csrutil disable and press Enter.
  • Restart your Mac.

2. Create a new partition

I've taken all the images from this amazing guide since it's beautifully explained and since I'm not writing this from macOS

  • Open Disk Utility from the β€œ/Applications/Utilities” folder.
  • Select your boot disk in the sidebar and click the β€œPartition” button. Alt Text
  • Click β€œPartition” in the dialog box to confirm.

Alt Text

  • Click the β€œ+” button to add a partition

Alt Text

  • Set the size and name. Choose β€œMS-DOS (FAT)” for your partition type. This will be erased by the Ubuntu installer.

Alt Text

  • Click β€œApply,” then β€œPartition” to execute.

Alt Text

3. Creating a bootable USB with Linux

  • Download the ISO file from the Linux Mint page or your distro of preference.
  • Download and Install Etcher in order to burn the ISO in our USB stick.
  • Now plug the USB stick, open Etcher and select the ISO file to burn it.

Alt Text- Click on "Flash!" button.

4. Booting from the USB stick

Now we have Linux on our USB stick, it's time to begin the installation. I didn't need to use any external keyboard / mouse but keep in mind that you might require them if for some reason the built-in set doesn't work with the live USB.

  • Restart the Mac with the USB stick inserted while the Option/alt (βŒ₯) key is pressed. This will launch Apple’s β€˜Startup Manager’ which shows bootable devices connected to the machine. Your USB stick should appear as gold/yellow and labelled β€˜EFI Boot’. Selecting this will lead you to the distro boot menu.

Alt Text

5. Running the installer

  • Connect to your wireless network (if you can) and choose to install third-party software.
  • At the installation selection screen, choose β€œSomething Else” from the bottom.
  • Select the FAT-32 partition you created earlier. Click the β€œβ€“β€ button to delete it. Alt Text
  • With the free space selected, click the β€œ+” to create a new partition.

Alt Text

  • Set the size to 4000 MB and β€œUse as” to β€œswap.” (Some people say that for hibernation to work properly, the size of your swap should be around 1.5 times the size of your RAM. Not sure if this is the case, but hibernation didn't work for me anyway).

Alt Text

  • Create another new partition with the β€œ+” button. Use all the available free space. Set β€œUse as” to β€œExt4 journaling file system.” Set the mount point to β€œ/.”

Alt Text

  • Choose the ext4 partition under β€œdevice for bootloader installation.”

Alt Text

  • Click through the remaining steps to create your user and finish the installation.

πŸ§™ Linux tweaks

Alt Text

So far you should have Linux installed on your MacBook just fine, the built-in display, keyboard and trackpad should be working out of the box. Now we're going to fix the following:

  1. πŸ“Ά Wifi
  2. πŸ•΅οΈ Spoof macOS
  3. πŸ“Ό Switch to the iGPU
  4. πŸ”Š Audio
  5. πŸ‘‰ Touchbar

Keep in mind that Wifi won't work until you reboot.

1. Wifi

This MacBook model uses a Broadcom wireless board which is not great but at least we'll get decent wifi. There's an issue with the brcmfmac module used by the kernel. Here's how to fix it.

  • Download this file
  • And then cp brcmfmac43602-pcie.txt /lib/firmware/brcm

Wifi works generally ok, but there are a few issues you should be aware of:

  • Connectivity signal is not the best.
  • After suspend/wake 5 GHz networks are not visible, and even if they are you cannot connect to them. 2.4 GHz works fine.

2. Spoof macOS

We need to make the laptop thinks she's going to boot macOS, otherwise there are some components that don't get powered, included the integrated Intel GPU. For this we'll use a custom EFI file like this:



cd /tmp
# See more at https://github.com/0xbb/apple_set_os.efi/issues/20#issuecomment-557352747
wget https://github.com/0xbb/apple_set_os.efi/files/3877561/apple_set_os.zip
unzip apple_set_os.zip

# As root...
sudo su 
mkdir -p /boot/efi/EFI/custom
mv /tmp/apple_set_os.efi /boot/efi/EFI/custom


Enter fullscreen mode Exit fullscreen mode

Now we need to edit GRUB



sudo su
nano /etc/grub.d/40_default

# Add the following lines:
search --no-floppy --set=root --label EFI
chainloader (${root})/EFI/custom/apple_set_os.efi
boot

# Update grub
update-grub


Enter fullscreen mode Exit fullscreen mode

**Note:* If you prefer using rEFInd, that's totally fine. Just remember to uncomment the "spoof_osx_version" line in refind.conf. See more at rEFInd's documentation site.*

3. Switch to the iGPU

This laptop has two GPU boards, one is the integrated Intel Graphics card and the other one is the dedicated ATI Radeon card. Since there are no drivers for this card to work properly we'll have to switch to the integrated one and then power off the dedicated GPU.



sudo su

# Blacklist amdgpu
echo "blacklist amdgpu" > /etc/modprobe.d/blacklist-amdgpu.conf

# Switch to integrated GPU
cd && git clone https://github.com/0xbb/gpu-switch
cd gpu-switch
sudo ./gpu-switch -i


Enter fullscreen mode Exit fullscreen mode
  • Reboot
  • Now we'll load amdgpu module and turn the card off properly. ```bash

sudo su
gpu-manager | grep 'amdgpu loaded? no' && sudo modprobe amdgpu || echo 'AMD GPU already loaded'
echo OFF > /sys/kernel/debug/vgaswitcheroo/switch

See more at https://github.com/Dunedan/mbp-2016-linux/issues/6#issuecomment-416015734

***Note:** Repeat last three steps every time you reboot (can be automated)*

## 4. Audio
Audio doesn't work out of the box, here's how to fix it.

```bash


sudo su
cd /tmp
sudo apt-get install wget make gcc linux-headers-generic
git clone https://github.com/leifliddy/snd_hda_macbookpro.git
cd snd_hda_macbookpro
./install.cirrus.driver.sh


Enter fullscreen mode Exit fullscreen mode

**Note:* Changes won't take effect unless you reboot the system.*

5. Touchbar



sudo apt-get install git dkms

cd /tmp
echo -e "\n# macbook12-spi-drivers\napplespi\napple_ib_tb\nspi_pxa2xx_platform\nintel_lpss_pci" >> /etc/initramfs-tools/modules

git clone https://github.com/roadrunner2/macbook12-spi-driver.git
cd macbook12-spi-driver
git checkout touchbar-driver-hid-driver
dkms add .
uname -r # check kernel version
dkms install -m applespi -v 0.1 -k 5.3.0-24-generic # replace this with your kernel version

# lsinitramfs /boot/initrd.img-5.3.0-24-generic | grep -i "dkms/apple"
lib/modules/5.3.0-24-generic/updates/dkms/apple-ibridge.ko
lib/modules/5.3.0-24-generic/updates/dkms/apple-ib-tb.ko
lib/modules/5.3.0-24-generic/updates/dkms/applespi.ko


Enter fullscreen mode Exit fullscreen mode

If you want the F-keys to be always on by default and the Fn button for switching from F-keys to special keys, then use the following command (if not, fnmode=1):



echo 'options apple_ib_tb fnmode=2' | sudo tee /etc/modprobe.d/apple_ib_tb.conf
echo 'options apple_ib_tb idle_timeout=60' | sudo tee /etc/modprobe.d/apple_ib_tb.conf
update-initramfs -u -k 5.3.0-24-generic # replace this with your kernel version


Enter fullscreen mode Exit fullscreen mode

You can also swap fn and a control keys:



echo 'options applespi fnremap=1' | tee /etc/modprobe.d/applespi.conf
update-initramfs -u -k 5.3.0-24-generic # replace this with your kernel version


Enter fullscreen mode Exit fullscreen mode

Or remap it to any other key:



# modinfo applespi | grep -w fnremap
parm: fnremap:Remap fn key ([0] = no-remap; 1 = left-ctrl, 2 = left-shift, 3 = left-alt, 4 = left-meta, 6 = right-shift, 7 = right-alt, 8 = right-meta) (uint)

Enter fullscreen mode Exit fullscreen mode




πŸŽ‰ Bonus #1 - Keyboard

Here's a guide on how to remap your keyboard.
https://medium.com/@petrstepanov/a-macos-like-keyboard-remap-on-ubuntu-linux-cae1d108a97

πŸŽ‰ Bonus #2 - Trackpad

Trackpad is not very good on Linux, here's how to improve it.
https://int3ractive.com/2018/09/make-the-best-of-MacBook-touchpad-on-Ubuntu.html


What doesn't work

  • Built-in microphone
  • Hibernation
  • Audio after suspend
  • 5 GHz wifi networks after suspend

Status

Check out https://github.com/Dunedan/mbp-2016-linux for an updated status of each component.

Alt Text

That's all Folks!

I hope you enjoyed this guide. Don't hesitate on commenting if you have any questions or you have any new findings regarding this topic.

Big thanks to all the people that made this possible. It's unbelievable the amount of people spending time on this without any retribution whatsoever πŸ™

Sources

Top comments (13)

Collapse
 
tom1827 profile image
Tom1827

Cris, I've been following your very helpful guide. Only issue is that every time the Mint install finishes followed by a reboot, the new Linux install doesn't appear as an option in the Apple boot menu.

Any ideas?

Collapse
 
cmiranda profile image
Cris πŸ‘¨πŸ»β€πŸ’»

Hi Tom! Sorry for the delay on the response. Have you been able to figure this out?. It sounds like there's something wrong with the partitions (maybe?). Are you using rEFInd?

Let me know!

Collapse
 
greenboy59 profile image
greenboy59

Thank you so much! I have installed Ubuntu 20.04 on Macbook Pro 2017 and no sound from the speakers. I have followed you guide and work perfectly now. Thank you, thank you, thank you

Collapse
 
spiderz3r0 profile image
sipder.z3r0

Hi, just wanted to say thanks and to say that of Kernel 6.8 the audio and touchbar fixes no longer work. But this is still the best tutorial I've found for getting the install set up and wifi working on a 2016-2017 macbook pro.

Collapse
 
joshandersn profile image
Josh Anderson

Hey I got stuck in the spoof MacOS section. My laptop is stuck booting forever with the apple logo.

Collapse
 
joshandersn profile image
Josh Anderson • Edited

I have access to grub or uefi menu? when I plug in my Linux USB drive and select it on startup

Collapse
 
sklyar profile image
Alexey Sklyar

I have the same problem.

Collapse
 
vicjones profile image
Victor Jones

Hey Cris, thanks for this guide! Question, do you have problems waking up your macbook pro 13,3 even after switching to intel on graphics I cannot get mind to wake up after suspend? I'm on 20.04

Collapse
 
cmiranda profile image
Cris πŸ‘¨πŸ»β€πŸ’»

Hey! I disabled suspend because I never got it working properly :(

Some comments may only be visible to logged-in visitors. Sign in to view all comments.