/ linux

Linux on mid-2017 MacBookPro


This article describes how to install Ubuntu Linux on your MacBookPro.


Apple MacBook Pro "Core i7 2.9 15" Touch/Mid-2017 with AMD Radeon Pro 560

Target OS/Distro

Linux 4.13 or newer on Ubuntu 16.04

Not working but can be worked around

- Audio input & output
- Wireless card

I am using a USB Wi-Fi adapter TP-LINK TL-WN722N for $15 and for audio any bluetooth headphones/speakers is working fine.

Preparing the disk

Partition for your Linux installation

You would need 10 GB minimum or 25 GB recommended space for the Ubuntu 16.04 installation.

All you need to do is to reduce your Macintosh HD partition from macOS by using Disk Utility. The freed space will be used by the Ubuntu Linux installer.

Remastering Ubuntu distro

I used another laptop running Ubuntu to apply the steps described in this section.

There are two drivers which you need to add to your Linux in order to avoid the unnecessary hassle with connecting external USB keyboard/mouse/stick as most of the howto's suggest.

By creating your own remastered Ubuntu Linux distribution, you will have a handy recovery tool you can use at any time.

Get Ubuntu

You can download it from its official website https://www.ubuntu.com/download/desktop

Extract the image

You need to extract the Ubuntu image before you can start remastering it.

cd ~/Downloads
sudo mkdir /mnt/iso
sudo mount ubuntu-16.04.4-desktop-amd64.iso /mnt/iso
mkdir customiso
rsync -a --exclude=casper/filesystem.squashfs /mnt/iso/ customiso/
sudo unsquashfs /mnt/iso/casper/filesystem.squashfs
sudo umount /mnt/iso

Chroot to the image

Once the image is extracted, you will need to continue remastering it from inside. To do so, you will need to use chroot.

sudo mount --bind /dev squashfs-root/dev/
sudo chroot squashfs-root/
PS1="(chroot) $PS1"
export PS1 HOME LC_ALL

mount -t proc none /proc
mount -t sysfs none /sys
mount -t devpts none /dev/pts

Update the image

It is a good idea to keep the software updated.

mv /etc/resolv.conf /etc/resolv.conf.bak
echo 'nameserver' | tee /etc/resolv.conf

apt-get update
apt-get upgrade
apt-get dist-upgrade
apt-get autoremove

apt-get -f install


Since MacBookPro mid-2017 is a pretty new hardware, it makes sense to ensure you are running it on the newest Linux kernel and the display server (Xorg).

In Ubuntu you can use the LTS Enablement Stack which is achieved simply by running the following command:

apt-get install --install-recommends linux-generic-hwe-16.04 xserver-xorg-hwe-16.04


In order to enable the external TP-LINK TL-WN722N USB WiFi adapter, you need to make sure the Ubuntu image has the necessary driver.

echo -e "\n# TP-LINK TL-WN722N\n8188eu" >> /etc/initramfs-tools/modules

apt-get install git dkms

git clone https://github.com/lwfinger/rtl8188eu.git
dkms add ./rtl8188eu
dkms install 8188eu/1.0

# lsinitramfs /boot/initrd.img-4.13.0-36-generic | grep -i 8188eu


To avoid hassle with plugging the external keyboard/mouse, you can already build in the keyboard/touchbar drivers:

echo -e "\n# macbook12-spi-drivers\napplespi\nappletb\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 .
dkms install -m applespi -v 0.1

# lsinitramfs /boot/initrd.img-4.13.0-36-generic | grep -iE "appletb|applespi"


Next, you need to set the proper dpi for the touchpad:

cat > /etc/udev/hwdb.d/61-evdev-local.hwdb << 'EOF'
# MacBook8,1 (2015), MacBook9,1 (2016), MacBook10,1 (2017)
evdev:name:Apple SPI Touchpad:dmi:*:svnAppleInc.:pnMacBook8,1:*
evdev:name:Apple SPI Touchpad:dmi:*:svnAppleInc.:pnMacBook9,1:*
evdev:name:Apple SPI Touchpad:dmi:*:svnAppleInc.:pnMacBook10,1:*

