Apple MacBook

From Gentoo Linux Wiki

Jump to: navigation, search
This article is part of the Hardware series.
Laptops TV Tuner Cards Wireless Servers Storage Other Hardware Motherboards Related
Split-arrows.gif It has been suggested that this article be split into multiple articles accessible from a disambiguation or index page.   (Discuss)

Contents

[edit] Introduction

This document serves the Apple MacBook in both hardware support and installation of Gentoo GNU/Linux. Any questions not answered here can be discussed on the MacBook thread in the official Gentoo Forums or visit us in #mactel-linux on irc.oftc.net. Also check out the Links section of this page for some additional resources. MacPro users should use the MacPro wiki for more detailed information.

Note: The MacBook wiki has information provided by good number of seasoned Linux users, please add or subtract information only if it is known. Unsure topics or details should be discussed on the Talk page.

Models Included

  • MacBook (First Generation(05/2006-11/2006) - Core Duo 1.83/2.0GHz, Intel GMA 950, Atheros 11g)
  • MacBook (Second Generation(11/2006-05/2007) - Core 2 Duo 1.83/2.0GHz, Intel GMA 950, Atheros 11n(need firmware upgrade))
  • MacBook (Third Generation(05/2007-11/2007) - Core 2 Duo 2.0/2.16GHz (Merom), Intel GMA 950, Atheros 11n)(Almost same as 2nd gen.)
  • MacBook (Fourth Generation(11/2007-02/2008) - Core 2 Duo 2.0/2.2GHz (Santa Rosa), Intel GMA X3100, Braodcom BCM43xx)
  • MacBook (Fifth Generation(02/2008-?) - Core 2 Duo 2.1/2.4GHz (Penryn), Intel GMA X3100, Broadcom BCM43xx 02/2008~)
  • Mac Mini (First Generation - Core Duo, Atheros 11g)
  • Mac Mini (Second Generation - Core2 Duo, Atheros 11n)
  • MacBook Pro (First Generation - Core Duo, Atheros 11g, ATI Graphics Card)
  • MacBook Pro (Second Generation - Core2 Duo (Santa Rosa, Atheros 11n, nVidia Graphic Card)*
*MacBooks Pro's also have other differences like additional connectors.

[edit] Subpages

[edit] Basic Installation

The MacBook marked the introduction of a processor shift by Apple from Motorola/IBM's PowerPC family to Intel x86 family. While the move to Intel has simplified some parts of installing Gentoo, proprietary hardware and software can make it a bit more complex than a typical x86 GNU/Linux install.

[edit] Preparing the Disk

In the early part of 2006, Apple created a hybrid partitioning scheme that allows Intel-based Macs to boot OS X with other operating systems. It is a unique partitioning scheme that implements Intel's EFI standard. The scheme includes support for GPT partitioning as well as legacy MBR for use with Windows. It does this by emulating the BIOS. For the moment, the only tool that can edit this partitioning scheme is Apple's diskutil (BootCamp also uses this program).

You can use standard MBR partitioning and be able to install Linux and Windows, but the Mac OS X 10.4.6 and before will not allow an install to an MBR partitioning scheme.

You will also need a bootloader to choose your OS at boot. rEFIt has a graphical loader, supports multiple file systems and includes a shell to help with editing. Optionally, BootCamp can install a bootloader.

[edit] Creating a Partition Map

There were two ways to partition a MacBook to install Gentoo GNU/Linux, use (diskutil) to partition on a pre-installed EFI-GPT scheme, or use third party utilities and partition with the MBR standard. Parted and gparted have proved to be reliable to many users.

[edit] Using diskutil

diskutil is included with Mac 10.4.6 or higher. It must be noted, that GPT partition standard only allows a maximum of four partitions to be created. The first partition is an EFI partition (an unseen partition) located at the first 200MB on a MacBook hard disk. With the GPT scheme this leaves only three partitions to work with. diskutil is used from the command line or can be used with BootCamp with limited ability.

Note: diskutil only is able to create primary/logical partitions hence the 4 partition GPT limit. It is possible to have a 7 partition system running smoothly with bootcamp using GPT, see the Alternate Partitioning Method 2 for details.

In OS X open the terminal application and type this to see your current partitioning scheme:

diskutil list
/dev/disk0
 #:                   type name               size      identifier
 0:  GUID_partition_scheme                    *74.5 GB  disk0
 1:                    EFI                    200.0 MB  disk0s1
 2:              Apple_HFS Macintosh HD        74.2 GB  disk0s2

The disk is already partitioned, notice the EFI partition here. Locate the "identifier" of your Mac OS X partition. This partition will be divided to create a partition(s) for the Linux install.

In this instance the partition is disk0s2.

In the example below, the disk is repartitioned from a 80GB partition to contain a 32GB OS X partition, 21GB Linux partition and 21GB Windows partition. The volume sizes and names can be changed but keep the order. This example includes a Windows partition. Note, a full Mac OS X Tiger (10.4.8) requires ~30GB of space.

Note: Mac OSX 10.5 (aka Leopard) provide a different version of diskutil and it seems to not allow you creating a Linux Partition Type! Just create FAT32 partitions, boot linux from CD and change to ext3/xfs/reisersf using parted. Reboot and sync partition table using rEFIt.
sudo diskutil resizeVolume disk0s2 32G \
"Linux" <name of linux volume> 21G \
"MS-DOS FAT32" <name of windows volume> 21G

If the above command fails, run the disk utility on the Mac OSX Install and check for errors. Also diskutil can fail if it cannot find a contiguous space for large files.

diskutil doesn't actually format here. It separates the disk (moves data if necessary) and writes a new GPT/EFI/MBR partition map.

Source:

[edit] Using BootCamp

If you are planning to use Boot Camp (best for new Mac OS X users) get it here. When you run BootCamp, create a Windows Drivers CD if you plan a Windows XP or Vista install. BootCamp simplifies the entire process. It will walk you through not only how to resize the Mac OS X partition, but also install a bootloader.


[edit] Partitioning using a 3rd Party Tool (Deprecated)

Warning: This may not be wise to delete your GPT partition as OS X expects it to be there.

If you ever need to do firmwire updates or reinstall/upgrade OS X, it might mess things up.

  1. Install OS X normally
  2. Clone or make a tarball of OS X and move it to an external disk.
  3. Boot Ubuntu LiveCD - repartition the disk as MS-DOS/MBR (NO GPT):
    1. - OS X HFS+
    2. - Windows NTFS
    3. - Ubuntu EXT3
    4. - Extended
      1. - Home (Ubuntu) EXT3
      2. - Swap swap
      3. - Storage - no filesystem yet (will be FAT32 for compatibility)
  4. Install Windows first to partition 2
  5. Install Ubuntu to partition 3
  6. Boot to Ubuntu and copy your OS X system to partition 1
  7. Now reinstall GRUB to the disk's MBR - Do update-grub to update your menu.lst

Another method:

If you won't be using Mac OS X at all, you may get away without messing around with GPT and all the rest, which is probably the easiest way, especially if you have a PC background. You should install rEFIt or Bootcamp though; this will give your machine the ability to boot directly from a hard drive that has a "legacy" BIOS partition table on it.

Install the Bootloader and press "C" (or Alt) so that you boot from your Linux cdrom.

Now, replace GPT by a good, old-fashioned, BIOS partition table. In order to get rid of the GPT layout, you may either:

  • Zero out the first and the last few sectors of the hard drive (ie, using dd if=/dev/zero ...)
  • Use the "mklabel" command of parted to create a new "MSDOS" table

You may now wish to reboot (still from your Linux cdrom) to confirm that GPT is gone, and after that you can proceed normally, as you would do on a regular PC.

[edit] Gparted

Using gparted is by far the easiest and most reliable way, now that parted and gparted support GPT/MBR.

Just boot up with a linux live cd (tested the live ubuntu 7.10 cd with 4th gen. macbook with leopard), and use gparted to resize your HFS+ partition and add whatever partitions you like. Note: gparted crashes after succesfully creating the partitions, but it is nothing to worry about. Then install Gentoo normally. When you reboot, be sure to hold down alt/option and you will get the option of booting into OS X or "Windows"-> really Gentoo. (Note: I used an ext2 boot partition). If you do not want to hold down alt/option on every boot or if you are using reiserfs, etc.., install rEFIt.

If you can't edit your HFS+ partition because gparted says that the data cannot be read, try disabling the journal under Mac OS X with this command:

diskutil disableJournal /dev/disk0s1

Don't forget to enable the journal afterwards again!

[edit] Installing a Bootloader

Download and run the rEFIt installer if you are not using bootcamp.

It is best to install and configure rEFIt in OS X. Trying to install rEFIt after installing a Linux bootloader can cause problems.

[edit] rEFIt / Linux-Only

Since rEFIt does not require the presence of OSX to function, one can remove osx, repartition the disk to have a 512MB(or something like that) HFS+ partition to install rEFIt, and the rest of the disk can be used for Linux.

To do that:

  1. Hold down 't' while booting MacBook to go into target-disk mode.
  2. Connect MacBook into another OSX machine
  3. Repartition MacBook's disk to have a very small HFS+ partition
  4. Install rEFIt onto that partition
  5. Run enable-always.sh to always enable rEFIt.
  6. Carry on with the rest of this wiki to partition the rest of the disk in Gentoo

Note: Since there is no longer an OSX installation on the Laptop, one would have to boot into OSX from an external disk(or swap the hard drive) to run firmware upgrades.


Also, you can install the rEFIt witout any other OSX machine,

  1. Download the rEFIt tar.gz from [1]
  2. Boot you machine with the OSX DVD, (remember to hold the C key)
  3. Open a Terminal
  4. Create a mount point, for example /Volumes/efi
  5. mount the EFI partition,
sudo mount -t msdos /dev/disk0s1 /Volumes/efi
  1. Decompress the refit-bin-X-Y.tar.gz and copy the
cd /Wherever/
tar zxvf refit-bin-X-Y.tar.gz
cp /Wherever/refit/efi /Volumes/efi/efi/
cp /Wherever/refit/tools /Volumes/efi/efi/
  1. Now, we will bless the EFI system partition
sudo bless --mount /Volumes/efi --setBoot --file /Volumes/efi/efi/refit/refit.efi --labelfile /Volumes/efi/efi/refit/refit.vollabel
  1. Now just unmount the EFI partition and reboot the machine


There is also a rEFIt ISO disk image, to boot you machine if you need it.

[edit] Choosing a CD

Gentoo Linux provides two install choices with a CD, the LiveCD and the Minimum Install CD. More people have had success with the Minimum Install CD.

First Generation MacBooks will need to use the i686 CD. Second Generation MacBooks feature the Core2 Duo which can emulate the 64bit instruction set.

The Core2Duo is a processor that uses the IA-32 microarchitecture with EM64T extension. That makes it similar to an AMD Athlon 64 processor. Although it is not a true 64 bit processor (not IA-64 microarchitecture) it can process the 64bit instruction set and features the 64bit address register extensions and general purpose registers. That means you can choose to run a traditional 32bit x86 or an x86-64 system. An x86-64 system is capable of running 32bit and 64bit applications. The 64bit applications can use 4GB address space per process (2GB in x86).

People having used the 64bit systems claim overall speed increases. It's caveat however is that some drivers and applications are 32bit only and sometimes 32-bit emulation doesn't work. If you wish to have a 64bit system use the AMD64 CD, use the i686 CD for a 32bit system.

Note: The stage3 tarball must also match the system.
Note: 2007.0 Minimal install runs 2.6.19 and does not support the rev 3 santa rosa macbook pro's wireless or wired network. sabayon 3.4f supports both wired and wireless on the rev3 macbook pro. small-gentoo for amd64-r8 does support wired network as well and is gentoo based and has gparted


[edit] Filesystems

Once you've booted into the Gentoo Live CD, follow the Gentoo Handbook on file system creation with the following in mind:

[edit] Partioning and resyncing

Use parted instead of fdisk to create your Gentoo partitions. Reboot and use the rEFIt partitioning tool to resync your partition tables. Then proceed with the installation as per the Handbook (this applies at least to some MacBooks 2nd generation).

[edit] Swap

Swap is the physical memory overflow file saved to the hard disk. If more memory is required than that of your physical (RAM) memory, then memory is saved to disk.

Comparatively Linux consumes much less memory than OSX, so unless you will be using memory intensive programs a swap may not be necessary.

It's possible to have a swap file rather than having swap reside in a separate partition. To do that:

dd if=/dev/zero of=/mnt/gentoo/swap bs=1024 count=2097152
mkswap /mnt/gentoo/swap
swapon /mnt/gentoo/swap

This creates a 2G swap in a file called '/swap' (count=2097152 is 2G). You may name it whatever you wish and give it whatever size you wish.

If you want a different sized swap then substitute "2097152" one of these values:

512MB = 524288
1Gb = 1048576
1.5GB = 1572864

Notes:

  • I have 512MB of RAM on my 6 year old Dell Inspiron 8000 that almost NEVER uses swap with Gentoo.
  • I now have a 2GB of RAM MacBook so I'm not going bother with a swap partition. There is a good chance that it will never be used.
  • Forgoing swap is not a good idea. Long compiles have hardlocked my system (both processors in stuck in IOWAIT) if there is no swap. If you are really streched for space, make a 256 or 512 MB swapfile, but don't just leave it out. --jimmers

[edit] Reiserfs

Reiser file system (sometimes call Reiser3) is a file system introduced to the kernel in 2001. It's contains better disk storage for smaller files and improved journaling over ext3, though ext3 is considered more tried and true. rEFI includes support for it (Visit rEFIt myths for more information). The kernel configuration file includes Reiserfs support.

Reiser4 filesystem is still considered unsafe by most users and not recommended as of this writing. -- 05-05-2007

[edit] XFS

XFS is (along with JFS) among the oldest journaling file systems available for UNIX systems, and has a mature, stable and well-debugged codebase. It is fast and solid. It has many advanced features such as xfs_fsr which improves the organization of mounted filesystems and 64 bit support. It is highly recommended and fully supported in current gentoo-sources kernel.

[edit] The fstab File

The fstab is a list of all the file systems on your computer. An example can be found in the MacBook Configuration-Files.

[edit] Preparing the System

At this point, things mostly progress the same as the Gentoo Handbook, starting with creating the filesystems. Almost all questions that you will encounter during the installation ("which kernel", "kernel config", "how to do this or that") are answered on this wiki-page. Be aware that some of the instructions on this page may not be in the same order in that you will encounter them during the installation. So I suggest that you read ahead a bit to avoid unwelcome surprises. Also Notes have been added to sections where users were kind enough to put in input of their personal experiences.

[edit] make.conf

The appropriate make.conf depends on whether you have a CD or C2D processor.

Some have opined that,

"The single most important thing you can do to having a successful Gentoo built is providing as complete a make.conf as possible."

The make.conf is the preferences file for compiling. What you put in it and how you set it up is a fundamental part to how well the system will run.

An example make.conf is in the MacBook Configuration-Files.

[edit] CHOST

Take note that it is important to set your CHOST alongside your CFLAGS. It is dangerous and time-consuming to change your CHOST later on.

for a 32-bit system and

CHOST="i686-pc-linux-gnu"

for a 64-bit system.

CHOST="x86_64-pc-linux-gnu"

[edit] CFLAGS

The CFLAGS provide GCC ( the compiler ) more accurate information about your processor type.

GCC 4.1.2 and below

MacBook First Generation

CFLAGS="-O2 -march=prescott -fomit-frame-pointer -pipe"

MacBook Second Generation

The next generation of MacBooks use the C2D with the Merom core. This includes the MacBook Pros (SantaRosa).

CFLAGS="-O2 -march=nocona -pipe"

GCC 4.2.*

With GCC 4.2.* has been included an option the will discover you correct march. Make sure you have "cpuid" set in the kernel.

# 32 bits
CFLAGS="-march=native -O2 -fomit-frame-pointer -pipe"
# 64 bits
CFLAGS="-march=native -O2 -pipe"

GCC 4.3

GCC 4.3 (still being developed) will include "-march=core2".

[edit] MAKEOPTS

All MacBooks have a processor with 2 cores so we can safely use 3 jobs. This wont change anything in the code we will produce, but it can cut compilation times.

MAKEOPTS="-j3"

[edit] Hardware Specs

Specifying the hardware specs will tell Gentoo Portage ( The Compiling Infrastructor ) what type driver to install for the given hardware.

Set the VIDEO_CARDS variable to the describe your video card.

For MacBooks with Intel card:

VIDEO_CARDS="i810 vesa"

For MacBooks with ATI card:

VIDEO_CARDS="fglrx radeon vesa fbdev"

For MacBooks Pro with NVIDIA card:

VIDEO_CARDS="nvidia nv vesa fbdev"

Very common devices for most users:

INPUT_DEVICES="keyboard mouse synaptics evdev"

[edit] Kernel Setup

Use the vanilla-kernel if you have issues with building a kernel. Most kernel builds include support for the MacBook.

[edit] Successful Kernel Builds

The following versions have been deployed successfully:

Kernel's prior to 2.6.20 have incomplete hardware support.

[edit] Downloading the Kernel

Fill in the appropriate version below: Removing the equals sign and version will install the latest version.

emerge =vanilla-sources-(version)

or

emerge =gentoo-sources-(version)

[edit] The MacTel Kernel Patches

As the development of the kernel for Intel-Mac related items improve, there will be less and less a need for the mactel-patches. As of 2.6.22 several mactel patches are already a part of the kernel (SMC, Appletouch, and Temperature Sensor).

The Mactel kernel patches are designed to work with the vanilla kernel and may or may not be compatible with the Gentoo kernel version (gentoo-sources). Kernel patches are not required for most kernels versions but provide added functionality and fix known errors. Examples are temperature sensors, trackpad control, minor audio tweaks, USB IR receiver, keyboard backlight control.

Get the svn tool.

emerge subversion

Download the appropriate mactel-patchset and apply it to the kernel source:

cd /usr/src
svn co https://mactel-linux.svn.sourceforge.net/svnroot/mactel-linux/trunk/kernel/mactel-patches-(version) mactel-patches-(version)
cd mactel-patches-(version)
./apply /usr/src/linux

[edit] Kernel Config

A 2.6.20 Kernel .config is provided here but more recent versions can be found in MacBook Configuration Files.

Also 2.6.18 Kernel .config and its notes can be found at blscreen's Kernel .config.

Download and Personalize the Configuration

cd /usr/src/linux
wget http://www.archive.org/download/ToddPartridgeMacBookKernelConfigurationFilefor2.6.20/config2.6.20macbookcore2duo
mv config2.6.20macbookcore2duo .config
make oldconfig
make menuconfig

2. Compile and install your kernel

make && make modules_install && make install
[edit] MacBook Configuration Files

Some kernel configs and stuff are available here:

MacBook Configuration Files

[edit] Modules Autoload

With many newer drivers make their presence known to udev and it may not be necessary to put modules /etc/modules.autoload.d/kernel-2.6 anymore. However it doesn't hurt to place them in either:

nano /etc/modules.autoload.d/kernel-2.6

and add these and whatever others you need. (you can always remove them later.)

appletouch
usbhid

[edit] Only on NEW Macbooks manufactured after Nov 2007

The newer Models include a Marvell Network Controller that seems to be not supported by the Kernel. (See lspci section for more info) Goto [2], download the driver and follow the README to get it working.

Note: Support for the network card has been added in the 2.6.23-R3 Kernel. Just build 'SysKonnect Yukon2' into the kernel and all is well.

[edit] Congratulations!

You should now have a working kernel installed.

If you experience any problems please report them in the forum so we can fix the instructions!

Some additional kernel patches may be required for some advanced features (e.g. suspend to ram/disk). You can find information about that in the corresponding sections of this wiki-page.

[edit] Configuring the Linux Bootloader

GRUB is the most used choice for MacBook users but LILO can be used as well. It's recommended that you use Grub 0.97-3 or later as this has support for hybrid GPT/MDR partition maps. For instructions on installing the bootloader, see the Gentoo Handbook.

Note: If you create multiple entries in the boot loader, a bug present in the firmware on MacBook Pro rev2 systems prevents the keyboard from working reliably. Unless Apple repairs the bug the only known workaround is to plug in an external USB keyboard and use it to select the alternate boot images.

[edit] Lilo

Emerge LILO and then edit /etc/lilo.conf

Example

[edit] Checking the New System Out

Test that this kernel runs and boots properly on your MacBook before you make any more changes.

rEFIt (or BootCamp) should now be able to recognize you Linux system and load the Linux bootloader at startup. Hopefully at this time you have a functional and running system.

Notes:

  • If you have not installed rEFIt (or BootCamp) before the Linux install, these instructions may help you.
  • If you get a "No bootable device" error, select the partitioning tool from the rEFIt menu and update the MBR. This syncs the partition tables between the GPT and MBR loaders.
  • Upon reboot, if your display is giving you odd colors, you may need to reset your PRAM/NVRAM. To do this, hold down cmd+opt+p+r before your computer starts up and wait until you hear the second Mac startup sound. (I had to do this upon rebooting from the Gentoo 2008.0 Minimal Installation CD on a 1st Generation Macbook Pro.)

[edit] Building the Desktop

Now that the base system working we can build a desktop.

[edit] Installing the Desktop

MacBooks

MacBooks (first and second generation) use the Intel GMA 950 graphics processor with 64MB of DDR2 SDRAM shared with main memory. See this HowTo.

MacBook Pro

The first and second generation MacBook Pros use the ATI Mobility Radeon X1600 graphics processor, follow the ATI drivers Wiki. FGLRX (compositing support) works with full hardware acceleration as of gentoo-sources-2.6.21 and ati-drivers-8.37.6.

Third generation MacBook Pros use ...

The Macbook Pro, third generation (3,1 up) uses the Nvidia 8600M GT. See NVIDIA drivers for full instructions.

[edit] Powersaving

  • Macbook Pro Core Duo (first generation):

If you don't need the full graphic power you can underclock the card:

# /opt/ati/bin/aticonfig --list-powerstates
core/mem      [flags]
-----------------
1: 128/135 MHz  [low voltage]
* 2: 311/297 MHz  [performance mode, default state]
3: 311/297 MHz
# /opt/ati/bin/aticonfig --set-powerstate=1
  • Machbook Pro Core2Duo (second generation):

If you got a Macbook Pro C2D (second generation, still with x1600 card but Core 2 Duo Processor) the command will fail with:

Error: POWERplay is not supported on your hardware.

A useful workaround can be found here: http://ati.cchtml.com/show_bug.cgi?id=608#c9

Simply download the source for the patched radeontool (30kb), do a “make” and run

./radeontool power low

this will reduce your power consumption by ~7-8 W and finally allows battery capacity around 2,5hr, instead of just 1,5hr. And keep in mind, it's more silent because of less heat.

Notes:

  • Don't forget evdev and appletouch in your kernel config !

[edit] Configuring Special Keys: brightness, volume...

X server key mapping has worked fine since xorg-server-1.4. Keys should be properly mapped to handle eject, numlock ... In Gnome add gnome-power-manager to add brightness key support. An application call Pommed was used to fill the gap until xorg-server key mapping was integrated. Also pommed can add additionaly functionality.

[edit] HAL update bug

More recent versions of HAL (Hardware Abstraction Layer) cause problems for the MacBook hardware and most software attempting to alter screen brightness (see error below).

kpowersave: WARNING: Property: laptop_panel.brightness_in_hardware for: /org/freedesktop/Hal/devices/macbook_backlight doesn't exist.
kpowersave: ERROR: Could not call/set SetPowerSave on HAL, could be a bug in HAL spec

In between HAL versions hal-0.5.9.1-r3 and hal-0.5.10, a detrimental update was made. According to the HAL Portage Changelog, there are no versions of HAL released in between these two. Versions of HAL greater than hal-0.5.10 are known to not work with a second generation MacBook, but versions at or below hal-0.5.9.1-r3 will work for altering screen brightness. Many versions of HAL were tested for consideration with this problem to determine at what point the bug was introduced. There are at least two bugs on Gentoo Bugzilla related to this problem (#200060 & #211988), as well as Ubuntu bug #206921. According to these sources, the hotkeys of at least MacBooks (Pro), IBM Thinkpads, and HP Pavilion notebooks are affected. Many architectures are also affected (x86, x86_64, amd64...), and clearly multiple Linux distributions.

To resolve the hotkey issue, you may simply downgrade HAL via

emerge =sys-apps/hal-0.5.9.1-r3 

After which, it is likely a good idea to reboot. You may instead restart the individual daemons if you like, but HAL controls many other programs, such as NetworkManager, so a system reboot is not a bad idea.

At this point, functions altering screen brightness, such as pommed and kpowersave ought to behave! However, some keys have been remapped in X compared to more recent versions of HAL. It is unknown at this time if a re-emerge of X related packages fixes this HAL downgrade problem.

In HAL versions 0.5.10 and above, we have the following xev keycode associations: 116 - Down Arrow, 134 - Right Apple, 104 - Numberpad Enter. In HAL versions 0.5.9.1-r3 and below, we have the following xev keycode associations: 104 - Down Arrow, 116 - Right Apple, 108 - Numberpad Enter. For now, an easy fix is to alter your ~/.xmodmap appropriately, and then run

xmodmap ~/.xmodmap

[edit] pommed

pommed is a small daemon written specifically for MacBook Pros and MacBooks, requires little or no configuration. It includes GUI indicator indicating in brightness, volume, numlock and eject. It also can manage automatic brightness and can be used to personalize the "fn" key behavior and turn the Apple Remote receiver on/off.

Hot keys will not work unless you have enabled the proper driver in your kernel configuration; this works for MacBooks even though you are enabling support for iBook/PowerBook hot keys as well as EVDEV support. In menuconfig:

Device Drivers --> USB Support --> [*] Enable support for iBook/PowerBook special keys

Kernel 2.6.22

Device Drivers --> HID Devices --> [*] Enable support for iBook/PowerBook special keys
It is also necessary to set CONFIG_INPUT_EVDEV=y

If this driver was not already enabled, be sure to recompile your kernel and reboot.

Pommed is in Portage

emerge pommed

Pommed can be configured through /etc/pommed.conf, which is thoroughly commented, then start the daemon:

/etc/init.d/pommed start

The configured keys should work in the console or in X. If you install pommed with USE="gtk", the GUI daemon called gpomme will show popup windows when you press a key handled by pommed.

Add pommed to your run-level:

rc-update add pommed default

Notes:

[edit] Colour Profile

The many Linux desktops do not have included support for color management of displays. Some drivers provide this support or you can use the program xcalib. Xcalib uses colour profiles form Mac OS X (ICC profile).

Calibrate a profile in Mac OS X in System Preferences > Displays > Color - use Expert-mode for finer control. The saved profile will be in /Users/<username>/Library/ColorSync/Profiles.

Xcalib will be needed to calibrate in Linux:

emerge -av xcalib

And calibrate with your profile.

xcalib calibrated.icc
Note: The profiles shall go in /usr/local/share/color/icc

As well some profiles are already in OS X.

MacBook C2D (new MacBook Pro):

xcalib /mnt/osx/Library/ColorSync/Profiles/Displays/Color\ LCD-4271880.icc

MacBook Pro CoreDuo (old MacBook Pro):

xcalib /mnt/macos/Library/ColorSync/Profiles/Displays/Color\ LCD-4271800.icc

MacBook (not Pro) C2D (new MacBook):

xcalib /mnt/osx/Library/ColorSync/Profiles/Displays/Color\ LCD-4271780.icc

MacBook (not Pro) CoreDuo (old MacBook):

xcalib /mnt/osx/Library/ColorSync/Profiles/Displays/Color\ LCD-4271780.icc

xcalib can be loaded on startup. In Gnome System > Preferences > Sessions > Startup Programs and click Add.

Notes: "* Source moros

  • As of version 0.6-r1 gamma wasn't working right. After calibrating with PC gamma (2.2) in Linux would give me a very dark look, while Mac gamma 1.8 would be a tad light. Using a gamma 1.9 to 2.0 worked nice.

[edit] Hardware Setup

With a desktop now active, you can finalize your installation by making sure you hardware is setup correctly.

[edit] Sound

Sound uses the hda-intel module. This should already be added to the kernel .config if you used the kernel configuration above. With older Macbooks (before Autumn 2007), by default, sound will "just work", in that ALSA will detect your hardware. With newer Macbook Pro Santa Rosa (bought during or after Autum 2007), sound will just work, but only with kernels > 2.6.24_rc1 . Previous kernels will give you no sound output.

Sound can be used with a separate Alsa driver or with it build into the kernel. Check your kernel configuration:

For the seperate Alsa driver:

Linux Kernel Configuration: Sound Configuration
Device Drivers  --->
  Sound  --->
    <M> Sound card support
      Advanced Linux Sound Architecture  --->
        < > Advanced Linux Sound Architecture

Kernel built-in:

Linux Kernel Configuration: Sound Configuration
Device Drivers  --->
  Sound  --->
    <M> Sound card support
      Advanced Linux Sound Architecture  --->
        <M> Advanced Linux Sound Architecture
        <M>   Sequencer support
        < >     Sequencer dummy client
         <M>   OSS Mixer API
        <M>   OSS PCM (digital audio) API
        [*]     OSS PCM (digital audio) API - Include plugin system
        [*]   OSS Sequencer API
        <M>   RTC Timer support
        PCI Devices ->
          <M> Intel HD Audio

Emerge Alsa utilities and alsa oss modules. Emerge the separate alsa driver (if you choose to use the driver not in the kernel). Then configure alsa, start the Alsa daemon, and set it to run at boot:

emerge alsa-utils alsa-oss
emerge alsa-driver
alsaconf
/etc/init.d/alsasound start
rc-update add alsasound boot

A quick test:

emerge mpg321
mpg321 Emo_Love.mpg

Also see:

[edit] Crackling Sound on the left Channel

In case you have the problem that sometimes your left channel goes crackling on high frequencies and makes listening to music a real pain there are some workarounds available (which i heard off):

  • This one worked for me (.22 mactel-sources): Edit the /etc/modprobe.d/options and insert
options snd-hda-intel model=macbook

You have to insert the correct type of Mac you are using:

intel-mac-v1 : Intel Mac Type 1
intel-mac-v2 : Intel Mac Type 2
intel-mac-v3 : Intel Mac Type 3
intel-mac-v4 : Intel Mac Type 4
intel-mac-v5 : Intel Mac Type 5
macmini : Intel Mac Mini (equivalent with type 3)
macbook : Intel Mac Book (eq. type 5)
macbook-pro-v1 : Intel Mac Book Pro 1st generation (eq. type 3)
macbook-pro : Intel Mac Book Pro 2nd generation (eq. type 3)
imac-intel : Intel iMac (eq. type 2)
imac-intel-20 : Intel iMac (newer version) (eq. type 3)
  • Some people said for them also worked
options snd-hda-intel position_fix=1
  • Another one is to restart the Alsasound at startup with
/etc/init.d/alsasound restart

Dont forget to run update-modules for the upper two solutions :)

[edit] Touchpad

The touchpad uses a specialized module (appletouch) to connect with the standard touchpad driver (synaptics). So it can be configured just as any other synaptic touchpad can. See Synaptics Touchpad for more information. A patch has just been added to enable two finger click transforms (e.g. two finger right click). The details for installing can be found at the wiki link just above.

The touchpad control panel offers basic configuration.

emerge gsynaptics

Check to see if gsynaptics-init --sm-disable, to preserve changes between login sessions, is in System > Preferences > Sessions.

Notes:

  • For Kernels Prior 2.6.20 and versions of gsynaptics < gsynaptics-0.9.10
link
  • Set the touchpad up manually:
  • I had trouble getting my touchpad to work with the emerged version of synaptics, 0.14.5-r1, so I installed the newest version, 0.14.6, from the developers website. Then I replaced the synaptics_drv.so with the newer one (in /usr/lib/xorg/modules/input/), and now everything works great, including scrolling, two-finger touching, etc...
  • Due to updating xorg you may have to reemerge x11-drivers/xf86-input-mouse to make xorg work with the touchpad.
  • I only got the touchpad working by setting up the udev-rule you can see at "How to make Synaptics Touchpad survive suspend/resume"

[edit] WiFi

Built-in Wireless for MacBooks uses an Atheros chipset or a Broadcom chipset. The chipset in the original Core Duo-based Macbooks is well supported by the MadWifi project. The newer Core 2 Duo-based Macbooks use a different Atheros chipset (supporting draft 802.11n), scroll down if you have a Core 2 Duo MacBook or MacBook Pro.

[edit] Installing the driver

For both generations of MacBook, you will need the madwifi drivers (they provide a software driver set for the Atheros chipset). Note that the the Madwifi application dynamically loads extra kernel modules for rate selection. Therefore, be sure that you have the following options enabled in your kernel. Note: This option is the last under Loadable Module Support. I would have sworn I had it in there but I did not. The below snippet made me think just to enable the first two.

Loadable Module Support -->
   [*] Enable loadable module support
   [*] Automatic kernel module loading

Also kernels before 2.6.22 will need CONFIG_NET_RADIO configured:

-> Device Drivers
  -> Network device support
    -> Network device support (NETDEVICES [=y])
      -> Wireless LAN (non-hamradio)

[edit] Macbooks - 1st Generation

MacBooks made prior to November 2006 use the Atheros chipset with the 802.11g standard. MacBooks made prior to November 2007 use the Atheros chipset with the 802.11n standard.

For Kernels prior to 2.6.27 see the MadWifi article. 2.6.27 has the Ath9k driver build in which works out of the box.

[edit] Macbooks - 2nd-3rd Generation

MacBooks built during and after November 2006 use the Atheros chipset that supports the 802.11n standard.

The open source Atheros made Ath9k driver was introduced in the 2.6.27 kernel series, so this shouldn't be any real issue anymore if you are using an up to date kernel, just make sure you use the following:

[*] Networking support  ---> 
  Wireless  --->
    <*> Generic IEEE 802.11 Networking Stack (mac80211)
Device Drivers  --->
  [*] Network device support  --->
    Wireless LAN  --->
      [*] Wireless LAN (IEEE 802.11)
        <M>   Atheros 802.11n wireless cards support


[edit] Kernels prior 2.6.27
[edit] Madwifi

MadWifi 0.9.5 will support this Atheros chipset. As of April, 2008, MadWifi 0.9.5 is not yet released, but recent snapshots from the Madwifi mainline work with this chipset, and with kernel 2.6.22.

To install the latest Madwifi snapshot, do the following as root (the reboot should not be necessary):

cd /usr/src
wget http://snapshots.madwifi.org/madwifi-trunk-current.tar.gz
tar xzf madwifi-trunk-current.tar.gz
cd madwifi-trunk-r*
make
make install
make clean
ln -s /usr/src/madwifi-trunk-r2656-20070817 /usr/include/madwifi #replace dir name with the snapshot you downloaded
reboot
[edit] Ath9k

Wlan also works on the open ath9k driver see http://wireless.kernel.org/en/users/Drivers/ath9k

To install ath9k.

cd /usr/src/
git clone git://git.kernel.org/pub/scm/linux/kernel/git/mcgrof/ath9k.git
cp ath9k/ksrc linux/drivers/net/wireless/ath9k
cd linux
cat ../ath9k/top-level.patch | patch -p1
make menuconfig #and select appropriate drivers see ath9k page
make all install modules_install

Based on: http://ubuntuforums.org/showthread.php?p=2910343

If your wireless connection dies after some time (it "seems" connected but it is not, until you reboot), and you see a lot of FIFO buffer overrun in your logs, you've been hit by the buffer overrun bug. Maybe iwpriv ath0 bgscan 0 helps you. See http://madwifi.org/ticket/1017 for reference.

Also see the Atheros 5xxx article.

[edit] Macbooks - 4th-5th Generation

My Macbook has an "Broadcom Corporation BCM4328 802.11a/b/g/n" chipset.


Code: lspci
 02:00.0 Network controller: Broadcom Corporation Device 4328 (rev 03)

Until July 2008, the only way to get this card working was using ndiswrapper. This method is often reported as working quite bad (frequent loss of connection, WPA not working...). But in July 2008 Broadcom released new official and almost free drivers (they call it "hybrid") that seem to work very well.

(in my case, that was the only way to get WPA working, it even works with a 64bits kernel without multilib)

First we review the ndiswrapper way, (that should be soon deprecated) and then we show the use of the official broadcom driver (IMHO it should become now the standard way).


[edit] Using Ndiswrapper

First of all ensure you emerge the lastest version of ndiswrapper.

echo "net-wireless/ndiswrapper" >> /etc/portage/package.keywords

At the time I'm writing this guide the current version of ndiswrapper is 1.53.

Download the driver directly from the Leopard DVD Disk 1 (Drivers/BroadcomInstaller.exe). Unrar it.

Code: unrar e BroadcomInstaller.exe
Extracting  bcmwl5.inf                                                OK
Extracting  DPInst.exe                                                OK
Extracting  bcmwl5.sys                                                OK
Extracting  bcm43xx.cat                                               OK
Extracting  DPInst.xml                                                OK
All OK

if you don't have unrar already installed simply emerge it (emerge unrar).

Then all you have to do is to install the driver (bcmwl5.inf) with ndiswrapper.

Code: ndiswrapper -i bcmwl5.inf
installing bcmwl5 ...

Than check if the driver has been successfully installed.

Code: ndiswrapper -l
bcmwl5 : driver installed
        device (14E4:4328) present

Now you have only to load the ndiswrapper module:

depmod -a

modprobe ndiswrapper

Check if the module has been successfully loaded by checking dmesg

Code: dmesg
ndiswrapper version 1.53 loaded (smp=yes, preempt=no)
ndiswrapper: driver bcmwl5 (Broadcom,01/08/2007, 4.80.75.0) loaded
ndiswrapper: using IRQ 16
wlan0: ethernet device 00:1e:52:7f:3a:20 using NDIS driver: bcmwl5, 
version: 0x4504b00, NDIS version: 0x501, vendor: 'NDIS Network Adapter',
14E4:4328.5.conf
wlan0: encryption modes supported: WEP; TKIP with WPA, WPA2, WPA2PSK;
AES/CCMP with WPA, WPA2, WPA2PSK
usbcore: registered new interface driver ndiswrapper

Now the last command in order to completely ensure that all we have done is ok:

Code: ifconfig -a
wlan0     Link encap:Ethernet  HWaddr 00:00:00:00:00:00
          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)
          Interrupt:16 Memory:b4500000-b0634000

