[89351 views]

[]

Gentoo Linux on Apple MacBook Pro Core2Duo

This is a short guide for the experienced Linux user. It explains how I installed Gentoo Linux on my Apple MacBook Pro. I chose to run Linux on this laptop because it works best for my needs. Neither OS-X nor Windows are an option for me. Please note: This is a matter of taste. That it works for me doesn't necessarily mean that it works for you.

This page is gradually updated as new drivers / kernels are available. There is a page in the Gentoo Wiki, too. But I find the information there very chaotic, incomplete and sometimes wrong.

Hardware features

I bought the second edition of the MacBook Pro in December 2006 because of its excellent hardware and unsurpassed design. dmidecode, lspci, lsusb, /proc/bus/input/devices

My MacBook Pro

OS-X, Bootcamp, rEFIt, and booting the Gentoo LiveCD

As you have probably heard, Intel Macs don't come with a PC BIOS. They have an alternative boot firmware called EFI. In contrast to BIOS, a portion of EFI is installed on a partition on the harddrive. This makes it extensible. It also provides the BIOS calls for Linux. Decent EFI support is in process of being implemented into Linux since kernel 3.1 onwards only. Some drivers still rely on BIOS calls (graphics!). So currently don't bother with a pure EFI installation. It probably won't work.

First I booted into OS-X. Downloaded and installed rEFIt. rEFIt is nothing more than an EFI extension/module. It shows a boot menu that allows to boot other operating systems installed on other partitions or LiveCDs. It does no harm to your system. If you want to directly boot into OS-X without rEFIt, just select the OS-X partition as the boot disk in OS-X. As I never use OS-X I told rEFIt to boot Linux by default, by setting the legacyfirst option in /efi/refit/refit.conf.

Downloaded and installed BootCamp. BootCamp helps with resizing your OS-X partition to make room for the Linux partitions. Apart from that it does nothing: The BIOS emulation is part of your Mac's firmware.

Downloaded and burnt the Gentoo Live CD for x86 i686 (32 bit). At that time I was relying on some binary drivers, so I chose the 32 bit version. Who knows if the binary crap (why binary drivers are crap) would ever work in 64 bit mode. In December 2011 I reinstalled using the x86_64 Gentoo architecture. Today 64bit code is often more tested and more stable than 32bit code. I even have the impression that the 64bit Gentoo is faster filesystem wise.

As for boot CDs: the Gentoo minimal boot CD is not the best. It's kernel has no support for the WiFi card. I recommend the SystemRescueCD to install Gentoo or do any Gentoo maintenance work. It's kernel works with the MacBook Pro hardware.

Now, insert the boot CD and reboot. rEFIt will come up and let you choose to boot from the CD. In the live CD use fdisk to partition your hard drive. I deleted the Windows partition that BootCamp had created. Then I created a Linux partition and a Linux Swap partition. Rebooted and let rEFIt sync the EFI partition table (GPT). Used fdisk to fix the partition types again (83 and 82). The existing EFI partition is actually empty, but don't remove it!

I chose ext4 for the filesystem because it's still one of the fastest today (look at various Phoronix benchmarks on non-SSD disks). A very good alternative in terms of speed and reliability is XFS.

Portage settings

I am using this make.profile: /usr/portage/profiles/default/linux/amd64/10.0/desktop. plus these USE flags and config:

USE="X509 a52 aac aio amr amrnb amrr amrwb apache2 asf audacious avahi
     bash-completion bluetooth bzip2 cdda cddb cdparanoia cleartype contrast
     css dga dirac divx dmi dnotify dts dvdnav emerald enblend exif exscalibar
     ffmpeg fftw flac ftp gd gimp glibc-omitfp gmedia gs gtk2 hdri hfs
     hotpixels hpn html ibam idn ieee1394 imagemagick inotify ipod irda isight
     jabber jack java javascript jce jpeg2k kde kvm ladspa lame laptop latex
     lcms lensfun libvisual lm_sensors logitech-mouse logrotate maildir
     mdnsresponder-compat mmx mng moonlight mozdevelop mozsvg mp4 mpeg2
     mplayer msn multicall mysql network network-cron no-old-linux no-suexec
     nodrm nsplugin pcap pertty portaudio postscript ppds rdesktop rle sasl
     scanner sift slp smp sms speex spf sse sse2 sse3 ssse3 subversion tex
     theora thunderbird timezone tk type1 udev urandom usb userlocales
     utempter v4l v4l2 vaapi vcd vim-syntax visualization wifi win32codecs wmp
     wps x264 xcb xcomposite xine xinerama xosd xscreensaver xvid zeroconf zip
     -3dnow -3dnowext -abiword -acl -arts -cracklib -eds -esd -fortran -gnome
     -isdnlog -kerberos -lightning -mudflap -oss -pppd -qemu -semantic-desktop
     -spell"