# MacBookPro13,* (Late 2016), MacBookPro14,* (Mid 2017)
evdev:name:Apple SPI Touchpad:dmi:*:svnAppleInc.:pnMacBookPro13,1:*
evdev:name:Apple SPI Touchpad:dmi:*:svnAppleInc.:pnMacBookPro13,2:*
evdev:name:Apple SPI Touchpad:dmi:*:svnAppleInc.:pnMacBookPro14,1:*
evdev:name:Apple SPI Touchpad:dmi:*:svnAppleInc.:pnMacBookPro14,2:*

evdev:name:Apple SPI Touchpad:dmi:*:svnAppleInc.:pnMacBookPro13,3:*
evdev:name:Apple SPI Touchpad:dmi:*:svnAppleInc.:pnMacBookPro14,3:*
cat > /etc/udev/hwdb.d/61-libinput-local.hwdb << 'EOF'
libinput:name:*Apple SPI Touchpad*:dmi:*

Exit chroot environment

Exit the chroot environment when you are done modifying the Ubuntu image.

mv /etc/resolv.conf.bak /etc/resolv.conf
umount /dev/pts
umount /sys
umount /proc
sudo umount squashfs-root/dev/

Updating the kernel

To ensure the remastered Ubuntu boots the latest Linux kernel which you have installed in the chrooted system.

sudo cp squashfs-root/boot/vmlinuz-4.13.0-36-generic.efi.signed customiso/casper/vmlinuz.efi
sudo sh -c "gunzip -c squashfs-root/boot/initrd.img-4.13.0-36-generic | lzma -c > customiso/casper/initrd.lz"

Build remastered Ubuntu image

The following steps are to build the remastered Ubuntu image.
When running xorriso, keep in mind the order of arguments is important.

sudo rm customiso/casper/filesystem.squashfs
sudo mksquashfs squashfs-root customiso/casper/filesystem.squashfs

cd customiso
sudo rm md5sum.txt
sudo find -type f -print0 | xargs -0 sudo md5sum | grep -Ev "md5sum.txt|isolinux/boot.cat" | sudo tee md5sum.txt
cd ..

apt -y install xorriso isolinux

sudo xorriso -as mkisofs \
  -r -V "UBUNTU4MAC" -R -l -o ubuntu4mac.iso \
  -c isolinux/boot.cat -b isolinux/isolinux.bin \
  -no-emul-boot -boot-load-size 4 -boot-info-table \
  -isohybrid-mbr /usr/lib/ISOLINUX/isohdpfx.bin \
  -eltorito-alt-boot \
  -e boot/grub/efi.img \
  -no-emul-boot -isohybrid-gpt-basdat customiso/

Test the new image

Make sure your image boots, before writing the remastered it to your USB stick.

Out of the following methods, you would likely only need UEFI -> USB.

Install the UEFI firmware and qemu for running virtual machines:

apt-get -y install ovmf qemu-system-x86

Legacy (BIOS)

CDROM: qemu-system-x86_64 -enable-kvm -m 1G -cdrom ubuntu4mac.iso
USB: sudo qemu-system-x86_64 -enable-kvm -m 1G -device nec-usb-xhci,id=xhci -drive if=none,id=stick,file=ubuntu4mac.iso,format=raw -device usb-storage,bus=xhci.0,drive=stick


CDROM: qemu-system-x86_64 -enable-kvm -m 1G -bios /usr/share/ovmf/OVMF.fd -cdrom ubuntu4mac.iso
USB: sudo qemu-system-x86_64 -enable-kvm -m 1G -bios /usr/share/ovmf/OVMF.fd -device nec-usb-xhci,id=xhci -drive if=none,id=stick,file=ubuntu4mac.iso,format=raw -device usb-storage,bus=xhci.0,drive=stick

Installing the Linux

Boot your MacBookPro from your newly remastered Ubuntu - ubuntu4mac.iso
and create the following partitions:

/dev/nvme0n1p4 EFI 1024 MB
/dev/nvme0n1p5 /boot ext4 1024 MB
/dev/nvme0n1p6 physical volume for encryption (all free space)
on top of /dev/mapper/nvme0n1p6_crypt set ext4 and / as a mountpoint

