Linux on Apple MacBook

Yep, I now own a MacBook .. Core 2 Duo one, and the primary reason I choose is that it’s a great hardware to run Linux (and it’s relatively cheaper). I did some research to convince myself that Linux run well on this notebook. I could tell you that ‘now’ is the right time to have Linux running on MacBook since all hardware components are now well supported. Even better, newer distribution such as Ubuntu 7.04, which officially use 2.6.20, supports most parts of MacBook out-of-the-box. :)

Installation

You may completely overwrite OSX by Linux, but I think it is still a good idea to leave OSX on MacBook at least to upgrade firmware. So, the set up will be dual boot (or even triple boot with .. err .. MS Windows XP/Vista). Next, installation steps.

In Mac OS X, make sure you update all firmware available. Upgrading software is also preferred.

Download the latest version of rEFIt and follow its instruction to install rEFIt in your OSX volume. rEFIt is an EFI boot menu and EFI GPT utilities.

Download Boot Camp from Apple’s web site, run and follow its instruction, burn a Windows Driver CD (you will need it), and make sure you partition the disk so that available space is large enough for Linux. My choice would be that largest possible for Linux, smallest possible for OSX. After partitioning the disk, reboot.

Alternatively to Boot Camp, you may use ‘diskutil’, a command line to partition your disk. Just make sure that you know exactly what you are doing.

Install Linux. I’d recommend Ubuntu 7.04 Feisty Fawn. Good news is that Feisty uses the Linux kernel version 2.6.20, which includes several supports for MacBook (and other Apple machines). So, just boot up the live CD. If it produces a kernel panic, try boot option of

lpj=8000000

for MacBook 2.0 GHz, or

lpj=7330000

for MacBook 1.8 GHz.

Double click “Install”, at disk partition step, choose “Manually edit partition”. Do NOT touch sda1 and sda2, they are EFI GPT and Mac OS X, respectively. Make sure your root partition is sda3 or sda4. The others can be sda5 and beyond.

Okay, a lecture, MacBook uses Extensible Firmware Interface (EFI) instead of BIOS, and EFI uses GUID Partition Table (GPT) to describe partitions. There is no notion of ‘extended’ or ‘logical’ partition in GPT, and you are no longer limit to 4 (primary+extended) partitions. GPT allows up to 128 partitions, but for backward compatible with legacy BIOS mode, bootable partition(s) should be one of the first 4 partitions. Don’t worry, Linux knows EFI for quite some time and GNU Parted is capable to handle GPT quite well.

After reboot, you should see Tux sitting in the beautiful menu of rEFIt. Choosing Tux will bring you to GRUB boot loader. If not, reboot to rEFIt menu and choose ‘Partition Tool’ to sync GPT and MBR. GRUB should work after sync.

Things that work out-of-the-box and without additional configurations are

  • Intel HD Audio (snd_intel_hda)
  • Marvell 88E8053 10/100/1000BASE-T Gigabit Ethernet (sky2)
  • USB Controller (uhci_hcd, ehci_hcd) .. noted that build-in keyboard, AppleTouch, Infrared, and iSight are hardwired to USB.
  • Bluetooth
  • Agere FireWire (ohci_1394)
  • Suspend-to-Disk (hibernate) and Suspend-to-RAM (suspend)
  • Special keys (brightness, volume, eject)

Display

MacBook is equipped with Intel GMA 950 Integrated Graphics processor and 1280×800 13.3-inch glossy TFT display. X.org’s i810 driver + i915 DRM work well for this. However, it is 1024×768. To get native resolution of 1280×800, ‘915resolution’ helps.

# aptitude install 915resolution

Restart X .. done.

Apple PowerBook Keyboard

Okay, keyboard works, but I don’t like default mode, i.e, Fn + F1 = F1. I just want F1 to be F1 and use Fn to get special keys (backlight, volume, etc.) To do so, append the following to /etc/modprobe.d/options

options hid pb_fnmode=2

PowerBook Keyboard mode can be controlled via /sys/module/hid/parameters/pb_fnmode. 1 = OS X-ish, 2 = PC-ish

AppleTouch

Again, it works via X.org’s synaptics touchpad driver, but the default config sucks (sorry ..). Additionally, only one button may not be enough. Synaptics driver is very powerful and flexible if you know how to deal with. Try

$ man synaptics

You’ll see all available options. My config for synaptics is the following:

Section "InputDevice"
        Identifier      "Synaptics Touchpad"
        Driver          "synaptics"
        Option          "SendCoreEvents"        "true"
        Option          "Device"                "/dev/psaux"
        Option          "Protocol"              "auto-dev"
        Option          "LeftEdge"              "20"
        Option          "RightEdge"             "1200"
        Option          "TopEdge"               "20"
        Option          "BottomEdge"            "370"
        Option          "FingerLow"             "15"
        Option          "FingerHigh"            "30"
        Option          "MinSpeed"              "0.79"
        Option          "MaxSpeed"              "0.88"
        Option          "AccelFactor"           "0.015"
        Option          "MaxTapTime"            "100"
        Option          "MaxTapMove"            "80"
        Option          "MaxDoubleTapTime"      "95"
        Option          "TapButton1"            "1"
        Option          "TapButton2"            "3"
        Option          "TapButton3"            "2"
        Option          "VertTwoFingerScroll"   "true"
        Option          "VertScrollDelta"       "10"
        Option          "HorizScrollDelta"      "10"
        Option          "ClickTime"             "100"
        Option          "SHMConfig"             "on"
EndSection

You may use ‘synclient‘ to fine tune edges, pressure, timing, etc.

AirPort Extreme

MacBook C2D uses relatively new WiFi chip from Atheros that supports up to 802.11n. You have two options here: ndiswrapper or madwifi. Ubuntu provides ndiswrapper and should works out-of-the-sbox. Anyway, newer versions of ndiswrapper fixed many issues occurred in MacBook. First, install additional packages

# aptitude install linux-headers-generic
# aptitude install build-essential

Then, download ndiswrapper, unpack, build, and install

$ tar xzf ndiswrapper-1.44.tar.gz
$ cd ndiswrapper-1.44
$ make
$ sudo make install

Next, you’ll need the proprietary driver written for MS Windows. It is in the disk burned during Boot Camp.

$ mkdir atheros-driver
$ cd atheros-driver
$ unrar x atherosxpinstaller.exe

Install the driver, and insert ndiswrapper module. The wlan0 interface will be up.

# ndiswrapper -i /path/to/atheros-driver/net5416.inf
# modprobe ndiswrapper

If things go well, you may want to append the following in /etc/modules

ndiswrapper

Now, ndiswrapper will be inserted automatically during boot up your system.

For madwifi, you need snapshot version of 0.9.30.13 or newer. Download, unpack, build, and install.

$ tar xzf madwifi-hal-0.9.30.13-current.tar.gz
$ cd madwifi-hal-0.9.30.13-r2351-20070519
$ make
$ sudo make install

Just replace existing files if there exist. Now, it’s ready to use

# modprobe ath_pci

The wireless LAN device wifi0 should be ready, and the ath0 interface should also be created automatically. Since madwifi is multiband driver, it can create multiple network interfaces, running different mode, from a single wireless device. Although ndiswrapper 1.44 is more stable, I’d prefer madwifi mainly because it is open source, and it supports monitor mode.

iSight

This does not work out-of-the-box. You’ll need a patched version of uvcvideo 0.1.0-e. Download, unpack, make, and install

$ tar xzf linux-uvc-0.1.0-e.tar.gz
$ cd linux-uvc-0.1.0-e
$ make
$ sudo make install

The module will be installed in /lib/modules/<kernel-version>/usb/media, and should be moved to /lib/modules/<kernel-version>/misc/. A utility named ‘extract’, provided with uvcvideo, to load Mac OS X firmware of iSight.

# mount /dev/sda2 /mnt
# extract /mnt/System/Library/Extensions/IOUSBFamily.kext/Contents/PlugIns/AppleUSBVideoSupport.kext/Contents/MacOS/AppleUSBVideoSupport
# modprobe uvcvideo

Alternatively, download isight-extract utility. This utility will extract iSight firmware from AppleUSBVideoSupport.

$ cd isight_extract
$ make
$ extract /mnt/System/Library/Extensions/IOUSBFamily.kext/Contents/PlugIns/AppleUSBVideoSupport.kext/Contents/MacOS/AppleUSBVideoSupport

The file named ‘isight.fw’ will be created in the current directory. Put this file to /lib/firmware/<kernel-version> iSight firmware should be loaded automatically when uvcvideo is inserted. Try ekiga with V4L2 driver to test iSight camera.

iRemote

To use iRemote, install inputlirc

# aptitude install inputlirc

Now, iRemote will be able to control volume :D .. Additionally, install lirc and lirc-x and get more fun

# aptitude install lirc lirc-x

The two packages provides many utilities, including ircat, irexec, irxevent. Consult manpages for more information. Also, this is <a href=files/lircrc>my ~/.lircrc</a> to control a number of applications via iRemote.

Not test yet

  • FireWire

Seem to work though.