Skip to content

Instantly share code, notes, and snippets.

@david-batranu
Forked from TRPB/arch-macbook2018.md
Created August 24, 2020 12:24
Show Gist options
  • Save david-batranu/a89476c3ad81835bf98b47592d8e00db to your computer and use it in GitHub Desktop.
Save david-batranu/a89476c3ad81835bf98b47592d8e00db to your computer and use it in GitHub Desktop.
Guide: Running Arch on a 2018 MacBook Pro

Hardware Prerequisites

You'll need at least the following hardware:

  • At least 3 USB-A to USB-C converters or hub with enough ports for at least 3 USB devices if all your devices are USB-A then:
  • A USB drive
  • A USB keyboard
  • USB to Ethernet adapter, compatible USB dongle or USB tethering on a phone

General notes:

  • I strongly recommend against deleting OSX entirely even if you'll never use it, it is required for locating the WiFi firmware during install and can be valuable for determining which hardware you have.

Build archiso with a custom kernel

You'll need an existing arch install to do this

  1. Firstly grab a copy of the archiso script as instructed here:

https://wiki.archlinux.org/index.php/Archiso

cp -r /usr/share/archiso/configs/releng/ archlive
cd archlive
  1. Add aunali1's repo to pacman.conf:
[mbp]
Server = https://packages.aunali1.com/archlinux/$repo/$arch
  1. Ignore the original kernel in pacman.conf
# Pacman won't upgrade packages listed in IgnorePkg and members of IgnoreGroup
IgnorePkg   = linux linux-headers
  1. Add the linux-mbp pakages to the end of packagesx86_64
...
wvdial
xl2tpd
linux-mbp
linux-mbp-headers
  1. Force the build script to use interactive mode for pacstrap:

sudo nano /usr/bin/mkarchiso

In this file press Ctrl+W type pacstrap and replace every pacstrap -C with pacstrap -i -C:

# Install desired packages to airootfs
_pacman ()
{
    _msg_info "Installing packages to '${work_dir}/airootfs/'..."

    if [[ "${quiet}" = "y" ]]; then
        pacstrap -i -C "${pacman_conf}" -c -G -M "${work_dir}/airootfs" $* &> /dev/null
    else
        pacstrap -i -C "${pacman_conf}" -c -G -M "${work_dir}/airootfs" $*
    fi

    _msg_info "Packages installed successfully!"
}

Note: There is definitely a better way to accomplish this

  1. Build the iso:
sudo ./build.sh -v

Press Y to everything including skipping ignored packages (so the only kernel installed is linux-mbp) then write to your usb (where /dev/sdb is your usb) drive:

