Skip to content

Instantly share code, notes, and snippets.

@cobaohieu
Forked from gbrow004/ubuntu-MBP-16.md
Last active December 24, 2024 18:36
Show Gist options
  • Save cobaohieu/4a4074f6c65d3d3b9141d16541236969 to your computer and use it in GitHub Desktop.
Save cobaohieu/4a4074f6c65d3d3b9141d16541236969 to your computer and use it in GitHub Desktop.
Ubuntu on Apple Macbook Pro 15-inch (2015)

Acknowledgements Install Ubuntu on Macbook Pro

Requirements

2 USB drives >= 8GB

Pre-Install

Create bootable USB drive

  1. Grab the latest Ubuntu Desktop iso image

a. Method 1: Extract iso to USB with 7z

  • Download 7z for macOS
  • Unzip 7z2409-mac.tar.xz
  • Open Terminal and cd to the 7z2409-mac folder than type as below
./7zz x -y "ubuntu-iso-name.iso" -o"drag-USB-name-here"
  • Wait for a few minutes and you have a Ubuntu Bootable USB

b. Method 2: Using Balena Etcher to create usb bootable as these steps were paraphrased here

  1. Eject the USB drive with Finder or Terminal command line below
`diskutil eject /dev/diskN` (where N is the device)

Prep Macbook Disk

It's important to resize your disk using Disk Utility from inside of MacOS instead of using the Ubuntu installer. Don't worry about creating all the individual partitions right now, the partition creation will be handled during the install.

  1. Open Disk Utility in MacOS
  2. Choose Macintosh HD on the left side of the window
  3. Click on Partition on the right side of the window
  4. Click the + to add a new partition
  5. Resize the new partition and choose to leave it as free space

Driver Packages

Download the packages for bcmwl-kernel-source and dkms to another USB drive. We will use these packages in a later step to enable wifi.

Install

Ubuntu Installer

Plug in the USB drive that contains your Ubuntu image and reboot your Macbook. Once the screen goes black, hold down the Alt key until you see the boot menu. Choose EFI boot from the boot menu. You will be presented with the Grub menu, select 'Install Ubuntu'.

IMPORTANT: When you reach the screen in the installer titled "Installation Type", you must choose the option "something else". This allows for custom partitioning, if you let the installer choose, you may not be happy with the result.

Create whatever partitioning scheme you'd like, for example:

swap  swap 4GB
/     ext4 10GB
/home ext4 Remainder

NOTE: I recall reading somewhere that it was important to leave the 0MB free space partition between the MacOS partitions and the linux partitions, but I have been unable to find that reference.

IMPORTANT: Under Device for bootloader, ensure the EFI partition is selected /dev/sda1

Finish up the installation and boot into Ubuntu.

Post-Install

Wireless

What doesn't work

Wifi: Catalina is weird, so currently no one has firgured out what it's using to make WiFi work. It's either that or reverse engineer something. As a workaround, I use a USB WiFi adapter (TP-Link N150 USB) that works out of the box with most linux kernels and distros.

Sound via the speakers is a little weird. It technically works, but some apps don't seem to know how to connect. Although if you use the testing feature, you can hear the nice lady saying "Front!" "Left center", etc etc. Youtube in the browser gets sound, but sometimes VLC doesn't. Headphones through the jack or bluetooth audio seems to work OK, although I haven't fully tested out sound.

External GPU's: while other Thunderbolt 3 devices work well, including the OWC thunderbolt 3 dock, external GPU's seem to have some trouble. The eGPU is recognized and authorized, but the drivers don't load, despite what Ubuntu widgets are telling you. Even if you manually install nVidia drivers (sudo apt install nvidia etc), the driver seems to install, but using nvidia-smi complains about no drivers.

GDM3, the standard/usual/normal windows manager for Ubuntu. I'm not sure if it's a true bug or an incompatiblity with Apple's hardware. As a fix, I installed plasma (sddm). Basically you'll need to install kubuntu. Plenty of google help out there on that.

Hardware Prerequisites

You'll need at least the following hardware:

At least enough USB-A to USB-C converters or hub with enough ports for at least 3 USB devices if all your devices are USB-A:

  1. A USB drive with Ubuntu on it
  2. A USB keyboard
  3. A USB Mouse

Optional: USB to Ethernet adapter, compatible USB Wifi 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.

If you want to triple boot, I'd recommend installing Windows 10 before Linux, via bootcamp. If it isn't obvious, you'll need to create a partition using Disk Utility in MacOS to make room another OS partition. You'll actually want to partition drive and not just add another logical volume. Google it, if you need help with this. It's pretty well documented. NOTE: The following steps will mess up Windows boot (the install is safe). There's a fix for that at the end.

  1. Download Ubuntu 24.04 (Noble Numbat)

As of this writing, 24.04 is the only Ubuntu version out there that uses kernel 5.4, which is when the linux kernel gained the ability to access the internal Apple NVME SSD.

Download from here: https://releases.ubuntu.com/24.04.1/ubuntu-24.04.1-desktop-amd64.iso

  1. Use your favorite program to write the ISO to a USB stick (Balena etcher for Mac, etc).

Installation

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

Insert the USB stick and boot the laptop holding down the "option" key to seelct the USB for boot (it'll be an orange EFI disk. Choose the far right one, if there are multiple.)

The text will be tiny, but choose the second option (try Ubuntu without installing (Safe graphics).

I don't know what the issue is, but grub and/or Ubuntu really don't like this laptop. Therefore, we're going to install Ubuntu WITHOUT a bootloader. To do this, open up a terminal and type sudo ubiquity -b Proceed to install as normal and make sure you're installing to the empty partition you made and not MacOS or Windows.

On reboot, your laptop should boot directly into MacOS as there's no way to boot into linux at this point. Download REFIND from sourceforge and install it the standard way.

REFIND: https://sourceforge.net/projects/refind/

Installation Instructions: https://www.rodsbooks.com/refind/installing.html

Reboot. You should be able to select Ubuntu now via REFIND. Boot into Ubuntu.

WiFi (currently not working. Here for reference if using the 2018 MBP's running Mojave)

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

It will show something like:


    | |   |         |       "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:

Copy the trx to /lib/firmware/brcm/brcmfmac4364-pcie.bin (e.g. sudo cp kauai.trx /lib/firmware/brcm/brcmfmac4364-pcie.bin The clmb to /lib/firmware/brcm/brcmfmac4364-pcie.clm_blob (e.g. sudo cp kauai-X3.clmb /lib/firmware/brcm/brcmfmac4364-pcie.clm_blob) 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, sudo /etc/modprobe.d/apple-tb.conf and add

options apple-ib-tb fnmode=2

Fixing bootcamp/Windows

If you had installed Windows 10 via bootcamp prior to intalling Ubuntu, you may have noticed that Windows no longer boots. Fear not! Windows is still there, but for some reason, bootcamp installs Windows 10 in hybrid legacy/GPT mode instead of the regular UEFI. Here's the fix:

  1. Boot into linux

  2. Open a terminal and type sudo gdisk /dev/nvme0n1

  3. Push x for expert mode

  4. Press n to create a protective MBR

  5. Press w to write the partition and y to confirm

  6. If you're not automatically exited from gdisk, then type q to exit

Reboot and hold down the option key to choose the boot drive. Pick Windows and confirm it loads properly. If so, you'll need to reboot back into MacOS and reinstall rEFInd. This should resolve any weird boot behavior (ie, no more win10, resetting MacOS password, etc).

Using the integrated GPU to save battery life

You'll need to spoof the Macbook Pro into thinking it's booting into MacOS when it's really booting into Linux (this also works for Windows!). Follow the directions here:

https://github.com/0xbb/apple_set_os.efi

Bootloader

Add MacOS as option on Grub menu

Append the following lines to /etc/grub.d/40_custom:

menuentry "MacOS" {
 exit
 multiboot /boot
}

Change these options in /etc/default/grub:

#GRUB_HIDDEN_TIMEOUT=0                  # Disable hidden Grub
#GRUB_HIDDEN_TIMEOUT_QUIET=true         # Disable hidden Grub
GRUB_TIMEOUT=5                          # [Optional] Set smaller timeout (default was 10)
GRUB_CMDLINE_LINUX="libata.force=noncq" # Linux parameter to prevent occasional SSD freezes
GRUB_DEFAULT=2                          # [Optional] Default to MacOS entry

Fix small grub fonts

On the command line execute the following:

sudo grub-mkfont -s 36 -o /boot/grub/DejaVuSansMono.pf2 /usr/share/fonts/truetype/dejavu/DejaVuSansMono.ttf

Open and edit again /etc/default/grub and add the following line at the bottom:

GRUB_FONT=/boot/grub/DejaVuSansMono.pf2

Update Grub

sudo update-grub

Common issues

Wifi stops working after suspend

This is caused by a bug in the network-manager.

You can verify this by running the following to see if wifi returns:

sudo systemctl restart network-manager.service

To automate restarting network-manager, create /etc/systemd/system/wifi-resume.service and paste the following into it:

#/etc/systemd/system/wifi-resume.service
#sudo systemctl enable wifi-resume.service
[Unit]
Description=Restart networkmanager at resume
After=suspend.target
After=hibernate.target
After=hybrid-sleep.target

[Service]
Type=oneshot
ExecStart=/bin/systemctl restart network-manager.service

[Install]
WantedBy=suspend.target
WantedBy=hibernate.target
WantedBy=hybrid-sleep.target

Finally run this to activate it:

sudo systemctl enable wifi-resume.service

Fan not working properly

The Macbook Pro's fan requires a daemon to adjust the speed.

Add the following to /etc/modules:

coretemp
applesmc

Install build-essential package: sudo apt install build-essential

Clone the mbpfan source:

git clone [email protected]:dgraziotin/mbpfan.git

Follow directions found here to build and install: A beginner's tutorial for mbpfan under Ubuntu

High CPU usage by kworker

The most important issue I have found so far is the high CPU usage by kworker (i.e. Linux Kernel worker thread), which seriously affects the battery life. Apparently this is caused by an interrupt storm on ACPI interrupt GPE06, as described here. You can verify it by checking if interrupt GPE06 contains a high value:

$ grep . -r /sys/firmware/acpi/interrupts/
...
/sys/firmware/acpi/interrupts/gpe05:       0   invalid
/sys/firmware/acpi/interrupts/gpe06: 2938373   enabled <---
/sys/firmware/acpi/interrupts/gpe07:       0   enabled
...

A quick solution for this issue is to disable this interrupt, i.e.

echo disable > /sys/firmware/acpi/interrupts/gpe06

In order to disable it on every boot, you can add the previous line to /etc/rc.local, just before exit 0.

Remap MacBook Pro keyboard keys to be standard

Create /etc/systemd/system/keyboard-map.service and paste the following into it:

#sudo systemctl enable keyboard-remap.service
[Unit]
Description=Remap keyboard keys
After=multi-user.target

[Service]
Type=oneshot
ExecStart=/usr/bin/setxkbmap -device $(/usr/bin/xinput list --id-only "keyboard:Apple Inc. Apple Internal Keyboard / Trackpad") -option "altwin:swap_alt_win"

[Install]
WantedBy=multi-user.target

Finally run this to activate it:

sudo systemctl enable keyboard-remap.service

http://askubuntu.com/questions/29731/rebind-alt-key-to-win-using-setxkbmap https://lampjs.wordpress.com/2015/06/26/remapchange-your-secondaryusb-keyboard-keys/

Install on Gnome Extension

https://extensions.gnome.org/extension/3264/ubuntuvn-desktop/

Install another packages

sudo add-apt-repository ppa:aglasgall/pipewire-extra-bt-codecs
sudo apt update
sudo apt-get install ubuntu-restricted-extras
sudo apt-get install libav-tools libavcodec60 ffmpeg
sudo apt-get install gstreamer1.0-libav ffmpeg
sudo apt install libdvdnav4 gstreamer1.0-plugins-bad gstreamer1.0-plugins-ugly libdvd-pkg
sudo apt-get update
sudo apt-get install gstreamer0.10-ffmpeg

References

Installing Ubuntu 15.04 on a Macbook Pro 11,2

Arch - MacBookPro

Installing Ubuntu 15.10 - Wily Werewolf on a Macbook Pro 12-1 (2015)

Wifi doesn't work after suspend after 16.05 upgrade

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