perri.to: A mashup of things

Debianizing my (intel) Macbook Pro 13" 2017

  2023-11-09


Debianizing my (intel) MacBook PRo 13 (MacBookPro 14,2)

Macbook Pro with the keyboard I actually use it with

Why?

I have been wanting to have a linux laptop for some time. Since I work daily on macOS, my only linux computer is a desktop.

I try not to spend more time than my work time on my desk to have work/life separation.

Turns out we had an old Macbook Pro, a 2016 model with a i5 Processor and 8G of ram.

This machine was terrible on macOS, it was barely usable.

Given nobody will buy it, I decided to experiment putting some linux on it.

I chose debian as the OS because my favorite Linux used to be Ubuntu but I can’t stand snaps.

How?

Important tips

  • Do not use relatively modern mac, they are not without problems and definitely sub-optimal hardwar for anything but macOS.
  • If you have a touchbar, prepare to compile kernel modules.
  • You will need some knowledge of systemd and unix daemons.
  • Do not erase your macOS, resize the partition to 50G (a fresh install helps here) so you can update firmware (and you need the EFI partition to hold the touchbar OS, yes it runs a full OS)
  • This works “ok” for me with kernel 6.1.0.x (debian 12 as of the time of writing) but not with 6.5.x.x (debian trixie while on testing). I patched the touchbar module to work with the new kernel but there seems to be something else incompatible. I am unsure at this point if it is worth it to try and forward port this to a newer kernel since this hardware is no longer produced.

Installing

  • Resize your macOS (potentially APFS) partition, for this you will need to use the terminal on the Recovery screen (hold Cmd+R when booting) and use diskutil command, it is easy once you read the docs and understand your partition layout.
  • Install your Debian (use a modern one, drivers) on the available empty space.

Making it work

I did not test this script but I wrote it from my bash history, none of this is my original production it is mostly googling and discerning what is outdated.

#!/bin/bash

## This assumes debian ~12, worked for me in a Macbook 2017 with touch bar I. 
## According to apple it is [this](https://support.apple.com/kb/SP755?viewlocale=en_US&locale=en_US) machine, the docs about installing a linux on it use the **MacBookPro14,2** nomenclature.
#
# This requires root for most things (or sudo but who has time for that)
# Some of the sources for this are:
#
## * The repos themselves from which this script clones
## * https://github.com/Dunedan/mbp-2016-linux
## * https://github.com/roadrunner2/macbook12-spi-driver # previous fork of tb driver
## * https://easylinuxtipsproject.blogspot.com/p/root-command-startup.html

## dependencies
apt install build-essential curl wget git dkms

## soundcard
git clone https://github.com/davidjo/snd_hda_macbookpro.git /usr/src/snd_hda_macbookpro
pushd /usr/src/snd_hda_macbookpro
./install.cirrus.driver.sh
popd

## touchbar, this is not the og repo but the one arch linux uses for pacman so its up to date.
git clone https://github.com/marc-git/macbook12-spi-driver.git /usr/src/applespi-0.1
dkms install -m applespi -v 0.1
# yes, i know, this is insecure, i actually downloaded the thing and read it myself
# but this is for the sake of brevity, you are running this script anyway.
curl https://wiki.t2linux.org/tools/touchbar.sh | sh

## And now, lets configure the correction for the bazillion issues mac has
#
## This magical incantation is required by the broadcom nic to work
## why? nobody knows for certain, it just works.
## I tried setting it to other tx powers, this seems to be ideal.

cat << EOF | tee /opt/captain.sh > /dev/null
#!/bin/bash
# This disables d3cold on nvme, otherwise your machine will never return from suspension
echo 0 > /sys/bus/pci/devices/0000\:01\:00.0/d3cold_allowed
# This does the wifi resurrection thing
sleep 20
iwconfig wlp2s0 txpower 5
exit 0
EOF

## Notice that you need to run this after all sorts of sleep or wifi and bt do not work
## I have no clue how bluetooth is also affected likely all in the same chip and needs a kick
cat << EOF | tee /etc/systemd/system/captain.service > /dev/null
[Unit]
Description=Captain service
After=network.target suspend.target hibernate.target hybrid-sleep.target suspend-then-hibernate.target

[Service]
ExecStart=/home/hduran/fixes/captain.sh

[Install]
WantedBy=multi-user.target
EOF

systemctl captain start
systemctl enable captain.service

## This is required to kickstart the touchbar, which is useful if you want
# Esc and F# keys :p or any form of multimedia controls.
cat << EOF | tee /etc/systemd/system/macbook-quirks.service
[Unit]
Description=Re-enable MacBook 14,3 TouchBar
Before=display-manager.service
After=usbmuxd.service

[Service]
Type=oneshot
ExecStart=/bin/sh -c "echo '1-3' > /sys/bus/usb/drivers/usb/unbind"
ExecStart=/bin/sh -c "echo '1-3' > /sys/bus/usb/drivers/usb/bind"
RemainAfterExit=yes
TimeoutSec=0

[Install]
WantedBy=multi-user.target
EOF

systemctl macbook-quirks start
systemctl enable macbook-quirks start
comments powered by Disqus