The new device's name will be wlan0.

If you want ndiswrapper module to autoload at system startup you can easily do that by letting ndiswrapper to configure its module:

ndiswrapper -m

and than add "ndiswrapper" to the modules' list into /etc/modules.autoload.d/kernel-2.6

echo "ndiswrapper" >> /etc/modules.autoload.d/kernel-2.6

Don't forget to create a symlink for your new interface and make it starting during the boot.

ln -s /etc/init.d/net.lo /etc/init.d/net.wlan0

rc-update add net.wlan0 default

Than you can proceed to setup your network configuration. There is a plenty of guides about that ;)


[edit] Using the official Broadcom driver (DRAFT, FIXME IF NEEDED)
Note: This is supposed to work but your mileage may vary
Note: Notice that as we rely on the kernel sources you should do the following after having compiled, installed your kernel and being running it. An ebuild using gentoo's specifics would be a nice touch.

Depending on your architecture, download the 32bits or 64bits archive at http://www.broadcom.com/support/802.11/linux_sta.php. Also download the README file. From now on the instructions in the README file should be sufficient. Briefly said, you just have to compile the driver and then install it.

[edit] Compilation

Say you created a directory named "broadcom" in your home directory and downloaded the archive in it, then:

cd ~/broadcom
# 32 bits
tar -xzf ./hybrid-portsrc.tar.gz

