Installing Ubuntu Linux 16.04 LTS on Macbook Air 7,2 (2015) and getting it to work properly

Apr 19, 2016  

Got this laptop last autumn as a replacement for my old travel pal 12” Asus EEE PC which became too old to rely on. Unfortunately it turned out that it had a hardware revision barely compatible with Linux, so after some googling around i gave up and ran OS X for half a year doing my work in a virtual machine. Yeah, it sucked, but using OS X sucked even worse.

After a while i checked it again and discovered that the new kernel 4.4.0 supports SSD installed in this machine and someone even launched Linux on it, but it required too much hacking; being a lazy person i patiently waited for the release of Ubuntu 16.04 LTS which should support this thing out of the box.

Apparently some days ago the lame piece of crap OS X drove me insane, so i finally decided to get rid of it even though the Ubuntu release i’ve been waiting for hasn’t been live yet, so i got its beta and spent the evening getting it to work. And i didn’t expect it to work that good!

The howto below is meant for users familiar with Linux. Probably these tips will work on other distros with minor changes, but keep in mind that kernel 4.4.0 or newer is required. All shell commands must be executed as root.

Installation

Create a UEFI bootable USB stick, use the amd64 desktop iso – netinstall doesn’t work as it lacks UEFI support which is required here. I didn’t look much into this part, the Ubuntu startup disk creator did the job just fine, but probably you can use Unetbootin or prepare the media manually.

Download the Ubuntu Server hd-media image from Ubuntu website or your local mirror and roll it out on a USB stick.

wget http://releases.ubuntu.com/xenial/ubuntu-16.04-server-amd64.img
sudo dd bs=1M if=ubuntu-16.04-server-amd64.img of=/dev/sdX

Plug the stick into your Air and (re)start it holding the alt key, the boot menu will appear in a while. Boot from the USB, the mac bootloader may call it something like “EFI disk”, simply select the other option from booting OS X. The installation is totally straightforward, the only thing is that a EFI partition is required on the disk. I created it the very first one (sda1) and set it 200Mb large, you can try making it even smaller. Do the rest of partitioning as you like, finish the installation and boot into your new Ubuntu.

Troubleshooting

Here comes the most interesting part.

The stock Ubuntu 16.04 LTS has numerous issues on Macbook Air: it occasionaly freezes, some functions don’t work, the laptop gets hot and consumes too much energy.
Luckily all of them can be resolved and in the end i got a smoothly runnnig system.

Wireless NIC

Usually wi-fi card works out of the box. Install the package bcmwl-kernel-source if you used some alternate installer.

Grub tweaks

Add these parameters to GRUB_CMDLINE_LINUX_DEFAULT in /etc/default/grub:

intel_idle.max_cstate=1 acpi_backlight=vendor

The first parameter fixes the sporadic freezing issue, the other one gets backlight controls to work. Run update-grub2 to generate the new configuration.

Function keys

By default the function keys control backlight and volume, so you must hold the fn key while pressing them to get their original functionality(F1-12). The fix for some old Ubuntu distros did the trick and made them work normally:

echo options hid_apple fnmode=2 | tee -a /etc/modprobe.d/hid_apple.conf
update-initramfs -u -k all

Webcam

While the Facetime HD webcam is not supported by Linux kernel, some smart guy has reverse-engineered it and provided a fully working driver for Linux. I didn’t bother building a nice package which is quite useless here, just did the following:

git clone https://github.com/patjak/bcwc_pcie.git
#download the OS X driver and extract the webcam firmware required for operation
cd bcwc_pcie/firmware/
make
make install
cd ..
#buld the driver
make
#ignore the OpenSSL errors, it should be ok
make install
#load the module on every boot, it won't do it automatically
sed -i '$imodprobe facetimehd' /etc/rc.local
#blacklist the bdc_pci module which causes problems, we don't need it here
echo "blacklist bdc_pci" > /etc/modprobe.d/blacklist.conf

The bad thing about these 3-rd party drivers is that they must be rebuilt upon every kernel upgrade.

Backlight control

Another weird problem is that after suspend you can get only discrete 0% or 100% brightness, but nothing in between. The same smart guy made a fix which suprisingly works on the new Air and Ubuntu. The copy-and-paste instructions are following:

git clone git://github.com/patjak/mba6x_bl
cd mba6x_bl
make
make install

Try rebooting your Ubuntu to see that things have become far better than they were. But the Macbook Air still needs to become cooler and less energy-hungry.

Power tuning

Install the tlp package, the default settings in /etc/default/tlp are fine. I tried playing around with them, but didn’t get any significant improvement. Apparently the laptop is much cooler without it. Install powertop instead, run “powertop –auto-tune” and check the improvement. Add it to /etc/rc.local so it will run on every startup.

And finally cooling

Install the package macfanctld. The default settings in /etc/macfanctl.conf will make your Air ice-cold like on OS X, but i prefer slowing the fan down and spending less power on cooling with the following config:

# Config file for macfanctl daemon
#
# Note: 0 < temp_X_floor < temp_X_ceiling
#       0 < fan_min < 6200       

fan_min: 1000

temp_avg_floor: 45
temp_avg_ceiling: 55

temp_TC0P_floor: 52
temp_TC0P_ceiling: 60

temp_TG0P_floor: 50
temp_TG0P_ceiling: 58

# Add sensors to be excluded here, separated by space, i.e.
# exclude: 1 7
# will disable reading of sensors temp1_input and temp7_input.

exclude: 18 19

# log_level values:
#   0: Startup / Exit logging only
#   1: Basic temp / fan logging
#   2: Log all sensors  

log_level: 0

Although the laptop becomes slightly warm, the CPU temperature never exceeds 70 degrees Celcius. Use the original config if you don’t like it.

Known issues

  • All power managers slowly react on power source change (AC/battery), it takes them about a minute to display the changed state.
  • HTML5 video on Webkit browsers (Chromium etc) has some artifacts in full screen. Tried to tune GPU acceleration settings but it didn’t help. Apparently it works great in Firefox, so i have no idea what causes it: the i915 video driver or webkit.

Bonus: smooth tearfree video playback

echo 'Section "Device"
	Identifier "Intel Graphics"
	Driver "intel"
	#Causes artifacts in Chromium HTML5 fullscreen video playback
	#Option "AccelMethod" "sna"
	#This seems to work better.
	Option "AccelMethod" "uxa"
	Option "TearFree" "true"
EndSection
' > /etc/X11/xorg.conf.d/10-intel.conf