Skip to content

Instantly share code, notes, and snippets.

@Tomasvrba
Last active March 30, 2024 17:46
Show Gist options
  • Star 17 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save Tomasvrba/f91f7399d99d3e25b62116cbe54794f8 to your computer and use it in GitHub Desktop.
Save Tomasvrba/f91f7399d99d3e25b62116cbe54794f8 to your computer and use it in GitHub Desktop.

How to set up Linux dual-boot on a MacBook Pro

1. Partitioning and bootloader setup

  • Partition your drive using the Disk Utility (hold Command + R during startup and select "Disk Utility")
  • Create a new partition (NOT Volume, important!) with at least 50GB of space and preferrably the Ext4 filesystem so it's recognized by the Linux installer
  • On OS X El Capitan and later disable SIP (System Integrity Protection):
    • Restart your Mac and hold Command + R again to get into Recovery mode.
    • Open the Terminal and enter the following:
      $ csrutil disable
    • Restart your Mac
    • Once you have the Mac desktop back, download rEFInd from SourceForge at rEFInd beta, an EFI boot manager utility. Open the downloaded refind-bin-0.12.0 (or later) folder and install rEFInd with the ./refind-install file
    • Optional but recommended: Go back to Recovery mode and re-enable SIP by entering the following in Terminal:
      $ csrutil enable

More details here: https://www.lifewire.com/dual-boot-linux-and-mac-os-4125733

2. Installation

  • Plug in the live USB installation media with your Linux distribution
  • Now when you boot your Mac, you should get the rEFInd bootloader screen.
  • Select the Boot EFI\boot... entry (rEFInd) to boot from your Linux USB
  • Proceed with installation. When asked for Installation type, choose Something else and manually configure the partitioning scheme on the partition you reserved previously.
  • I recommend the following swap and root partitions: https://www.maketecheasier.com/install-dual-boot-ubuntu-mac/

3. After installation

3.1. Fixing the bootloader

After installation, Ubuntu (GRUB) will likely take over as the main bootloader and boot automatically into Linux, without giving you the option to boot into MacOS. To change the bootloader priority back to rEFInd for dual booting, use efibootmgr.

You will get output similar to this:

$ sudo efibootmgr 
BootCurrent: 0080
BootOrder: 0000, 0080, 0081
Boot0000* ubuntu
Boot0080* Mac OS X
Boot0081* Mac OS X
Boot0082* 
BootFFFF*

If you're not seeing rEFInd already, you can determine the boot partition it's on with sudo efibootmgr -v and then change the boot order accordingly. In my case with:

$ sudo efibootmgr -o 0080,0000,0081

to set the boot priority in order of: rEFInd, Ubuntu, MacOS

For more details see: https://www.rodsbooks.com/refind/bootcoup.html#efibootmgr

3.2. Fixing Wi-Fi and wireless drivers:

With Apple using Broadcom hardware for networking, there is a good chance your wireless won't work on Linux out of the box. This is most easily resolved if you have internet access either via ethernet cable or USB/Bluetooth tethering from your phone. This issue is a little more complex since it can depend on the exact version and revision of your Broadcom network card. These are the steps that worked for me:

$ sudo apt-get purge bcmwl-kernel-source
$ sudo apt update
$ sudo update-pciids
$ sudo apt install firmware-b43-installer
$ sudo reboot
$ sudo iwconfig wlp2s0 txpower 10dBm

Unfortunately, the last command, setting the iwconfig does not persist across reboots and needs to be run on each startup. To solve this, I added a short script to my ~/.config/autostart to run this on my user login/ To the following file: ~/.config/autostart/iwconfig.desktop add:

[Desktop Entry]
Name=Iwconfig
Comment=Configure wireless network interface transmit power for MacBook Pro
Type=Application
Exec=bash -c "sudo iwconfig wlp2s0 txpower 10dBm"

To dig into more details to find out which Broadcom card you have and which drivers you might need, see:

3.3. Fixing the mouse touchpad and the Touch Bar

For the newer MacBook Pros with the upper Touch Bar, this most likely won't work out of the box, and possibly neither will your mouse touchpad. The instructions below are specific to Debian/Ubuntu distros. For others, see this guide: https://gist.github.com/roadrunner2/1289542a748d9a104e7baec6a92f9cd7#keyboardtouchpadtouchbar

To get everything working, do this:

$ sudo apt install linux-headers-generic dkms
# Prepare for the modules to be included in the ramdisk (so they are loaded early during boot):
$ cat <<EOF | sudo tee -a /etc/initramfs-tools/modules
# drivers for keyboard+touchpad
applespi
apple-ib-tb
intel_lpss_pci
spi_pxa2xx_platform
EOF
# get and build the drivers
$ git clone https://github.com/roadrunner2/macbook12-spi-driver.git
$ cd macbook12-spi-driver
$ git checkout touchbar-driver-hid-driver
$ sudo ln -s `pwd` /usr/src/applespi-0.1
$ sudo dkms install applespi/0.1

Next we need to set the proper dpi for the touchpad and adjust the sensitivity (download the 61-evdev-local.hwdb, 61-libinput-local.hwdb, and local-overrides.quirks from this gist - the 61-evdev-local.hwdb is only needed for udev < 242, the 61-libinput-local.hwdb is needed for libinput versions < 1.12, the local-overrides.quirks for libinput versions >= 1.12):

# if 'udevadm --version' less than 242:
$ sudo cp <the-downloaded-61-evdev-local.hwdb> /etc/udev/hwdb.d/61-evdev-local.hwdb
# if 'libinput --version' less than 1.12:
$ sudo cp <the-downloaded-61-libinput-local.hwdb> /etc/udev/hwdb.d/61-libinput-local.hwdb
# if 'libinput --version' 1.12 or later:
$ sudo mkdir /etc/libinput # if it doesn't exist
$ curl https://gist.githubusercontent.com/roadrunner2/1289542a748d9a104e7baec6a92f9cd7/raw/3d46a8ae6576fffa816edd53e78fa9cba27198e3/local-overrides.quirks > local-overrides.quirks
$ sudo mv local-overrides.quirks /etc/libinput/
$ sudo systemd-hwdb update

You can test the drivers by loading them and their dependencies:

sudo modprobe intel_lpss_pci spi_pxa2xx_platform applespi apple-ib-tb

Finally, reboot to make sure it all works correctly:

sudo reboot

3.4. Fixing Suspend/Hybernation

To get the Suspend functionality to work at least somewhat we need to disable the d3cold PCIe power state for the NVMe controller to successfully wake up again by setting sys/bus/pci/devices/0000\:01\:00.0/d3cold_allowed to 0 using echo 0 > /sys/bus/pci/devices/0000\:01\:00.0/d3cold_allowed: https://github.com/Dunedan/mbp-2016-linux#suspend--hibernation

Unfortunately, this variable gets reset on every startup, so I added the command to root's (must be root!) crontab with @reboot:

$ sudo crontab -e
@reboot bash -c "echo 0 > /sys/bus/pci/devices/0000\:01\:00.0/d3cold_allowed"

4. Additional resources:

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