or

# 64 bits
tar -xzf ./hybrid-portsrc-x86_64.tar.gz

And compile the driver:

make -C /lib/modules/$(uname -r)/build M=$(pwd) clean
make -C /lib/modules/$(uname -r)/build M=$(pwd)

You should find now a file named "wl.ko" in the same directory. This is the driver.

[edit] Installation

First uninstall the other drivers, if needed, with one of the following commands:

rmmod bcm43xx
rmmod b43; rmmod b43legacy
rmmod ndiswrapper

Maybe you will also have to remove it from /etc/modules.autoload/kernel.2.6


Then copy the driver in the modules directory and load it. You may need to create the "misc" directory first.

cp wl.ko /lib/modules/$(uname -r)/misc
update-modules -f
modprobe wl

Now the last command in order to completely ensure that all we have done is ok:

Code: ifconfig -a
eth1     Link encap:Ethernet  HWaddr 00:00:00:00:00:00
          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)
          Interrupt:16 Memory:b4500000-b0634000

Notice the new device's name will be eth1 whereas with other drivers it is generally called "wlan0". This is normal. Don't forget to update your /etc/conf.d/net file about this.

If you want wl module to autoload at system startup you can easily do that by adding "wl" to the modules' list into /etc/modules.autoload.d/kernel-2.6

