[133038 views]

[]

[toggle ads]

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 makes it a little difficult to get started with Linux.

First I booted into OS-X. Downloaded and installed rEFIt. rEFIt is an EFI extension. 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. Today I'd go for amd64.

Now insert the Gentoo boot CD and reboot. rEFIt will come up and let you choose to boot from the CD. In the Gentoo live system 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 as ReiserFS is basically dead today.

Portage settings

I am using this make.profile: /usr/portage/profiles/default-linux/x86/2006.1/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 kvm ladspa lame latex lcms lensfun
     libvisual lm_sensors logitech-mouse logrotate maildir                    
     mdnsresponder-compat mmx mng mozdevelop mozsvg mp4 mpeg2 mplayer msn     
     multicall musicbrainz 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 vcd vim-syntax visualization wifi wmp wps x264 xcb     
     xcomposite xine xinerama xosd xscreensaver xvid zeroconf zip -3dnow      
     -3dnowext -acl -arts -eds -esd -fortran -gnome -isdnlog -kerberos        
     -mudflap -oss -pppd -qemu -qt3 -semantic-desktop -spell"
INPUT_DEVICES="evdev keyboard mouse synaptics"
VIDEO_CARDS="fglrx radeon vesa fbdev"
ALSA_CARDS="hda-intel"
LINGUAS="en de"     
  

Note: I have disabled arts, the KDE sound daemon as the important apps can use ALSA directly.

With GCC 4.3 in 32 bit mode:
  CHOST="i686-pc-linux-gnu"
  CFLAGS="-O2 -march=core2 -fomit-frame-pointer -pipe"
  
With GCC 4.3 in 64 bit mode:
  CHOST="x86_64-pc-linux-gnu"
  CFLAGS="-O2 -march=core2 -fomit-frame-pointer -pipe"
  
With GCC 4.1 in 32 bit mode:
  CHOST="i686-pc-linux-gnu"
  CFLAGS="-O2 -march=prescott -fomit-frame-pointer -pipe"
  
With GCC 4.1 in 64 bit mode:
  CHOST="x86_64-pc-linux-gnu"
  CFLAGS="-O2 -march=nocona -fomit-frame-pointer -pipe"
  

Kernel

Some important config options:

2.6.32

I got a 2.6.32 kernel out of git. Here is my kernel config. I have converted my ext3 partition to ext4 now.

2.6.31

I got a 2.6.31 kernel out of git. Here is my kernel config. Regression: Might Mouse was initially broken but works again as of 2.6.31.2. Note that the horizontal scrolling direction of the Mighty Mouse is now correct, and you can remove any xmodmap pointer tweaks from your X system.

2.6.30

I got a 2.6.30 kernel out of git. I did not apply any patches. Here is my kernel config. ath9k works now - no more ndiswrapper. The ALSA mixer controls have once again changed names. Make sure to adapt /etc/pommed.conf accordingly.

2.6.29

I got a 2.6.29 kernel out of git. I did not apply any patches. Here is my kernel config. ath9k works now - no more ndiswrapper. Use pommed-1.25.

2.6.28

I got a 2.6.28 kernel out of git. I did not apply any patches. Here is my kernel config. ath9k sort of works, but it initializes the WLAN chip incorrectly so that the signal is much too weak. So still using ndiswrapper-1.53. Use pommed-1.25.

2.6.27

I got a 2.6.27 kernel out of git. I did not apply any patches. Here is my kernel config. ath9k sort of works, but it initializes the WLAN chip incorrectly so that the signal is much too weak. So still using ndiswrapper.

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.32
root (hd0,2)
kernel /boot/linux-2.6.21 resume=/dev/sda4

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

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 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.

udev rules

To create semantic device nodes for some common hardware I put the following udev rules into /etc/udev/rules.d/10-local.rules (see udev guide):

# Internal touchpad
SUBSYSTEMS=="usb", DRIVERS=="appletouch", ATTRS{interface}=="Touchpad", SYMLINK+="input/touchpad"

# Mighty Mouse in report mode (kernel with bluez patches)
SUBSYSTEMS=="input", ATTRS{name}=="Apple Computer, Inc. Mighty Mouse", SYMLINK+="input/btmouse"

# iSight
SUBSYSTEM=="video4linux", DRIVERS=="usb", ATTRS{product}=="Built-in iSight", 
 ATTRS{manufacturer}=="Micron", SYMLINK+="v4l/isight"