INPUT_DEVICES="evdev keyboard mouse synaptics"
VIDEO_CARDS="fglrx radeon vesa fbdev"
ALSA_CARDS="hda-intel"
LINGUAS="en de"     
  
With GCC 4.5 in 32 bit mode:
  CHOST="i686-pc-linux-gnu"
  CFLAGS="-O2 -march=core2 -fomit-frame-pointer -pipe"
  
With GCC 4.5 in 64 bit mode:
  CHOST="x86_64-pc-linux-gnu"
  CFLAGS="-O2 -march=core2 -fomit-frame-pointer -pipe"
  
Of course you can always use -march=native instead.

Kernel

Some important config options:

3.3

I got a 3.3 kernel out of git. 3.3.1 breaks WIFI, please patch -R -p1 < commit-db6a6a7. Here is my kernel config for x86_64

3.2

I got a 3.2 kernel out of git. Here is my kernel config for x86_64

3.1

I got a 3.1 kernel out of git. Here is my kernel config for x86 and x86_64.

older kernels below are all 32 bit

3.0

I got a 3.0 kernel out of git. Here is my kernel config.

2.6.39

I got a 2.6.39 kernel out of git. Here is my kernel config.

2.6.38

I got a 2.6.38 kernel out of git. Here is my kernel config.

2.6.37

I got a 2.6.37 kernel out of git. Here is my kernel config.

2.6.36

I got a 2.6.36 kernel out of git. Here is my kernel config.

2.6.35

Sorry, I had not much fun with .35. So leaving this one out.

2.6.34

I got a 2.6.34 kernel out of git. Here is my kernel config.

I have converted my ext3 partition to ext4 now.

Grub

I am using the Grub boot manager to boot the kernel. The /boot/grub/grub.conf contains:

timeout 3

default 0
fallback 0

# Prod
title Linux-2.6.33
root (hd0,2)
kernel /boot/linux-2.6.33 resume=/dev/sda4 root=/dev/sda3 rootfstype=ext4 radeon.dynclks=1

# Testing
title Linux-2.6.34
root (hd0,2)
kernel /boot/linux-2.6.34
  

The problem that most of the time the keyboard is dead when Grub comes up is resolved by the MacBook Pro EFI Firmware Update 1.4 from 09/27/2007.

Groups

I found it useful (not to say necessary) to assign the user to the following groups:

Keyboard layout

I have set my system to UTF-8, using a en_US.utf8 locale (eselect locale) and I am using a UTF-8 keymap (not a Latin-1 one!): I have modified the keymap a little. The more keys you get right in the keymap file the less work you have in X, as it inherits these settings! I started off with a keymap file created with dumpkeys, tweaked it and put it to /etc/default.kmap. This file is then referenced from /etc/conf.d/keymaps in the KEYMAP variable. For X see below!

The Apple keys work as Alt-Gr. So it provides access to the 'at' sign as Apple-2, the # sign as Apple-3, square brackets [] as Apple-ü and Apple-", braces {} as Apple-ä and Apple-$, pipe | as Apple-1 (or Apple-7), backslash \ as Apple-<. Additionally the Apple-E is the Euro € and Apple-G the 'at' like on a Mac. I have made the keypad Enter key (between Right Apple and Cursor Left) a 'Delete' key. With Shift it's 'Insert'. You also get 'Delete' with Fn-Backspace (Kernel does that).

By default the Kernel sets the Fn key to always enabled (OS-X behaviour). If you don't like that turn it off with the kernel parameter usbhid.pb_fnmode=2 in Grub or change it at runtime through /sys/module/usbhid/parameters/pb_fnmode.

Wifi (AirPort)

Since kernel 2.6.29 I have been happily using the ath9k driver.

For WPA support I am using wpa_supplicant.

/etc/conf.d/net
modules=( "wpa_supplicant" )
  config_wlan0=( "dhcp" )
  dhcpcd_wlan0="-L -t 20 -E"
  wpa_supplicant_wlan0="-Dnl80211"
  