sudo dd if=out/archlinux*.iso of=/dev/sdb bs=1M
  1. Boot your mac in recovery mode enable booting from USB: https://www.ninjastik.com/support/2018-macbook-pro-boot-from-usb/

  2. Hold option while booting up and select your USB. (For some reason it didn't show at first for me and I had to unplug and re-plug the drive once the menu was on the screen)

Installation

You'll need to use a USB keyboard for the installation

  1. Follow the Arch Install as normal: https://wiki.archlinux.org/index.php/Installation_guide You can resize the OSX partition, I'd already installed Windows in bootcamp which did this for me so I just wiped off windows and installed Linux on the partitions it created.

  2. Mount the existing apple EFI partition (/dev/nvme0n1p1) to /boot (if you haven't run arch-chroot yet it will be mount /dev/nvme0n1p1 /mnt/boot)

  3. After you've used arch-chroot to see the file system as you would post install, add aunali1's repo to /etc/pacman.conf:

[mbp]
Server = https://packages.aunali1.com/archlinux/$repo/$arch
  1. Then install the kernel:
sudo pacman -S linux-mbp linux-mbp-headers
sudo mkinitcpio -p linux-mbp
  1. Use GRUB, (Systemd-boot crashed for me and forced me to hard reboot)

Install your DE and anything you want to use.

Keyboard/touchpad

  1. install yay:
sudo pacman -S git gcc make fakeroot binutils
git clone https://aur.archlinux.org/yay.git
cd yay
makepkg -si
  1. Install macbook12-spi-driver-dkms:
yay --editor=nano --editmenu -S macbook12-spi-driver-dkms

When it says PKGBUILDs to edit? type A to open nano (or substitute your favourite editor in the command above).

In the source( line change the branch to mbp15, replace https://github.com/roadrunner2/macbook12-spi-driver.git#branch=touchbar-driver-hid-driver with https://github.com/roadrunner2/macbook12-spi-driver.git#branch=mbp15

  1. Get MCMrArm's bridge driver and install it to extramodules:
git clone https://github.com/MCMrARM/mbp2018-bridge-drv.git
cd mbp2018-bridge-drv
make
cp bce.ko /usr/lib/modules/extramodules-mbp/bce.ko

you'll need to remember to rebuild the module every time you update the kernel), I'm looking for a way to automate this

  1. Have it load on boot:
sudo nano /etc/modules-load.d/bce.conf

Add the following:

bce
  1. Reboot, you can now disconnect your external keyboard and use the laptop's touchpad.

WiFi

Boot into OSX and run the following in terminal: ioreg -l | grep C-4364

It will show something like:

"RequestedFiles" = ({"Firmware"="C-4364__s-B2/kauai.trx","TxCap"="C-4364__s-B2/kauai-X3.txcb","Regulatory"="C-4364__s-B2/kauai-X3.clmb","NVRAM"="C-4364__s-B2/P-kauai-X3_M-HRPN_V-u__m-7.5.txt"})

    | |   |         |       "images" = {"C-4364__s-B2/kauai-X3.txcb"={"imagetype"="TxCap","required"=No,"imagename"="C-4364__s-B2/kauai-X3.txcb"},"C-4364__s-B2/P-kauai-X3_M-HRPN_V-u__m-7.5.txt"={"imagetype"="NVRAM","required"=Yes,"imagename"="C-4364__s-B2/P-kauai-X3_M-HRPN_V-u__m-7.5.txt"},"C-4364__s-B2/kauai-X3.clmb"={"imagetype"="Regulatory","required"=Yes,"imagename"="C-4364__s-B2/kauai-X3.clmb"},"C-4364__s-B2/kauai.trx"={"imagetype"="Firmware","required"=Yes,"imagename"="C-4364__s-B2/kauai.trx"}}


It'll be different depending on your exact model.

There are three files to note down. A .trx (for me: C-4364__s-B2/kauai.trx), a .clmb (for me: C-4364__s-B2/kauai-X3.clmb and a .txt (for me: C-4364__s-B2/P-kauai-X3_M-HRPN_V-u__m-7.5.txt

These refer to files on OSX in /usr/share/firmware/wifi. Copy the trx, clmb and txt somewhere you can easily access them when you boot back into linux (e.g. your home directory if you want to mount the HSF partition in linux, a usb stick, etc)

Boot back into linux and place the files in the following locations:

  1. Copy the trx to /lib/firmware/brcm/brcmfmac4364-pcie.bin (e.g. sudo cp kauai.trx /lib/firmware/brcm/brcmfmac4364-pcie.bin
  2. The clmb to /lib/firmware/brcm/brcmfmac4364-pcie.clm_blob (e.g. sudo cp kauai-X3.clmb /lib/firmware/brcm/brcmfmac4364-pcie.clm_blob)
  3. The txt to something like /lib/firmware/brcm/brcmfmac4364-pcie.Apple Inc.-MacBookPro15,1.txt. You will need to replace 15,1 with your model number. (e.g. sudo cp P-kauai-X3_M-HRPN_V-u__m-7.5.txt /lib/firmware/brcm/brcmfmac4364-pcie.Apple Inc.-MacBookPro15,1.txt)

Use networkmanager and iwd:

sudo pacman -S networkmanager iwd
sudo systemctl start NetworkManager.service
sudo systemctl enable NetworkManager.service

If you're on kde also install plasma-nm

Configure networkmanager to use iwd. Create /etc/NetworkManager/NetworkManager.conf and add:

[device]
wifi.backend=iwd

Restart the NetworkManager service and you should have wifi working.

Touchbar

If you've installed the mbp15 branch of @roadrunner2's spi driver as outlined above you just need to load the modules:

modprobe apple-ib-tb
modprobe apple-ib-als

If you want the touchbar to display F* keys by default create /etc/modprobe.d/apple-tb.conf and add

options apple-ib-tb fnmode=2

Audio

See MCMrARM's gist here: https://gist.github.com/MCMrARM/c357291e4e5c18894bea10665dcebffb

Create the three files and reboot.

Suspend

As of 20/09/2019 you have to choose between audio and suspend though this will likely change when MCMrARM updates the bridge driver.

  1. Install the suspend branch of the bce module:
git clone https://github.com/MCMrARM/mbp2018-bridge-drv.git
cd mbp2018-bridge-drv
git checkout suspend
make
cp bce.ko /usr/lib/modules/extramodules-mbp/bce.ko
modprobe bce
  1. Blacklist applesmc

/etc/modprobe.d/applesmc.conf

blacklist applesmc
  1. Add pcie_ports=compat as a kernel parameter. Edit /etc/default/grub and add it to GRUB_CMDLINE_LINUX_DEFAULT e.g. GRUB_CMDLINE_LINUX_DEFAULT="loglevel=3 quiet pcie_ports=compat" then run grub-mkconfig -o /boot/grub/grub.cfg and reboot.

  2. Currently (20/09/2019) the touchbar driver crashes on resume and the thunderbolt driver causes suspend to take 30+ seconds and resume to take several minutes. This is fixed by automaitcally unloading the problematic modules on suspend and reloading them on resume.

Create /lib/systemd/system-sleep/rmmod.sh and add:

#!/bin/sh
if [ "${1}" == "pre" ]; then
        rmmod thunderbolt
        rmmod apple_ib_tb
elif [ "${1}" == "post" ]; then
        modprobe apple_ib_tb
        modprobe thunderbolt
fi

and make the file executable:

sudo chmod +x /lib/systemd/system-sleep/rmmod.sh

DisplayPort over USB-C

Works out of the box with a compatible adapter

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