echo "wl" >> /etc/modules.autoload.d/kernel-2.6

Don't forget to create a symlink for your new interface and make it starting during the boot.

ln -s /etc/init.d/net.lo /etc/init.d/net.eth1
rc-update add net.eth1 default

Than you can proceed to setup your network configuration (seen gentoo documentation) or use network-manager.

[edit] Feedback
  • It works perfectly for me (gentoo-sources 2.6.25 r7, 64bits, no-multilib), and even with WPA!
  • It works nice for me as well (mactel 3.1 according to hal but 4.1 according to this guide, gentoo-sources 2.6.24 r8 + mactel patches, 64bits, multilib), and even with WPA! One little drawback though is that I can't seem to ssh anywere. --EvaSDK

Reported to work on other distributions, please add your config if it works for you too.

[edit] Starting Wireless (Manually)

If the Gentoo boot scripts doesn't connect you can connect manually. This will work with modern, non-specialized routers, if additional configuration (wireless extensions) is needed, see the MadWifi Wiki.

iwconfig ath0 essid any
ifconfig ath0 up
dhcpcd ath0

The driver will search for the strongest AP (Access Point) and try to connect to it. If it fails try scanning the AP's and manually entering it:

wlanconfig ath0 list scan
iwconfig ath0 essid "yourAP"

Notes:

  • USE flag onoe while emergin madwifi is no longer necessary as of madwifi-ng-0.9.3-r3.

[edit] Power Management

[edit] Backlight Dimming

In portage there is macbook-backlight (app-laptop/macbook-backlight) that can manually set the backlight.

Automatically Dim When the Power Cord is Unplugged

The Gentoo Linux Power Management Guide explains how lower the backlight when the power cord is unplugged.

The boot script is a bit different as macbook-backlight (app-laptop/macbook-backlight) is used:

The on_ac_power command is provided by the powermgmt (sys-power/powermgmt-base) ebuild.

/etc/init.d/lcd-brightness

#!/sbin/runscript

set_brightness() {
	if on_ac_power
	then
		LEVEL=${BRIGHTNESS_AC:-148}
	else
		LEVEL=${BRIGHTNESS_BATTERY:-32}
	fi
	
	ebegin "Setting LCD brightness"
	/usr/bin/macbook-backlight -s ${LEVEL}
	eend $?
}

start() {
	set_brightness
}

stop() {
	set_brightness
}


Gnome Power Manager (gnome-extra/gnome-power-manager) can now do this ability as well, but I have found security concerns about it.

Also there is Pbbuttonsd (app-laptop/pbbuttonsd) - ( discussion and links to ebuilds ).

[edit] System Management Controller

The SMC introduced into the 2.6.22 kernel provides added ability to manage power of the MacBook.

We need to have the proper hardware modules loaded, so enable the following in menuconfig:

Device Drivers -->
    Hardware Monitoring Support -->
        [M] Apple SMC

Then make sure the computer loads the module when it boots Gentoo. If you edit /etc/modules.autoload.d/kernel-2.6, just add the line:

applesmc

To load it now modprobe it :

modprobe applesmc

This makes some magic files available under /sys/devices/platform/applesmc

Put your fan in manual mode by typing :

echo "1" > /sys/devices/platform/applesmc/fan0_manual

After, you can set the speed of the fan by running :

echo "1200" > /sys/devices/platform/applesmc/fan0_target_speed

Values are ranged from /sys/devices/platform/applesmc/fan0_minimal_speed to /sys/devices/platform/applesmc/fan0_maximal_speed and you can get the safest value in /sys/devices/platform/applesmc/fan0_safe_speed

To restore the fan in automatic mode, just type :

echo "0" > /sys/devices/platform/applesmc/fan0_manual

The keyboard backlight is accessible through the file /sys/class/leds/smc:kbd_backlight/brightness. Brightness values range from 0 (off) to 255 (brightest).

To set the brightness:

echo 0 > /sys/devices/platform/applesmc/leds:smc:kbd_backlight/brightness