Before that the MadWifi project did not support the new Atheros chipset AR5418 yet. That means you have to use a bloody Windows driver with ndiswrapper. I have found the Lenovo (IBM) driver to work best (the D-Link caused a kernel panic in some networks). To obtain the driver (deep linking impossible):

  1. go to Lenovo support site
  2. enter "2007VEH" as the product number (it's a ThinkPad T60)
  3. click on "Software and Device Drivers"
  4. click "Networking-Wireless"
  5. download under "ThinkPad 802.11abgn wireless LAN" "Windows 2000, XP"
  6. Save the driver to disk (exe file)
  7. Use cabextract (emerge cabextract) to unpack the archive
  8. Install the driver using ndiswrapper: ndiswrapper -i WIN2K_XP/NET5416.INF

Tethering with the HTC Hero

Tethering is extremely simple with the Hero. Just make sure to enable "RNDIS and ActiceSync" device support in the kernel (USB_NET_RNDIS_HOST). In 2.6.33 that option is well hidden below:

After plugging in the phone and enabling Wireless Controls > Mobile Network Sharing on the phone, you get a new ethernet device (usb0 here). Use it like any other regular ethernet device.

# lsusb  -t   
/:  Bus 01.Port 1: Dev 1, Class=root_hub, Driver=ehci_hcd/8p, 480M                          
    |__ Port 3: Dev 9, If 0, Class=comm., Driver=rndis_host, 480M                           
    |__ Port 3: Dev 9, If 1, Class=data, Driver=rndis_host, 480M
    
# ifconfig -a usb0
    usb0      Link encap:Ethernet  HWaddr 12:34:56:78:90:AB  
          BROADCAST MULTICAST  MTU:1500  Metric:1        
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000                        
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

xorg and 3D

The MacBook has a Radeon Mobility X1600 M56P, which is a RV5xx chip also known as RV515 or RV516. So make sure to set these variables in your /etc/make.conf:

INPUT_DEVICES="evdev keyboard mouse synaptics"
VIDEO_CARDS="fglrx radeon vesa fbdev"

You have the choice between two different graphics drivers for Xorg:

ATI drivers

AMD's (former ATI) proprietary closed source driver fglrx from the ati-drivers ebuild: offers 3D acceleration, has some bugs, breaks often with new kernel versions, closed source

Some versions of the ati-drivers are really buggy (break Google Earth and suspend to RAM). I have used ati-drivers-8.39.4 for kernels before 2.6.24, and ati-drivers-8.452 and ati-drivers-8.542 since. But now I have switched to the xorg drivers.

Xorg drivers

The Xorg xf86-video-ati (radeon) driver offers good support. To get propert 3D acceleration this driver needs DRI. DRI is provided by r300_dri.so which comes with MESA 7.2 onwards.

Kernel mode setting (KMS)

KMS works very well with xf86-video-ati-6.13.1 and kernel 2.6.36. You get a working framebuffer console and fast console/X switching. You can also save your battery with radeon.dynclks=1 on the kernel command line. You can always fall back to old user modesetting (UMS) by specifying nomodeset on the kernel commandline. If X crashes on start, try removing your xorg.conf.

Here is my xorg.conf: xorg.conf. Note that I don't specify any mode lines as xorg can perfectly figure out the best mode with no help. To get nice anti-aliased fonts see the this Wiki page. For Keyboard and Touchpad config there are files for /etc/X11/xorg.conf.d: 10-keyboard.conf, 11-touchpad.conf

The keyboard in X needs a little tweaking with xmodmap. For xorg-server I am using this Xmodmap. Just save it as the global /etc/Xmodmap or a local ~/.Xmodmap.

Touchpad

The touchpad can operate either through the appletouch driver (which is the default) or through the USB HID driver. Which one is used is determined by a HID_QUIRK_IGNORE_MOUSE in the blacklist entry in /drivers/usb/input/hid-core.c:

	{ USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ANSI, HID_QUIRK_POWERBOOK_HAS_FN | HID_QUIRK_IGNORE_MOUSE },
	{ USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ISO, HID_QUIRK_POWERBOOK_HAS_FN | HID_QUIRK_IGNORE_MOUSE | HID_QUIRK_POWERBOOK_ISO_KEYBOARD},
	{ USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_JIS, HID_QUIRK_POWERBOOK_HAS_FN | HID_QUIRK_IGNORE_MOUSE },
.

The HID driver of course does not provide extended features like tapping, multifinger, scrolling etc. The appletouch driver does (together with the synaptics xorg input driver). You may also want to run syndaemon -i 1 -t -d from an Autostart script in X.

Mighty Mouse

I have an optical Bluetooth Mighty Mouse with a scroll ball (Vendor/Product: 05ac:030c). It works out of the box with the help of the bluez-utils and kdebluetooth. Please note that with bluez-utils-3.10 the hidd is gone and the following is no longer necessary. In fact the job of connecting/pairing the device is now performed by kdebluetooth.
In /etc/conf.d/bluetooth make sure to enable the HID daemon and to specify the MAC address of the mouse (use hcitool and hcidump).

  
# Start hidd (allowed values are "true" and "false")
HIDD_ENABLE=true

# hard code MAC address of mouse
HIDD_OPTIONS="--connect aa:bb:cc:dd:ee:ff"

From 2.6.19 on the HID layer is decoupled from USB and can be used by the bluetooth subsystem. The full HID support is available as of 2.6.21. For earlier kernels there is a patch.

Sound

The MacBook Pro has on-board Intel HDA STAC 922x sound. Audio playback and recording works fine with internal speakers and headphones. The mixer controls seem to be changing with every kernel version (very annoying). Be careful when switching between kernels, as ALSA keeps an asound.state file with configured devices in /var/lib/alsa (or /etc on other distros) which may be read by alsactl at boot time. If your mixer does not show the PCM device, or pommed's sound support doesn't work you may need to delete those after changing the kernel. In Gentoo also check the settings in /etc/conf.d/alsasound. I said yes to save and restore sound levels.

More information about the STAC 922x and ALSA can be found there.

The card has no MIDI synthesizer, so to play MIDI files you need timidity++. If you want to get into real audio development, your best start is qjackctl and pam config for realtime priority. Also make sure to set options snd-hda-intel position_fix=1 in /etc/modules.d/alsa and update-modules, to eliminate xruns in jackd!

iSight camera

The iSight is now fully supported by the linux-uvc kernel module and works fine in Kopete and Skype. The module is included in the vanilla kernel 2.6.26. For earlier kernels it can be obtained separately: emerge linux-uvc. Use version 0.1.0_pre157 which also requires the isight-firmware-tools. On OS-X the firmware is found under System/Library/Extensions/IOUSBFamily.kext/Contents/PlugIns/AppleUSBVideoSupport.kext/Contents/MacOS/AppleUSBVideoSupport. Copy it to /lib/firmware and run ift-extract --apple-driver AppleUSBVideoSupport to extract it to /lib/firmware/isight.fw.

After modprobe uvcvideo a v4l device is created.

You can use GStreamer to play and record video (emerge gstreamer gst-plugins-base gst-plugins-good gst-plugins-v4l2 gst-plugins-ffmpeg).

# view only (some magic)
gst-launch-0.10 v4l2src ! autovideosink

# view only (no magic)
gst-launch-0.10 -v v4l2src ! videorate ! video/x-raw-yuv,format=\(fourcc\)UYVY,width=320,height=240 ! \
  ffmpegcolorspace ! xvimagesink

# record and preview
gst-launch-0.10 -v v4l2src ! videorate ! video/x-raw-yuv,format=\(fourcc\)UYVY,width=320,height=240 ! \
 ffmpegcolorspace ! tee name=preview ! xvimagesink sync=false preview. ! ffenc_msmpeg4 ! queue ! \
 avimux ! filesink location=1.avi
 
# record with sound from microphone and preview
gst-launch-0.10 v4l2src ! videorate ! video/x-raw-yuv,format=\(fourcc\)UYVY,width=320,height=240 ! \
 ffmpegcolorspace ! tee name=preview ! xvimagesink sync=false preview. ! ffenc_msmpeg4 ! queue ! \
 avimux name=mux alsasrc ! queue ! audioconvert ! ffenc_ac3 ! mux. mux. ! filesink location=1.avi

Or use mplayer2: mplayer2 tv:// or more complete options:

tv=driver=v4l2:input=1:width=320:height=240:device=/dev/v4l/isight:outfmt=uyvy:fps=24
  

Mplayer is then started with: mplayer tv:// -vf mirror,screenshot To save a still image (photo booth) press s.

Recording to file is also possible with mencoder (but you don't see what you're recording). I have defined a profile in ~/.mplayer/mencoder.conf:

[webcam]
o=1.mpg
oac=pcm=yes
ovc=lavc=yes
lavcopts=vcodec=mjpeg
tv=driver=v4l2:input=0:width=320:height=240:device=/dev/v4l/isight:outfmt=uyvy:fps=24
vf=mirror
nosound=1

Mencoder is then started with: mencoder -profile webcam tv://
But it crashes after a while with floating point exception.

ffmpeg works (but you don't see what you're recording):

  ffmpeg -f video4linux2 -s qvga -i /dev/v4l/isight 1.mpg
  

luvcview has been patched to support the UYVY format.

luvcview -f uyvy

Pluggable devices

Just make sure the user is in the plugdev group. Forget HAL: it is no longer necessary and deprecarted.

Special keys

The macbook has a couple of special keys to control the LCD brightness, speaker volume, CD eject and keyboard backlight. The pommed daemon handles them nicely: emerge pommed and modify /etc/pommed.conf to your liking. Then run gpomme -c to setup the optional GUI and add gpomme to your X login scripts. Make sure the kernel is compiled with INPUT_UINPUT.

In KDE the backlight and volume are handeled by global shortcuts by default already. So you can safely disable support for that in pommed. All you need pommed for is keyboard backlight these days.

Remote control

Use LIRC.

Suspend to RAM

Works well on recent kernels. Just use KDE's power management.

Useless screenshot

Here is the obligatory completely atypical and useless screenshot. Click for the full-size image (1680x1050, 1MB).

Desktop screenshot