Arch Linux on a Macbook Air 4,2

Installing linux on a laptop, especially an Apple laptop, can be a
frustrating experience. While the initial setup still isn't trivial,
a pure EFI-boot copy of Arch Linux is by far the most straightforward install
I've done. No mucking around with BIOS/MBR, experimental Xorg drivers,
unstable binary-blob Wifi drivers, or complex suspend/resume scripts is
required!

Installation Overview (tl;dr)

This describes an Arch Linux install, not Ubuntu, and doesn't use the typical
BIOS compatibility mode suggested in most linux-on-Macbook guides. As such, you
shouldn't expect a point-and-click install.

This document is a work-in-progress, but will get you around the few small issues
that are specific to this laptop.

Partitioning and Installation

This section of the install doesn't deviate greatly from the usual Arch Linux
install process. The primary differences are the need for manual partition
creation, and manual installation of the GRUB2 bootloader to the EFI system
partition.

Boot from the USB stick

This is the easy part: just hold down the option key before the apple logo
appears on the gray firmware boot screen. Using arrow keys (or the mouse),
choose the USB stick which will be mis-labeled "Windows".

GRUB will start up; choose the normal kernel.

Partition hard drive using cgdisk

Before doing anything in the Arch setup script, you'll need to create one or
more partitions manually using cgdisk1. cgdisk manages a
GPT parititon table, rather than the traditional MBR-style partitions.

I created one small 100MB partition for /boot, leaving the remainder of the
free space for my root / partition. I didn't make a swap partition, but
that's up to you. I've yet to use more than 1GB of ram in my usage so far!

Install Arch

Proceed through the normal Arch setup menus and dialogs as you would on any
other machine. Once you reach the partitioning section, though, be careful!
Don't let Arch do any partitioning of its own; instead, just move on and
choose the partitions that you've already created and tell the script where to
mount them.

Install GRUB2 to EFI System Partition

When you get to the bootloader question, make sure to choose grub2. The
script will fail to fully install it, complaining about the EFI system
partition.

Note that the EFI/boot/bootx64.efi path is very important. The OSX EFI
firmware is hardcoded to look for alternative EFI bootloaders there on 64-bit
machines.

Reboot into the new system

Once you've finished up the Arch setup script and GRUB bootloader
installation, you should reboot into the new system. Hold option again to
get the list of boot options, and choose "EFI Boot". You should get the
familiar GRUB menu; choose the fallback kernel option, since the current
(as-of-this-writing) Arch-distributed kernel has issues with the keyboard when
not in HID mode.

You'll get a bit of garbage on the right and bottom edges of your screen. The
i915 driver fails to detect the native resolution of the internal LCD panel
properly, but it's still usable.

Install a newer kernel

To fix the keyboard issues, you'll need at least version 3.1.1 of the Linux
kernel. This version includes a number of fixes for the MacbookAir4,x series,
including the keyboard driver.

To fix the display issues, you'll need to patch the i915 driver. The patch
includes a hardcoded set of timings, overriding what the driver (improperly)
detects.

Patch the i915 driver

You'll need to patch the i915 driver with the display timings appropriate
for your machine. There are, at this time, five known panels in the Macbook
Air 4,1 and 4,2 models. There is an Ubuntu-specific script that contains all
of the modelines, but requires apt to install the get-edid utility which
will identify your display.

If you don't already know which panel your machine has, you have two choices.
Either install get-edid yourself, and follow along with the fix-i915.sh
script by hand, or run the following in OSX: