Linux Driving a Macbook Pro Retina Part 1
Have you ever felt the OSx UI/system to be too restrictive ?
Are you fed up with how the UI on the later installations of OSx is transforming itself into a phone UI ?
< insert_additional_favourite_reason_here >
Have you ever wondered how it is like to run a linux distro on a macbook pro retina, just in case you had to use a macbook pro but don’t want/like to use the OSx installation ?
If so than continue reading to find out more.
Summary / tl;dr for this blog post
Since this is a large blog post I’ll give you a content summary:
- introduction and motivation telling you why I chose to use linux on a macbook pro retina
- hardware description
- the things I can remember about the installation procedure
- summary of laptop functions that work
- summary of laptop functions that don’t work and glitches
- summary of other fixes and hacks that I employ to drive the macbook. Some of these scripts/hacks are not only macbook related, they can be used on other hardware.
- video showcase where I show the macbook being driven by linux ( in part 2 of this blog post )
- links to resources and inspiration that have helped me
Introduction and motivation
My work laptop is a macbook pro retina 11,3 as can be seen from the lshw
output.
1 2 3 4 5 6 7 8 |
|
I don’t have an option to choose a linux friendly laptop so I’m stuck with the macbook pro for work.
As a personal preference, at the same time I want the flexibility and ease of use of the linux ecosystem and tooling:
- really simple way of installing software: via a package manager
- desktop environment / window manager of choice - not the same phone UI enforced on everyone
- native support for container technology ( no need for another VM to run containers - run containers directly on the laptop installation )
- native kernel resource management using cgroups
I’ve decided to test how easy it is to run a linux distro on a macbook pro retina.
This decision was taken at a time when ubuntu 14.04 was in beta stage.
Hardware description
The laptop is a macbook pro retina, late 2013 model. ( MacbookPro11,3 as lshw
shows )
You can find the full technical specification on the apple support website [14]
Ubuntu has a community maintained wiki page about the MacbookPro11,3 [15]
See the intel ark website for a detailed description of this beast of a CPU [16]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
|
1 2 3 4 5 |
|
1 2 3 4 |
|
The integrated Intel Iris 5200 graphics card is invisible to the linux kernel, continue reading to find out why.
1 2 3 4 5 6 7 8 9 10 |
|
Installation
I’ll lay down the installation notes from memory since I don’t have my detailed installation notes.
I chose to install, as a linux distro of my preference Ubuntu 14.04 LTS, because I could remember from previous encounters with running linux on a macbook pro(in 2010 and in 2012) that Ubuntu’s kernel had better support for the macbook pro hardware.
Seeing Ubuntu as having better kernel support for macbook hardware is not the case these days as you can see from the list of resources at the end of this post. These days people have installed various other distros on macbooks.
The installation has taken place in march 2014, when Ubuntu 14.04 LTS was in beta stage.
boot manager
Even before thinking of installing linux on your macbook you have to install a boot manager ( equivalent to grub) capable of being booted by the Apple firmware ( equivalent to a bios ).
rEFInd [1] installs itself on the MBR of the HDD/SSD. rEFInd will give you the ability to choose which OS to boot in the eventuality of a dual-boot scenario ( which is what I intended originally )
As I found out during the initial installation, these days grub-efi
is more than capable to act as the boot manager to boot from the Apple firmware, rEFInd is not necessary for single boot. For dual-boot it might still be necessary. [2]
This is how you can check if you’re booting using grub-efi
as opposed to rEFInd
[17]
1 2 3 4 5 6 7 8 9 10 11 |
|
HDD partitioning
Initially I’ve intended for this installation to be a dual boot system ( 50% HDD space for OSx, 50% for linux )
This was because at the time of installation a macbook pro retina was still new hardware and I wasn’t really sure if I would have enough support on linux to run the macbook, with linux, in an satisfactory state.
Because the installation took place very late during the night, and lack of sleep always strikes back, during the installation procedure I happen to choose as a partitioning scheme: full encrypted LVM.
This partitioning scheme makes Ubiquity [3], the ubuntu graphical live CD/DVD installer, overwrite the MBR of the SSD making it impossible at this point to boot into OSx.
Not having an OSx installer DVD at hand at this point I said it is time to go all the way to see what linux is capable of on this macbook hardware. There was no turning back at this point anyway until a couple of days later when I could get the install USB stick from the office.
This means that the dual boot system quickly became a 100% linux installation.
As we all know SSD drives are much much faster than HDD drives but their life span is shorter apparently(no SSD drive has died on me yet). In order to prolongue the life of the SSD I’ve enabled trim on the non-encrypted partitions, for reference here are the SSD trim settings that I use.
1 2 3 4 5 6 7 |
|
Because this is a work laptop I’ve decided to also encrypt a single partition that holds all sensitive data.
HDD encryption
I won’t delve too much into the SSD encryption, this whole area deserves its own blog post entry.
Enough to say that I’ve used an encrypted LUKS volume.
Using a LUKS encrypted partition, with the aid of cryptsetup
, and libpam-mount
allows me to automatically mount the encrypted partition after I type the login password for my user ( in a cold boot situation ).
Build yourself a new kernel
I can’t remember 100% why, but I had to build a whole new kernel, that didn’t ship with ubuntu 14.04 at the time of the installation.
I think the reason for building a newer kernel was to boot from a 3.16.x
kernel so that I can get support for the hardware / multimedia buttons on the macbook pro’s factory crippled keyboard ( I’m referring to missing keyboard keys compared to non-apple laptops if you haven’t spotted the pun :) ).
If anybody else is using linux on a macbook pro and is running a newer than 3.16.x
kernel and it works, please shout and I’ll give it a try.
This blog post [4] has a pretty good approximation of the steps I took to compile a new kernel, I don’t have notes from my kernel compilation.
Wireless
1 2 3 |
|
To install the wireless driver, which Ubiquity wasn’t be able to do for you at that time, I had to use the USB-to-ethernet dongle(wired networking) , download these 2 packges from http://packages.ubuntu.com/ :
bcmwl-kernel_source
( for the broadcom driver )dkms
and install them by hand.
After that the wireless works as intended.
The problem that I’ve found with the wireless card is that newer kernels from the ubuntu kernel ppa don’t work with it. ( I haven’t tried any of the 4.x kernels lately )
If you’re running a newer kernel version on your macbook shout on a twitter DM and I’ll look into it.
Video cards
1 2 3 |
|
The macbook pro retina comes with 2 graphics cards. An integrated Intel Iris 5200 1.5GB RAM graphics card for light graphics tasks and a discrete Nvidia Geforce GT 750M 2GB RAM for heavy graphics tasks.
Unlike the first generation of macbook pro retina which had a BIOS/physical switch for the graphics cards the late 2013 macbook pro retina 11,3 comes with a downgrade in terms of video switching.
The switching between the intel card which consumes far far less power and the power hungry nvidia card happens all in software ( inside the OSx OS ) [5]
This weird software switch plus the fact that the 2 thunderbolt/mini-DVI ports on the laptop are tied to the discrete nvidia card means that it is impossible to use the intel graphics card, especially since I’m using 2 external monitors.
This intentional crippling exists even if the Intel Iris 5200 can easily support 2 external monitors on the versions of macbook pro retina that only come with an integrated Iris 5200 card. [6]
Currently I can only use the nvidia graphics card, the intel card is invisible to my linux installation.
For the nvidia driver I initially installed the driver that was present in the ubuntu repos
1
|
|
then I’ve found out about the xorg-edgers ppa repo and I continue to this day to update the nvidia driver via this ppa
1 2 3 |
|
Gaming
I’ve installed the Steam client and have played a couple of hours of dota2 to test the graphics functionality of the Nvidia graphics card.
I’ve ran dota2 at near max settings, without antialiasing, I think, it was working well enough, I didn’t spot any glitches.
Since this test I’ve not played any games on this laptop.
For gaming and other video intensive tasks ( think video editing ) I have a Linux KVM VGA passthrough VM ( virtual machine, you read it correctly ), running on a desktop computer.
This should be a good topic for another blog post.
Desktop environment
The desktop environment that feels the most useful to me is KDE.
I’ve used many DEs and dabbled with some standalone WMs during my journeys into the linux world: kde3.x, gnome2.x, xfce, unity, fluxbox, openbox, briefly gnome3.x, kde4.x
Fair to say that I’ve seen many approaches to the UI in linux.
I currently use the KDE version packaged with Ubuntu14.04, which is KDE 4.13.3, as my daily DE. I’ve been using KDE4.x for the last 2 years.
I’ve used unity before and during multiple sleep/wake-up cycles it used to leak memory like crazy and become really slow on a quad core i7 laptop. That was unnaceptable ! This wasn’t my only gripe with unity, just one of the ones I can remember now.
To install KDE over the ubuntu install that comes with unity all I had to do was:
1
|
|
After this logout and, and on login, choose KDE as the desktop environment. That is all there is to installing KDE over a standard Ubuntu installation.
I won’t go into much detail on why I like KDE as a DE, I’ll enumerate just a few useful features:
- kwin is without a doubt one of the best window managers out there, maybe even the best window manager
- KDE’s notification tray allows me to catchup on lost notifications, a feature that I’ve not seen implemented in any of the other DEs or even the OSx notifications
- customisations galore in the KDE UI allows the user to transform the DE as she/he chooses or to just use the defaults. The fact that it caters for both categories of users is a big plus in my book.
- the fact that kwin comes with just enough features from a tiling window manager, without being a full tiling window manager, is another big plus for me. In my workflow I have to tile windows to a corner of the monitor, or to half of the monitor using keyboard shortcuts. kwin has this feature builtin.
Tiling window support
You’ll find the keyboard shortcuts for tiling kwin windows in the system settings:
1
|
|
You can achieve the same effect by using the mouse. I find myself using the keyboard 99% of the time for tiling windows though.
Keyboard
Screen backlight / media buttons / keyboard backlight
The macbook pro media keys and keyboard backlight keys worked out of the box after installing KDE and booting the 3.16.x
kernel, I didn’t have to do anything else to get these keys to work.
On the other hand to get the panel brightness keys to actually change the brightness of the laptop panel I had to add this in my /etc/rc.local
1 2 |
|
F1-F12 keys
By default the hid_apple
driver recognises the keyboard including the backlight keys and uses them as you would on an OSx installation.
I want to use the F1-F12 keys as function keys. The apple keyboard is missing other keyboard keys as it is anyway ( no insert, no delete keys …) , I don’t want to loose the F1-F12 keys as well.
To set the the F1-F12 keys to normal functionality ( pressing Fn + F10 for muting the volume and pressing just F10 means F10 for example ) I had to change the behaviour of the hid_apple
driver, regenerate the kernel initramfs and reboot.
1 2 3 |
|
Font-antialiasing
KDE supports font antialiasing natively and it is easy to setup by using the System Settings GUI.
Touchpad
Normal mode scrolling
This is the normal mode of scrolling, meaning different than what the apple marketing machinery has named natural scrolling which is reverse scrolling.
KDE’s system settings comes by default with normal scrolling or if you really prefer it you can have reverse scrolling, just change the touchpad settings.
Multitouch
By default the only multitouch gesture supported out of the box by a KDE 4.x installation is two finger scrolling. Set it up in the System Settings GUI and you’re done.
If you want to enable ala OSx multitouch in linux, here is another person that has solved that problem. [9]
Laptop functions that work
Sleep
Putting the laptop to sleep and waking up the laptop works flawlesly almost 100% of times.
Sleeping is a little slow , after you close the lid it takes 30s until the laptop actually goes to sleep. Waking up is also not instantaneous, it takes 3-5s to wake up.
For comparison purposes: sleep and wakeup is literally instantaneous on a thinkpad, tested on a a much older thinkpad with an i3 processor and on another newer than the macbook, with an i5 processor
One glitch with sleep/wakeup cycles is that very rarely, the laptop refuses to go to sleep when you close the lid. After a reboot the laptop starts behaving normally again with regards to the sleeping functionality. I’ve seen this happen to my colleagues running OSx, although less often. The fact that this buggy behaviour is present on OSx and with the ubuntu package upgrade cycle ( some of which require a reboot anyway ) this glitch is not that annoying or noticeable.
Battery life
The battery life is not as good as it is on OSx, I can get ~70% of the battery life that you get on OSx.
Battery life for me is between 4 to 5 hours depending on the workload, where on OSx my colleagues can get a battery life of 7 hours maximum.
There are many microcontrollers/microchips on the macbook pro motherboard that the linux kernel doesn’t know how to put into sleep mode since it is missing the drivers to talk to them. Missing drivers for the mainboard microcontrollers is showed by the fact that if I sleep the laptop over the weekend when I come back and wake it up the battery is low as if something was draining the battery in sleep mode.
If drivers would exist then I’m sure battery life would be in the range of 95-99% of the battery life in OSx, there isn’t anything magic about battery life but using the right drivers and using applications that are not battery hogs.
TLP settings
In linux I’ve used tlp to manage battery power settings.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
|
External multiple monitors
The macbook pro has 2 thunderbolt/mini-DVI video outputs on the left and 1 HDMI video output on the right side.
The video output combinations that I’ve tried and work are:
- 2 external monitors via the thunderbolt/mini-DVI video output and the laptop panel.
- 1 external monitor via one of the thunderbolt/mini-DVI video output and the laptop panel.
- 1 external monitor or external smart-tv via the HDMI video output and the laptop panel.
All three described setups works in a plug-and-play fashion with the nvidia driver installed.
The single glitch with external single/multiple monitors is the fact that the laptop panel must set to the maximum resolution, 2880x1800.
See the video showcase for how external monitors work with Ubuntu on the macbook pro retina.
USB to Ethernet adapter
The USB to Ethernet adapter works flawlesly without any intervention. Just plug it and use it.
Laptop functions that don’t work and glitches
webcam
The iSight webcam that comes with this version of the macbook pro retina doesn’t work at all under linux.
There are various bugs on launchpad against Ubuntu, and on bugzilla.kernel.org against the linux kernel to get the iSight camera to work. [7] [8]
If anyone has got the iSight camera working let me know.
USB glitch
Extremely rarely the USB on the right side, next to the HDMI cable, throws this weird stacktrace and refuses to continue working.
The USB refuses to work after wakeup from sleep mode, throwing this error message in syslog. I have to reboot as a workaround for this glitch.
1 2 3 4 5 6 7 8 9 10 11 12 |
|
Since it happens extremely rarely this USB glitch is hardly noticeable, I have to reboot on a fairly regular basis for package updates anyway.
kded4/kdeinit4 crashes sometimes
Sometimes, when plugging and unplugging multiple monitors, many times in a day the kded4 / kdeinit4
daemon crashes.
The icons change in the system notification area when kded4
crashes and the external monitor doesn’t output anything when kded4
crashes. You can’t miss it :)
The workaround is very very simple for this bug, open a terminal and type ( as your user, sudo/root is not needed )
1
|
|
After typing this the icons change to their normal look and the video output starts outputting on the external monitor.
Other fixes and hacks that I employ
Scripted resolution scaling
Using a macbook pro retina with external monitors requires that I scale the resolution, to maximum, when plugging in the external monitors, and to 1920x1080 when using it the laptop by itself.
To achieve this fast scaling without opening the nvidia driver UI or the KDE display configuration UI I’ve found and altered a shell script to quickly change resolution by using xrandr. [13]
1 2 3 4 5 6 7 |
|
kworker hogging cpu
This issue is not caused by running linux on a macbook pro, it is related to the combination of ubuntu linux distro and kernel version. The same issue has happened to other people on different hardware.
This hasn’t happen in a long long time, but since I have some notes I’ll add it in this blog post for posterity.
In the beginnings, after the install in 2014, there were times when, sometimes, one kworker thread would hog a CPUs continuously.
To fix it you must find the kworker thread and disable it.
1 2 |
|
Follow these links to detailed articles on what and why kworker is hogging a cpu [10] [11] [12]
Touchpad / trackpad settings
To decrease the sensitivity of the trackpad in KDE, I’ve used some of the trackpad settings from unity.
To have the keyboard settings activate on KDE login I’ve created a ~/.xinitrc
file with this content:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
|
Video showcase
Stay tuned for part 2 of this blog post where I will have some youtube videos of how the laptop works with linux on it.
Comments
If you have any comments please use twitter DM, I’ve not enabled any comments on this blog yet.
Resources and inspiration
[1] - http://www.rodsbooks.com/refind/installing.html
[2] - http://glandium.org/blog/?p=2830
[3] - https://wiki.ubuntu.com/Ubiquity
[4] - https://blog.jessfraz.com/post/linux-on-mac/
[7] - https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1287984
[8] - https://bugzilla.kernel.org/show_bug.cgi?id=71131
[9] - https://medium.com/@PhilPlckthun/ubuntu-14-10-running-on-my-macbook-18991a697ae0
[10] - http://capocasa.net/crushing-the-kworker-uprising-or-how-to-fix-your-linux-lenovo-ideapad-y560p
[11] - https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1087010
[12] - http://askubuntu.com/questions/33640/kworker-what-is-it-and-why-is-it-hogging-so-much-cpu
[13] - https://gist.github.com/stefancocora/476bcaa51115cb28b174
[14] - https://support.apple.com/kb/SP690?locale=en_GB
[15] - https://help.ubuntu.com/community/MacBookPro11-3
[16] - http://ark.intel.com/products/76086/Intel-Core-i7-4850HQ-Processor-6M-Cache-up-to-3_50-GHz
[17] - https://unix.stackexchange.com/questions/148356/how-to-know-if-im-booting-using-uefi