Make sure you have set /dev/nvme0n1p5 as a "Device for boot loader installation".

Get the Ubuntu EFI files back to their place

When the Ubuntu Linux installation finishes, do not restart your MacBookPro yet.

The Ubuntu installer mounted /dev/nvme0n1p1 instead of /dev/nvme0n1p4 as an EFI partition and put Ubuntu EFI files in there.
To fix this, apply the following steps.

Move Ubuntu EFI files to a correct partition

mount /dev/mapper/nvme0n1p6_crypt /target
mount /dev/nvme0n1p5 /target/boot/
mount /dev/nvme0n1p4 /target/boot/efi/

mkdir /mnt/p1
mount /dev/nvme0n1p1 /mnt/p1
rsync -avHx --progress /mnt/p1/EFI/ubuntu /target/boot/efi/
rm -rf /mnt/p1/EFI/ubuntu
umount /mnt/p1

Tell the future system to use a proper EFI partition

Get UUID of your EFI partition by running blkid /dev/nvme0n1p4 and set it in the /target/etc/fstab file for the /boot/efi mountpoint.

Set proper EFI boot record

Without this record your MacBookPro will not boot into the installed Ubuntu Linux.

efibootmgr -v
efibootmgr -v -c -d /dev/nvme0n1 -p 4 -L ubuntu -l '\EFI\ubuntu\shimx64.efi'

Boot your Linux

Now you can reboot your system without the remastered Ubuntu image.
In order to boot back into macOS, just hold "option" button while your laptop is booting and select "Macintosh HD".


Having the remastered Ubuntu Linux USB stick handy, you can boot off it, mount your partitions where Ubuntu is installed, chroot into it and fix the issues.

Mounting your system

cryptsetup luksOpen /dev/mapper/nvme0n1p6 nvme0n1p6_crypt
mkdir /target
mount /dev/mapper/nvme0n1p6_crypt /target
mount --bind /dev /target/dev/
mount /dev/nvme0n1p5 /target/boot/
mount /dev/nvme0n1p4 /target/boot/efi/

Chrooting to your system

chroot /target
PS1="(chroot) $PS1"
export PS1 HOME LC_ALL

mount -t proc proc /proc
mount -t sysfs sys /sys
mount -t devpts none /dev/pts
mount -t efivarfs efivarfs /sys/firmware/efi/efivars

Now you can fix things like EFI boot records, changing Linux kernel, updating drivers and so on.

Exitting chroot

umount /sys/firmware/efi/efivars
umount /dev/pts
umount /sys
umount /proc

Unmounting your system

umount /target/dev
umount /target/boot/efi
umount /target/boot/
umount /target/
cryptsetup luksClose nvme0n1p6_crypt


Windows in QEMU/KVM

You can download Windows 10 for free and install/use it in QEMU/KVM.

Steam in Docker

As a great surprise for some, you can play games in Linux on your MacBookPro using AMD Radeon Pro 560.
For that you can either install Steam on your own or use my Steam image which is much simpler https://hub.docker.com/r/andrey01/steam/


If bluetooth is not working for you, you can backport patch for your Linux kernel or just install a fresh one.

I am using the mainline kernel, to install one apply the following steps.

Download the kernel http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.16-rc3

sudo dpkg -i linux-headers-4.16.0-041600rc2_4.16.0-041600rc2.201802190311_all.deb linux-headers-4.16.0-041600rc2-generic_4.16.0-041600rc2.201802190311_amd64.deb linux-image-4.16.0-041600rc2-generic_4.16.0-041600rc2.201802190311_amd64.deb

This will automatically trigger dkms which will rebuild your kernel modules.

# dkms status
8188eu, 1.0, 4.13.0-36-generic, x86_64: installed
8188eu, 1.0, 4.16.0-041600rc2-generic, x86_64: installed
applespi, 0.1, 4.13.0-36-generic, x86_64: installed
applespi, 0.1, 4.16.0-041600rc2-generic, x86_64: installed


- Linux On MBP Late 2016
- MBP 2016 Linux

Andrey Arapov

Andrey Arapov

"If you want to live a happy life, tie it to a goal, not to people or things." - Albert Einstein

Read More