# DigiCam
SUBSYSTEMS=="usb", DRIVERS=="usb", ATTRS{product}=="Sony DSC", ATTRS{manufacturer}=="Sony",
 SYMLINK+="cam%e", GROUP="plugdev"

# iPOD - get the right partition with start attribute
SUBSYSTEM=="block", KERNEL=="sd??", ATTR{start}=="65600", ATTRS{model}=="iPod            ",
 ATTRS{vendor}=="Apple   ", SYMLINK+="ipod", GROUP="plugdev"
  

I find the following script udevdevice handy to extract possible rules for an existing device:

#!/bin/sh
# shows udev rules for a device
# syntax: udevdevice /dev/mydevice
udevinfo -a -p $(udevinfo -q path -n $1)
  

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

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.

Kernel mode setting (KMS)

As of this writing xf86-video-ati-6.12.4 supports KMS (through TTM/GEM). If you compile your kernel with KMS support for the radeon you get a working framebuffer console and fast console/X switching. However X is slow because of disabled DRI. This will be addressed in later driver releases probably. So for the moment this is still experimental and not a recommended feature for production use.

Here is my xorg.conf for xorg-server 1.5 and later and 1.3. You can use HAL with xorg-1.5 which moves the input device configuration to an FDI policy file such as /etc/hal/fdi/policy/50-x11.fdi completely. 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.

The keyboard in X needs a little tweaking with xmodmap. For xorg-server-1.5 with HAL I am using this Xmodmap. For xorg-server-1.3 I was using this Xmodmap, which is different because HAL uses the evdev xorg driver for the keyboard, which has different keycodes and behaviour. Whichever you use, 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 and asound.names 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.

I have disabled ARTS (the KDE sound daemon) by USE flag. To still get sound output from KDE applications that do not support ARTS directly, you can set an external player in Control Center > Sound & Multimedia > System Notifications > Player Settings. A good choice is either /usr/bin/play from sox, or a small shellscript that pipes the sound file through ALSA's /usr/bin/aplay with the right parameters.

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.

The udev rules in /etc/udev/rules.d/isight.rules will load the firmware. But you will have to (bug) specify the bus and device number for ift-load like so:

ACTION=="add", SYSFS{idVendor}=="05ac", SYSFS{idProduct}=="8300", 
   RUN+="/usr/lib/udev/ift-load -b 001 -d 003 --firmware /lib/firmware/isight.fw"  
  

The bus and device numbers can be found from the output of lsusb. After the firmware has been loaded the USB product id changes to 8501 and the device number changes to 007 on my system.

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 mplayer as of version 1.0_rc2. The mplayer options in /etc/mplayer/mplayer.conf or your ~/.mplayer/config:

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 must be patched to support the UYVY format. Then it works:

luvcview -f uyvy

Pluggable devices (HAL)

If you want memory sticks to work without manually messing with fstab, mountpoints and udev, just emerge dbus hal; rc-update add hal default nonetwork and make sure the user is in the plugdev group. HAL also handles auto-play of CDs and DVDs. With xorg-server-1.5 HAL can also handle registration and config of all input devices for you.

Special keys

The powerbook 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.

It should also be possible to use HAL to map these keys to some X actions.

Remote control

Use LIRC.

Suspend to RAM

As mentioned above make sure the kernel has CONFIG_HOTPLUG_CPU enabled! Suspend may work in X as long as you change the terminal to a text console (chvt). Depends on the ATI driver version. I am unloading the WLAN driver and the uvcvideo module. Wakeup with lid or powerbutton. The video mode ist restored with the vbetool. All that I have put into a little suspend script which is called by the acpi-power script.

With 2.6.23 and 2.6.24 suspend does not work in X anymore :-(

Save batteries with acpid

I am routing some ACPI events to a custom acpi-power script that is configured with /etc/acpi/power.conf.

mithril events # pwd
/etc/acpi/events
mithril events # ls
ac  bat  lid
mithril events # cat ac
event=ac_adapter .*
action=/usr/local/bin/acpi-power
mithril events # cat bat
event=battery .*
action=/usr/local/bin/acpi-power
mithril events # cat lid
event=button/lid .+
action=/usr/local/bin/acpi-power
  

The script takes care of dimming the backlight, throttling the CPUs, disabling the second core and suspending to RAM.

Useless screenshot

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

Desktop screenshot