To read the current setting:

cat /sys/devices/platform/applesmc/leds:smc:kbd_backlight/brightness

(The were made some changes in the applesmc sys tree, the fan0_target_speed is now called fan1_output)

[edit] Monitor CPU temperature through gkrellm

Compile your kernel with:

Device drivers -->
  I2C support -->
    <*> I2C device interface
      I2C Hardware Bus support -->
        <*> Intel 810/815      # for MacBook
        <*> Intel 82801 (ICH)  # for MacBook Pro

Now emerge gkrellm

emerge app-admin/gkrellm

Needs 2.2.10 or later with the lm_sensors USE flag enabled. In gkrellm, check the options in configurations --> builtins --> sensors. Enjoy!

[edit] Touchpad Fixes

[edit] Toggle Touchpad On/Off When Pluggin in Mouse

If the behavior of th touchpad randomly clicking and moving the cursor while typing is becoming annoying, it can automagically be turned off when you have an usb mouse plugged in through UDEV. Compile the kernel with those options:

Linux Kernel Configuration:
Device Drivers  --->
    USB support  --->
         [M] Apple USB Touchpad support
File systems
    [*] Inotify file change notification support
         [*] Inotify support for userspace

In newer kernels (2.6.24 for example) :

Linux Kernel Configuration:
Device Drivers  --->
    Input device support  --->
        Mice  --->
            [M] Apple USB Touchpad support
File systems
    [*] Inotify file change notification support
         [*] Inotify support for userspace

Inotify is not really needed, but makes it much easier to debug/config udev, because that way it takes notice of configuration changes on-the-fly.

First make sure you remove/comment out appletouch from /etc/modules.autoload.d/kernel-2.6

Then create /etc/udev/rules.d/10-local.rules and put in these udev rules:

SUBSYSTEM=="usb", SYSFS{product}=="*Mouse*", RUN+="/sbin/modprobe appletouch"
ACTION=="add", SUBSYSTEM=="input", ID_CLASS="mouse", RUN+="/usr/bin/synclient TouchpadOff=1"
ACTION=="remove", SUBSYSTEM=="input", ID_CLASS="mouse",  RUN+="/home/user/.scripts/mouse-touchpad-toggle-on"

As root, run udevstart (or reboot). Done!

It is possible just to use synclient to re-enable the touchpad, but only one rule at a time can be added and it is handy to use syndaemon to enforce a touchpad break while typing. Udev also didn't recognize if statements making just a basic script:

#!/bin/bash

synclient TouchpadOff=0 MaxTapTime=0;
syndaemon -i 1 -d

More information on how to create rules for udev can be found in:

[edit] Remote Control

[edit] Assigning key values to remote control buttons through xmodmap

The Apple remote control (RC) can work without Lirc; it works out of the box as an extension to the keyboard, and can easily be assigned key values through xmodmap, which is a command that comes with Xorg. Running the command xev, you can find out each RC key keycode; after that, you can bind those keys to keyboard keys.

  • NOTE: As of the 3rd generation MacBook Pro (Santa Rosa) Apple changed the device ID for the IR receiver. The default mactel patches won't work any more. For kernel 2.6.22 exists a patch (coming from arch-linux) to make it work again: [3]

Created ~/.xmodmap with:

keycode 153 = Right
keycode 144 = Left
keycode 176 = Up
keycode 174 = Down
keycode 162 = Return
keycode 158 = Escape

After creating the file, you should run

xmodmap ~/.xmodmap

and don't forget to run it each time you run Xorg. You can also do it automagically.

You can have mplayer control functionality by modifying /usr/share/mplayer/input.conf:

#DOWN seek -60
DOWN volume -1
#UP seek +60
UP volume 1
#ENTER pt_step 1 1
ENTER pause

[edit] Using the volume and remote control events in applications with inputlircd

emerge -va inputlircd
USE=lirc emerge -va mplayer
/etc/init.d/inputlircd start

You may want to use the irexec daemon additionally to manage the volume level independant of the media application. To do so you'll want to edit the /etc/lircrc file as below, run "irexec --daemon", and then start mplayer.

#

begin
        prog = mplayer
        button = KEY_PLAYPAUSE
        config = pause
end

begin
        prog = mplayer
        button = KEY_PREVIOUSSONG
        config = seek -10
        repeat = 1
end

begin
        prog = mplayer
        button = KEY_NEXTSONG
        config = seek +10
        repeat = 1
end

#begin
#       prog = mplayer
#       button = KEY_VOLUMEUP
#       config = volume 1
#       repeat = 1
#end

#begin
#       prog = mplayer
#       button = KEY_VOLUMEDOWN
#       config = volume -1
#       repeat = 1
#end

begin
prog = irexec
button = KEY_VOLUMEUP
config = amixer set PCM 9+ &      #amixer set PCM 3%+ &
repeat = 2
end
begin
prog = irexec
button = KEY_VOLUMEDOWN
config = amixer set PCM 9- &      #amixer set PCM 3%- &
repeat = 2
end


Using "amixer set PCM 3%+ &" won't work if the sound level is 0 !

[edit] Apple Keyboard

The Apple Keyboard is unique from other PC manufactures. The largest difference is function key behavior, as well as mapping of special characters (i.e. non-english).

[edit] Enable "normal" FN-key behaviour

Many people don't like the Apple default of "fn-always-on". pommed (see above) has a configuration option to change the fn key behavior, but if you do not use it, changing the behavior is still easy. Just pick your favorite:

I'm using kernel 2.6.21 and functions keys work as expected, e.g., a F1 press will open Help.

# FN always on (like in OS X)
echo -n 0x01 > /sys/module/usbhid/parameters/pb_fnmode

or

# FN behaves like "shift"
echo -n 0x02 > /sys/module/usbhid/parameters/pb_fnmode

And add the respective line to your /etc/conf.d/local.start

Newer 2.6.20 kernels: A recent patch to 2.6.20-rc kernels moved the pb_fnmode module parameter from usbhid module to the hid module, so you should replace "usbhid" with "hid" above if you are using this (or a later) version.

echo -n 0x01 > /sys/module/hid/parameters/pb_fnmode #FN default on
echo -n 0x02 > /sys/module/hid/parameters/pb_fnmode #FN default off

Working 2.6.20-rc6 snippet:

       -> Device Drivers
         -> HID Devices
           -> USB Human Interface Device (full HID) support (USB_HID [=y])
             [*]   Enable support for iBook/PowerBook/MacBook/MacBookPro special keys

Kernel <=2.6.24_rc8 doesn't recognize the special keys of 3rd Generation MacBook correctly. http://linux.twam.info/patches/macbook3rd-2.6.24_rc8.patch fixes this.

[edit] Console support for NumLock key

Set /etc/conf.d/keymaps with

File: /etc/conf.d/keymaps
EXTENDED_KEYMAPS="keypad"

Then issue

/etc/init.d/keymaps restart

But do it in the console, as it will alter X's keymap too.

[edit] Keyboard and Numpad configuration in X11

It seems simple, but one goes a long way until finding the sanest X11 configuration, so here it is (supports the new external Apple keyboards too):

File: /etc/X11/xorg.conf
Section "InputDevice"
        Identifier  "Keyboard1"
        Driver      "keyboard"
        Option      "XkbModel" "pc105"
        Option      "XkbLayout" "us"
#        Option      "XkbVariant" "intl"
        Option      "XkbOption" "numpad:mac"
EndSection 

Uncomment the commented line if you want dead keys (to get accented letters). I also polished the resulting keymap with xmodmap:

File: ~/.Xmodmap
keycode  77 = Pointer_EnableKeys Num_Lock
keycode 157 = KP_Equal
keycode 94 =  dead_grave dead_tilde

[edit] X11 configuration to use with Xmodmap

The keyboard is supported by USB-HID. but there seem to be no good keymaps for it.

One possible solution (for an X environment) is to use a xmodmap, my first try looks like this:

!!
!! xmodmap for Apple MacBook - German layout
!!
! Let the left apple key act as mode switch
keycode 115 = Mode_switch
! Use the right apple switch as "ALT_GR" key, provides the additional
! characters you find on a tradition pc keyboard (example @)
! !! Also this key acts as right mouse button when used with left apple key
keycode 116 = ISO_Level3_Shift NoSymbol Pointer_Button3
! Use the Delete key correctly
! Maps to center mouse if used with left apple key
keycode 108 = Delete Delete Pointer_Button2
! Page Up/Down
keycode 98 = 0xff52 NoSymbol 0xff55
keycode 104 = 0xff54 NoSymbol 0xff56
keycode 100 = 0xff51 NoSymbol 0xff50
keycode 102 = 0xff53 NoSymbol 0xff57
! Switch keys ( lt/gt <-> circle/accent )
keycode 94 = 0xfe52 0x00b0 0x00ac 0x00ac 0x00ac 0x00ac
keycode 49 = 0x003c 0x003e 0x007c 0x00a6 0x007c 0x00a6

This .xmodmap file is for the german keyboard layout, the last two lines will probably not apply to other versions. To make the keyboard -> Mouse click mappings work you will need to install a small tool (i could not find in in portage), get it here. When installed run at the beggining of each X-session:

xmodmap <the_file_above>
xkbset exp m
xkbset m

Note: mouse click mappings works without this, because it's X independent (see appropirate section on this page). If you just want to switch keyboard layouts, use setxkbmap. - Turdus, 15-12-2006

Please note that this key-mapping will not make the keyboard work as printed on the keys, but will match a standard german keyboard. Hints for your own tries: xev (event debugger - lets you see what keycodes are sent), xmodmap and its man-page.

Notes:

  • As of 06-07 function key still isn't recognized by xev, probably related to the keyboard driver?


[edit] Gnome keyboard layout

Bring up the Keyboard Preferences window with System ▸ Preferences ▸ Keyboard from the Main menu. Click on the Keyboard Layout Options tab, and find Third level choosers. Mark the right Win key as third level chooser. Now your right Apple key works as Alt Gr. Restart X (Ctrl+Alt+Backspace) for the changes to take effect.

This and other interesting info maybe found at https://help.ubuntu.com/community/MacBook.


[edit] Alt, Insert and Delete

This is a sample config how to make your life easier with MacBook. It maps right Mac key as right Alt, the key next to right Mac as Delete and left Mac as Insert.

keycode 108 = Delete
keycode 115 = Insert
keycode 116 = Mode_switch
# replace Mode_switch with ISO_Level3_Shift on new macbook (belgian macbook here). Mode_switch doesn't work

Additionally this is for Polish people to let them use Polish letters:

keysym a = a A aogonek Aogonek
keysym c = c C cacute Cacute
keysym e = e E eogonek Eogonek
keysym l = l L lstroke Lstroke
keysym n = n N nacute Nacute
keysym o = o O oacute Oacute
keysym s = s S sacute Sacute
keysym x = x X zacute Zacute
keysym z = z Z zabovedot Zabovedot

--szamot 22:35, 4 December 2006 (UTC)

[edit] Linux Console Keymap

Note: This might apply only to german keyboard layouts.

Note: It also works with the Spanish keyboard layout.

Note: Works for Macbook4,1 with us intl' keyboard and us layout.

First select your desired keyboard layout by editing /etc/conf.d/keymaps. A little tweaking is necessary to get ALT-GR and to swap the "^" and "<" key. Do a

dumpkeys > /etc/default.kmap

then in /etc/default.kmap replace all occurrences of the number "86" with "41" and vice versa, and be sure to have a line

keycode 126 = AltGr

This maps the right "Apple"-Key to AltGr. Choose /etc/default.kmap as KEYMAP in /etc/conf.d/keymaps.

[edit] Map mouse button 2 and 3 to keyboard

If you aren't using a mouse and since MacBooks don't have built-in right-clicks, it works nice to map mouse clicks to the keyboard.

To map the keys they have to be defined numerically. We'll need xev.

emerge xev

Using xev find the keycodes you need. In this example we'll be using Super_R (Right Apple) and the lower enter keys.

nano ~/.xmodmap

Add your keycodes here.

keycode 116 = Pointer_Button2
keycode 108 = Pointer_Button3
  • .xmodmap will load on xsession startup.
  • You also have to turn on mousekeys in the keyboard accessability preferences.
  • Script cannot be commented
  • Source

[edit] Map F11 and F12 to mouse button 2 and 3

To use keys for the missing second and third mouse button you need to enable CONFIG_MAC_EMUMOUSEBTN in the kernel .config, located in Device Drivers > Macintosh Device Drivers > if you use the menu, you need the patch to show it on x86 and do the following:

echo 1 > /proc/sys/dev/mac_hid/mouse_button_emulation
echo 87 > /proc/sys/dev/mac_hid/mouse_button2_keycode #for F11
echo 88 > /proc/sys/dev/mac_hid/mouse_button3_keycode #for F12

Since /proc is a temporary filesystem these settings will not be saved on exit. To have these rules applied on every boot apply the rules to /etc/conf.d/local.start.

Also, just about any key can be bound to the mouse buttons. To do this, exit to console and type "showkey".

[edit] MacBook (3rd generation)

In order to get my Fn key to work (vanilla-sources-2.6.24rc7), I had to change the DEVICE_ID of my keyboard in

File: /usr/src/linux/drivers/hid/usbhid/hid-quirks.c
#define USB_DEVICE_ID_APPLE_GEYSER4_ISO 0x022a

and recompile my kernel. I found the correct DEVICE_ID via lsusb.

In Kernel 2.6.25-rc2 support was added.