Gentoo Wiki ArchivesGentoo Wiki

Apple_MacBook

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

Contents

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.

Subpages

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.

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.

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.

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:

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.


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:

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.

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!

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.

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.

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


Filesystems

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

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

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

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

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.

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.

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.

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.

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"

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

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"

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"

Kernel Setup

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

Successful Kernel Builds

The following versions have been deployed successfully:

Kernel's prior to 2.6.20 have incomplete hardware support.

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)

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

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
MacBook Configuration Files

Some kernel configs and stuff are available here:

MacBook Configuration Files

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

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.

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.

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.

Lilo

Emerge LILO and then edit /etc/lilo.conf

Example

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

Building the Desktop

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

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.

Powersaving

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

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 !

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.

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

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:

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.

Hardware Setup

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

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

On my macbook 4,1 (Feb08) I needed the following line in /etc/modprobe.d/options to bring up the sound system:

options snd-hda-intel model=mbp3

Also see:

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):

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)
options snd-hda-intel position_fix=1
/etc/init.d/alsasound restart

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

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"

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.

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)

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.

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


Kernels prior 2.6.27
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
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.

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


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 ;)


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.

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.

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.

Feedback

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

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.

Power Management

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

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)

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!

Touchpad Fixes

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:

Remote Control

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.

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

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 !

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

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.

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.

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

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:


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.


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)

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.

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

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

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.

Microphone, internal speaker and headphones

Working with patched 2.6.20-r6 from scratch. (someone else??) - 2007-04-20

I was able to get the built-in mic working on the macbook thanks to Jason Parekh's howto (http://www.jasonparekh.com/linux-on-macbook#microphone).

I used the alsa-driver ebuild (version 1.0.13). If you have sound built into your kernel you can also get it working this way too, you just need to edit the files /usr/src/linux/patch_sigmatel.c and /usr/src/linux/sound/pci/hda/patch_sigmatel.c instead of the ones I mention below (and skip the ebuild commands).

Basically we just need to edit the patch_sigmatel.c file to re-map the pins to better suit the macbook. Here's how I did it with the alsa-driver ebuild and portage:

ebuild /usr/portage/media-sound/alsa-driver/alsa-driver-1.0.13.ebuild unpack
vim /var/tmp/portage/media-sound/alsa-driver-1.0.13/work/alsa-driver-1.0.13/pci/hda/patch_sigmatel.c

search for "d945gtp5_pin_configs" (line 354 for me), you should see something like this:

static unsigned int d945gtp5_pin_configs[10] = {
        0x0221401f, 0x01011012, 0x01813024, 0x01014010,
        0x01a19021, 0x01016011, 0x01452130, 0x40000100,
        0x02a19320, 0x40000100,
};

Make a new line under this section and paste the following:

static unsigned int macbook_pin_configs[10] = {
        0x0321E230, 0x03A1E020, 0x400000FD, 0x9017E110,
        0x400000FE, 0x400000F0, 0x1345E240, 0x13C5E22E,
        0x400000FC, 0x400000FB,
};

Now we need to tell alsa to use our new macbook pin configuration, so just a few lines down you should see:

[STAC_MACMINI] = d945gtp5_pin_configs,

Change this to:

[STAC_MACMINI] = macbook_pin_configs,

Note that the above DISABLES your line in. If you need to use your line in AND your mic, then in the new code block replace the "0x400000F0" value with "0x0381E021" so that it reads:

static unsigned int macbook_pin_configs[10] = {
        0x0321E230, 0x03A1E020, 0x400000FD, 0x9017E110,
        0x400000FE, 0x0381E021, 0x1345E240, 0x13C5E22E,
        0x400000FC, 0x400000FB,
};

Note: Mactel-Linx.com has since updated their patchset (by combining Jason's pins with Nicolas' unused pins) to use the following:

static unsigned int macmini_pin_configs[10] = {
	0x0321E230, 0x03A1E020, 0x9017E110, 0x01014010,
	0x01a19021, 0x0381E021, 0x1345E240, 0x13C5E22E,
	0x02a19320, 0x400000FB,
};

The disadvantage is that you will need to toggle the recording device to linein and back to mic to get it to work. Of course this could be done easily with /etc/conf.d/local.start, something like

amixer sset 'Input Source' 'Line'
amixer sset 'Input Source' 'Mic'

Save and exit patch_sigmatel.c. Now check to make sure the other file says the same thing. This is found under:

/var/tmp/portage/media-sound/alsa-driver-1.0.13/work/alsa-driver-1.0.13/alsa-kernel/pci/hda/patch_sigmatel.c

When you are sure they are both as mentioned above you're ready to build the driver. Run:

ebuild /usr/portage/media-sound/alsa-driver/alsa-driver-1.0.13.ebuild compile
ebuild /usr/portage/media-sound/alsa-driver/alsa-driver-1.0.13.ebuild install
ebuild /usr/portage/media-sound/alsa-driver/alsa-driver-1.0.13.ebuild qmerge

If you are using sound in your kernel, then re-build your kernel now. If you have sound built statically into your kernel you'll need to rebuild your kernel, copy it to /boot and reboot to it. If you're using sound as modules, then you should be able to just run:

cd /usr/src/linux/
make modules modules_install

Once you have emerged the package or rebuilt your kernel update the module deps

update-modules

I think it's a good idea to reboot at this stage, or reload your alsa modules. You could just re-run alsaconf if you like which should do this for you.

When you reboot you should now be able to use your microphone. Remember to toggle the recording device to linein and back to mic if you need to. You can toggle the mic for recording from the command line with:

amixer sset Capture '100%' toggle

Make sure it says "on" like so:

chris@localhost ~ $ amixer sset Capture '100%' toggle
Simple mixer control 'Capture',0
Capabilities: cvolume cswitch
Capture channels: Front Left - Front Right
Limits: Capture 0 - 14
Front Left: Capture 14 [100%] [21.00dB] [on]
Front Right: Capture 14 [100%] [21.00dB] [on]

Simply make sure that it is selected to record and give it a test!

Important note for the headphones sound :

If sound from the internal speakers still doesn't work, you can try one other change from MactelLinux.com.

Open the file patch_sigmatel.c and locate the entry:

static const char *stac922x_models[STAC_922X_MODELS]

and then add an entry for

SND_PCI_QUIRK(0x8384, 0x7680, STAC_MACMINI);

or

{ .pci_subvendor = 0x8384,
  .pci_subdevice = 0x7680,
  .config = STAC_MAXMINI },

depending on which version of the file you have. This change got internal speakers and microphone and headphone detection working on a Core Duo 20" iMac with alsa-drivers-1.0.14_rc1. The subvendor and subdevice are the upper and lower halves of the Sybsystem ID: cat /proc/asound/card0/codec#0 | grep Subsystem

Built-in iSight

The iSight camera is supported by the Linux USB Video Class driver. Kernel >=2.6.26 includes uvcvideo and the isight firmware loader (firmware must be placed be /lib/firmware). For kernels <2.6.26 you need to install it seperately:

echo -e "dev-libs/libusb ~x86\nmedia-video/linux-uvc ~x86\nmedia-video/isight-firmware-tools ~x86" >> /etc/portage/package.keywords
emerge -va linux-uvc isight-firmware-tools

Now, load the USB Video Class driver module you just compiled:

 modprobe uvcvideo

You need at least media-video/linux-uvc-0.1.0_pre173 to for the iSight firmware.

Probably you need to install the firmware first. Get the File System/Library/Extensions/IOUSBFamily.kext/Contents/PlugIns/AppleUSBVideoSupport.kext/Contents/MacOS/AppleUSBVideoSupport from your OS-X partition and copy it to /lib/firmware and run

 ift-extract --apple-driver AppleUSBVideoSupport

afterwards.

After this, i had to adjust /etc/udev/rules.d/isight.rules to

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

Then reboot or run udevtrigger for re-read udev rules. It creates new device /dev/video0.

Also I did not find the udevtrigger tool on my installation. I solved the issue by manually running:

 /usr/lib/udev/ift-load --firmware /lib/firmware/isight.fw -b 00{busnum} -d 00{devnum}

The expressions {busnum} and {devnum} have to be replaced by the appropriate numbers. I ran lsusb and took the numbers from the device with xxxx:8300. Example: /usr/lib/udev/ift-load --firmware /lib/firmware/isight.fw -b 001 -d 003

You will probably need to fix the permissions as follows

 chmod o=wrx /dev/v4l/video0

Test the iSight with mplayer:

 mplayer tv:// -tv driver=v4l2:width=640:height=480:device=/dev/video0 -fps 20 

If installation went well, you should see your face on the mplayer window. :)

You can also test with Cheese:

cheese


Driver works well with ekiga, gstreamer, mplayer(>=1.0_rc2), kopete (>=0.12.7), skype (>= 2.0.0.43). Clients such as amsn, xawtv, vlc will not function.

Getting iSight to work with Ekiga:

USE="v4l2 v4l ldap" emerge -av pwlib
emerge -av ekiga

Launch Ekiga, via menus or:

$ ekiga &

Configuration: You may have to select the iSight device.

Edit > Preferences > Devices > Video Devices >

- Video plugin: V4L2

- Input device: Built-in iSight

Getting full size frame from ekiga:

$ gconf-editor &

Now, from the left-hand tree, navigate to:
apps > ekiga > devices > video

Change the value for size from 0 to 1.

This changes the size from Small ( QCIF 176x144 ) to Large ( CIF 352x288 ).

Reopen Ekiga and you should see the full video image.

It is possible to have full resolution by changing "width=320:height=240" by "width=640:height=480" (the resolution that apple give on their website).

Actually, amsn seems to work if you download and compile the very latest snapshot from SVN (as of 2007-04-21).

Also, you can record video from camera with mencoder:

 mencoder tv:// -tv driver=v4l2:width=640:height=480:device=/dev/video0 -nosound -ovc lavc -o wcrecording.avi

Bluetooth

It seems the above mentioned kernel config doesn't include Bluetooth. You have to add the USB HCI driver, as the Apple baseband controller is just an HCI one, but with a special HID-on-powerup mode. Don't forget to recompile and install your kernel/modules!

To enable Bluetooth edit /etc/conf.d/bluetooth for hid2hci: Just change HID2HCI_ENABLE=false to true and add the Bluetooth service by executing

rc-update add bluetooth default

On my Macbook, this didn't work first. I had to manually specify hci-usb in /etc/modules.autoload.d/kernel-2.6. Otherwise, hid2hci wouldn't find the device (and wouldn't be able to switch it from HID to HCI mode). You can also compile the driver into the kernel, of course.

Suspend to Ram

Suspend to Ram is probably the most difficult feature to get fully working on your MacBook.

Most of us had to spend quite a few hours on tweaking to get it "right".

If it happens to work right away for you then you may consider yourself a very lucky person. :-)

Anyways, don't get discouraged when it fails for the nth time, it will work eventually!

Many people (including myself) go through many suspend/resume cycles every day without a hitch.

Alternatively you can use suspend2 to save to disk which is very simple and is completely outlined below under suspend to disk. Though this is not quite as fast, it will allow you to preserve your programs, data etc while you boot into OSX or other os.

How to set it up

Using Suspend

Note that this has been tested on a 2nd Generation Macbook using 32Bit.

Suspend is a tool that works almost right out of the box


Just emerge Suspend via the portage. Note that Suspend and lix86 are masked by ~x86.

Now type

s2ram

The only issue I had was that the madwifi driver wasn't reloaded properly after a suspend2ram.

For that edit /etc/hibernate/ram.conf and add

UnloadModules ath_pci
LoadModules ath_pci

I haven't tested this for other moduses of suspending because I only use s2ram. But i guess you will have to add this to their *.conf, too. Probably the common.conf is a master file for that. Just try it.

Other Methods

In order to get proper suspend/resume your system must fulfill the following prerequisites:

Once you meet all these requirements your suspend/resume should work!

The picoverlay is a nice solution for those who use layman. Just add the address to the "overlays:" section of your /etc/layman/layman.conf and do a

machine ~#
layman --fetchImage:CursorOFF.gif

If you are using x86_64, i.e. amd64:

I am using the picoverlay for s2ram, libx86, mactel-sources, pommed and a bunch of others. The libx86 ebuild contained in it, needs to be extended to hardcode the backend. (This is a temporary solution. If I find the time I either patch libx86 or the ebuild to do that automatically.)

All this was done using mactel-sources-2.6.21-r5 from picoverlay and xorg-x11-7.2 from portage.

# diff -u libx86-0.99.ebuild-old libx86-0.99.ebuild
--- libx86-0.99.ebuild-old      2007-06-18 17:34:58.000000000 +0200
+++ libx86-0.99.ebuild  2007-06-18 17:25:41.000000000 +0200
@@ -20,6 +20,10 @@
        sed -i -e "s@CFLAGS :=@CFLAGS +=@" Makefile || die "sed failed in Makefile"
 }

+src_compile() {
+       emake BACKEND=x86emu || die "install failed"
+}
+
 src_install() {
        emake install DESTDIR="${D}" || die "install failed"
        dodoc COPYRIGHT
After changing the ebuild, you need to regenerate its digest file and afterwards you can emerge s2ram:
# ebuild /usr/local/portage/picoverlay/sys-libs/libx86/libx86-0.99.ebuild digest
# emerge -a s2ram

These are the packages that would be merged, in order:

Calculating dependencies... done!
[ebuild  N    ] sys-libs/libx86-0.99  0 kB [2]
[ebuild  N    ] sys-power/s2ram-9999  0 kB [2]

Total: 2 packages (2 new), Size of downloads: 0 kB
Portage overlays:
 [1] /usr/local/portage/mine
 [2] /usr/local/portage/picoverlay

Would you like to merge these packages? [Yes/No]

libx86 should compile fine by now. With s2ram you might run into another problem: The s2ram ebuild checks for the kernel config option CONFIG_SOFTWARE_SUSPEND. As far as I understood, this is not necessary, when using CONFIG_SUSPEND2 and that using suspend2 is preferable. So either you fix the ebuild to check for SUSPEND2 (I did) or you compile a kernel with SOFTWARE_SUSPEND.

Just successfully suspended and resumed. Extensive tests need to follow.

--Chaoflow 15:45, 18 June 2007 (UTC)

Success stories

Partial or full success has been reported on the following configurations (please add yours):


C1D

echo 1 > /proc/sys/kernel/acpi_video_flags
VGASTATE=$(vbetool vbemode get)
sync
sync

echo mem > /sys/power/state

vbetool post
vbetool vbemode set ${VGASTATE}

C2D

Note : Using macbook you have to comment "# CONFIG_BLK_DEV_PIIX" in your kernel .config to make suspend-to-ram work. Unfortunately will disable the CDROM reader too.

It only works for me using echo mem > /sys/power/state. s2ram tries to switch to console which causes problems here.

MacBook Pro

# echo "mem" > /sys/power/state

(but please note that it's a Macbook Pro)

MacBook Air

for x:
# s2ram --force --vbe_save; sleep 5; chvt 12; sleep 2; chvt 7
for console:
# s2ram --force --vbe_save; sleep 5; chvt 12; sleep 2; chvt 1

How to perform a suspend

To suspend you simply type:

s2ram

...and the machine should go to sleep.

If you get a reboot instead of resuming when you open the lid, you might also try

s2ram -f -p -m


-f causes force, overriding the fact that the macbook is not on s2ram's whitelist. -p and -m cause s2ram to use vbetool to re-post on suspend and resume, which was necessary for the x1600 in MBP. See success stories (2.6.20) above for why these second two should no longer be necessary.

MacBook (non-pro) Core 2 Duo (maybe others with Intel GPU)

You might find s2ram works fine (with -f -s) from the console but if X is running it will restore into black screen, cursor will move for a while and then freeze. You might notice using echo mem > /sys/power/state avoids the freeze (eg you do a sound test by typing cat /dev/urandom > /dev/dsp) but the screen won't come back on. All you have to do to fix it is update xf86-video-i810 to at least version 2.0.0. Add to /etc/portage/package.keywords:

 x11-drivers/xf86-video-i810 ~x86
 x11-libs/libdrm ~x86
 x11-base/xorg-server ~x86
 media-libs/mesa ~x86

Then just

 emerge -av xf86-video-i810

Restart X. Now try as root (from within X):

 echo mem > /sys/power/state

Press the power button and hopefully your laptop should wake back into X. There's one last gotcha though, you'll find if you switch to a text terminal or quit X, the screen will just be blank (with backlight on). You can fix this by executing in X:

 chvt 1; vbetool post; chvt 7

Or you can have s2ram do this for you automatically with the command below:

 s2ram -f -p

I found the vbe_save (-s) option to s2ram causes the machine to reset when switching back to X with the new driver. It seems the 915resolution hack is also unnecessary for this version of the driver. If you're still having trouble make sure you're running kernel 2.6.20 or later, I'm using 2.6.20-r6 gentoo-sources + all mactel patches. This setup is also working fine with AIGLX/Beryl running.

Potential Problems

Most (even small) mistakes will render your WAKEUP/RESUME UNRELIABLE!. The Macbook may restart on wake up, halt on wake up, or wake up with the backlight off. If you have X11 running during suspend, then the machine may also crash immediately after wakeup, if it wakes up at all. Symptoms of this particular crash: frozen cursor, predominantly black screen, and squares of pixelation/static.

Oddily enough, on newer Macbook Pros the suspend could give more problems if launched from within a console than from within Xorg.

See the next section for hints about tracking down problems...

Checklist (if it doesn't work)

Here is a list of things you can try if you are having problems:

irqpoll acpi=force noapic
Section "Module"
       Load  "extmod"
       Load  "i2c"
       Load  "bitmap"
       Load  "ddc"
       Load  "vbe"
       Load  "dri"
       Load  "glx"
       Load  "freetype"
       Load  "type1"
EndSection


If anyone knows of other methods of solving the X11 crash issue, please update this page!

Please also refer to this post for a setup which is reported to work on at least two systems, but does not work on at least one other.

kernels 2.6.19-rc1 and later bring better suspend-to-ram support (tested under quake3) current problems :

to resolve the problem with the wrong color depth, you can put this line into /etc/hibernate/common.conf:

             OnResume 30 sudo /usr/bin/xset -display :1 dpms force off

after the screen goes blank, you have to move the mouse or tap on the touchpad and the screen should come up with the right resolution ***this is always functionally on a macbook pro, try it on a macbook*** edited by tw1nh3ad

Integrating with Gnome Power Manager

If you want to have Gnome Power Manager be able to employ s2ram, make the following alterations to /usr/share/hal/scripts/hal-system-power-suspend:


Tip: Update: The file to alter now lies in /usr/lib/hal/scripts/linux/hal-system-power-suspend-linux

Find the following:

File:
else
  if [ -x "/usr/bin/powersave" ] ; then
      $POWERSAVED_SUSPEND2RAM
      RET=$?
  elif [ -x "/usr/sbin/pmi" ] ; then
      /usr/sbin/pmi action suspend force
      RET=$?

and change it to

File:
else
  if [ -x "/usr/sbin/s2ram" ] ; then
      /usr/sbin/s2ram #You might need to instead
                      # put something like:
                      # (sleep 2; sudo /usr/sbin/s2ram -f -p)&
      RET=$?
  elif [ -x "/usr/bin/powersave" ] ; then
      $POWERSAVED_SUSPEND2RAM
      RET=$?
  elif [ -x "/usr/sbin/pmi" ] ; then
       /usr/sbin/pmi action suspend force
       RET=$?

You may also get gnome power manager giving you permission problems, if so, execute the following:

machine ~#
touch /var/run/console/YOUR_USERNAMEImage:CursorOFF.gif

You will need to put that command in the file /etc/conf.d/local.start in order for it to work after every boot.

Suspend to disk

Works almost out of the box with the suspend2 patches (I applied them to 2.6.18-rc6 together with the mactel patches). Many people with the macbook will be going back and forth between gentoo and OSX and maybe even windows. This 'hibernate' feature provides a very simple transition between workspace platforms. This is also possible in both windows, as hibernate (should be already setup?), and in OSX as 'safe sleep'. --Otho 23:52, 12 November 2006 (UTC) 'Safe sleep' doesn't work form me after I have booted into linux, making it currently almost useless to implement.

--Otho 21:56, 26 October 2006 (UTC)I used the portage cheat (above) applying the mactel patches to sys-kernel/suspend-sources-2.6.18, with no problems. This provides a much easier way to get the suspend2 and mactel patches (not to mention all the ones from the gentoo-sources).

Follow the HOWTO Software Suspend v2 and install hibernate-script from portage. 915resolution has to be restarted after resume. As there is only a tweak for 855resolution yet, put this into /etc/hibernate/scriplets.d/915resolution:

File: /etc/hibernate/scriptlets.d/915resolution
# -*- sh -*-
# vim:ft=sh:ts=8:sw=4:noet

AddConfigHandler 915resolutionOptions
AddConfigHelp "Run915resolution <boolean>" "Set to run 915resolution before switching back to X."

915resolutionResume() {
    /etc/init.d/915resolution restart || return 1
    return 0
}

915resolutionOptions() {
	case $1 in
		run915resolution)
			BoolIsOn "$1" "$2" || return 0
			if [ -z "$I915RESOLUTION_HOOKED" ] ; then
				AddResumeHook 98 915resolutionResume
				I915RESOLUTION_HOOKED=1
				XHacksOptions switchtotextmode 1
			fi
			;;
		*)
			return 1
	esac

	return 0
}

I am using the following configuration for a working hibernate and hibernate-ram.

File: /etc/hibernate/suspend2.conf
UseSuspend2 yes
Reboot no
EnableEscape yes
DefaultConsoleLevel 1
Compressor lzf
Encryptor none
FullSpeedCPU yes

SwitchToTextMode yes
Run915resolution yes

Include common.conf
File: /etc/hibernate/common.conf
Verbosity 0
LogFile /var/log/hibernate.log
LogVerbosity 1
Distribution gentoo
SaveClock restore-only
UnloadBlacklistedModules yes
UnloadModules usbhid appletouch ath_pci
LoadModules auto
DownInterfaces eth0 ath0
UpInterfaces auto
# If laptop_mode is installed:
# RestartServices laptop_mode
File: /etc/hibernate/ram.conf
UseSysfsPowerState mem
EnableVbetool yes
Include common.conf

External monitor

For MacBooks with intel 945 based video cards, external monitor output can be enabled or disabled via the app-misc/i810switch software. The latest version currently in portage (0.6.5-r1) doesn't support anyway the i945 card directly, and needs to be patched. Both a patch and a proposed ebuild can be found in gentoo bugzilla at here. It was tested on a CoreDuo MacBook, with the mini-dvi to vga adapter, and worked perfectly.

In the first generation MacBook with intel 945 video cards, driving a 1680x1050 or similar widescreen resolution on an external monitor requires the 915resolution (sys-apps/915resolution) hack of the video BIOS modes. This utility must be run before X is started to add the 1680x1050 resolution in the video BIOS. The main MacBook display is also widescreen and the basic init.d scripts included in 915resolution change only one entry in the video BIOS. I edited (hacked) the /etc/init.d/915resolution script to force 2 updates in the video BIOS to ensure that both the MacBook screen and external display (in my case an 22" ACER 1680x1050 widescreen LCD) would work with their native resolution. You must call those updates to the video bios before starting the X server. Read more on the use of 915resolution here.

To get the Fn + F7 key to switch on and off the external monitor, I used xbindkeys, by adding the following rows to my .xbindkeysrc file:

File: ~/.xbindkeysrc
...
"( i810switch | grep CRT | grep off ) && i810switch crt on || i810switch crt off"
   m:0x0 + c:214
...

This simply switches on and off the external monitor, without switching off the internal lcd. This is quite a different behaviour from the standard found on most laptops (which cycles between LCD-only,CRT-only,LCD+CRT). Anyway any more complex behaviuor should not be difficult to accomplish via a proper (and simple) bash script.

(please note that i810switch needs read/write permissions to /dev/mem, so you'll have to suid the binary, or find another workaround).

Unresolved Issues

In rare cases where your macbook has a MATSHITADVD you will have a problem with dvd answering with status too late,so you will get errors in dmesg every 2 seconds. I solved this by modifying /usr/src/linux/drivers/ide/ide-iops.c at line 558 from udelay(1) to udelay(2). This make the kernel wait a little longer for the cdrom status.


HDAPS

HDAPS feature (acceleration detection) is enable with applesmc patch. But, current interface is not compatible with other current hdaps tools (especialy hdapsd wich allow to park head of disk).

Power saving

MacOS X allow MacBook to work on battery during 6 hours. How have these results on Linux?

Hardware Sensors

The Intel 82801 (ICH) is the correct driver for the I2C bus, but I do not know what the drivers for any sensors are, if they exist.

The CPUs temperature can be fetch by using this little C code: http://svn.sourceforge.net/viewvc/mactel-linux/trunk/tools/temperature/

The new lm_sensors package contains a "coretemp" driver and allows reading temperature.

Non-official "applesmc" driver offers extended temperature info, fan control/info and motion sensor info. It also supports light sensors and keyboard backlights on the Macbook Pro.

A kernel patchset for this can be found here.

Appearently this is solved since upstream lm-sensors and upstream kernel now have support for applesmc and thus you can access all Macbook temperature and fan sensors!

The disk temperature can be fetch using hddtemp.

CD burning

When I'm trying to burn a 10-24X RW-DISK cdrecord says:

 Manufacturer: Mitsubishi Chemical Corporation
 cdrecord: Probably trying to use ultra high speed medium on improper writer.

The problem can be solved using -force option but not sure whether it's a proper solution.

--194.251.240.113 10:30, 16 August 2006 (UTC)

Luxury Items

Beryl

Nowadays, you should probably check out The newer Compiz Fusion which is the re-joining of the Compiz and Beryl projects. Everything should work out of the box.

See the up to date information at the Gentoo Xeffects Wiki. Beryl and others do work with Intel cards as well as with the ATI and Nvidia with Xgl, though for most Nvidia cards, Xgl is NOT required.

Dual Screen

To activate Dual screen run the following command:

   xrandr --output VGA --left-of LVDS --auto

This will activate the external display and set the max detected resolution for the screen.

To deactivate run the following two commands:

   xrandr --output VGA --off
   xrandr --output LVDS --mode 1280x800

The last of the two commands might not be needed, but I have had some problems with the internal screen taking the resolution of the external screen when I turn the external screen off..

http://www.thinkwiki.org/wiki/Xorg_RandR_1.2 shows lots of useful information how to configure X.org correctly for using xrandr.

AIGLX/Beryl Dual/Multi-Head Setup

When connected to an external display, during X11 startup, AIGLX will report that screen 1(the external one, the internal LCD is screen 0) does not support DRI. So if beryl is started as described above, it will try to take over both screens, and will fail to do so (crash). The solution is to first launch a non-DRI dependent window manger on screen 1, then launch beryl on screen 0. I used ion3 but you may use other wm.

I first edit my $HOME/.xinitrc to be like so:

  # if the "-oneroot" is not specified
  # ion3 will also try to take over both screen
  ion3 -display :0.1 -oneroot

Then open a terminal in ion3 and run:

  beryl --display :0.0 --strict-binding --screen 0 &

Then open a terminal in beryl and run:

  emerald &

There is still one problem: (in my case) X11 will freeze (must be rebooted) on exit for unknown reason(possibly related to Composite Extension as when it's not loaded, ion3 exits fine. But of course, not loading Composite Extension will prevent beryl from launching).

To have everything happen all at once during startup, make .xinitrc look like so:

  ion3 -display :0.1 -oneroot &
  DISPLAY=:0.0 emerald &
  beryl --display :0.0 --strict-binding --screen 0

Console framebuffer

32bit and Console Framebuffer

Works with Vesa-tng in the MacBook Pro (1440x900):

Linux Kernel Configuration: Console framebuffer
Device Drivers  --->
 Graphics support  --->
   [*] Support for frame buffer devices
   <*> VESA VGA graphics support                        (using radeonfb only)
         VESA driver type (vesafb-tng)   --->
(1024x768-24@60) Vesa default mode
   < > ATI Radeon display support
       Console display driver support  --->
         [*] VGA text console
         [*]   Video mode selection support
         <*> Framebuffer Console Support
         [ ]   Select compiled-in fonts
       Logo configuration  --->
         deselect everything

And in /etc/lilo.conf:

  addappend:"video=vesafb:mtrr,ywrap,1440x900-24@60"

vesafb-tng has been removed from gentoo-sources versions 2.6.23 and higher. intelfb doesn't seem to work for high resolution framebuffers, so MacBook users (at least pre-2007) will want to use the older kernel version.

-- note: vesafb-tng doesn't work for me on MBP 15" in its native 1440x900 resolution. I can only display a maximum of 1024x768, which does look prettz ugly. Does anybody know what kernel/vesafb-tng version was used in this howto?

-- note 2: The resolutions reported in /proc/fb0/modes go up to 1152x864. I'm not sure if widescreen frame buffers are supported. Also, 1024x768 seems to scale better to 1440x900 to1152x864 so I'd recommend using that instead.

x86_64 and Console Framebuffer

To use a proper Framebuffer on 64Bit systems you will either have to rely on vesafb or uvesafb, vesafb-tng is actually rather abadoned and doesnt even work on 64 Bit systems.

For uvesafb you will have to patch your kernel, which doesnt run very smoothly on the gentoo kernel. But there was a thread concerning that problem with an updated patcher (for which I sadly dont have the link anymore).

Refer to http://dev.gentoo.org/~spock/projects/uvesafb/ for download and installing instructions on uvesafv.

Xen

Xen uses paravirtualization kernel support to make it able to run multiple instances of Linux or other OS's on the same machine.

Xen can securely execute multiple virtual machines on a single physical system with close-to-native performance.

Download the sources from the marineam-xen portage overlay. First, install the very useful tool layman and install the overlay on your system.

emerge -av layman
echo "source /usr/portage/local/layman/make.conf" >> /etc/make.conf
layman -f
layman -a marineam-xen

Next, run emerge to build the xen sources. Emerge will use the overlay first before looking in the community portage tree.

emerge -av xen xen-tools
emerge -av xen-sources

As of this writing (20070425) the latest kernel tested is 2.6.16.46 which should run fine on the MacBook Pro. There are no existing patches to get the touchpad working along with various other things but it's possible to backport the mactel-linux patches to this kernel if you really need them.

Follow the instructions on the Xen page for kernel configuration and Xen details. Useful notes include:

There are no details for Xen kernel configuration specific to the MacBook Pro that need to be highlighted. The aforementioned wiki page, though generic, is sufficient to get a working kernel.

Obscura

Items that don't fit in elsewhere, or are rarely used.

What to do when touchpad or IR don't work?

It could be that udev loads usbhid before appleir and appletouch and the apple drivers cannot bind to the devices any more. To circumvent this problem you should add the following to your /etc/conf.d/local.start:

rmmod usbhid appletouch appleir
modprobe appleir
modprobe appletouch
modprobe usbhid pb_fnmode=2

you can look in modinfo to see what pb_fnmode does:

# modinfo -p usbhid
mousepoll:Polling interval of mice
pb_fnmode:Mode of fn key on PowerBooks (0 = disabled, 1 = fkeyslast, 2 = fkeysfirst)

I for one like to have them first for kde's ALT+F2 = "Run command"

Blscreen 20:18, 30 August 2006 (UTC)

The solution with /etc/conf.d/local.start has the drawback for me, that the X-Server is started before the modules are reloaded, forcing me to reload the server again after local.start has finished. My first attempted solution was to prevent udev from loading usbhid and appletouch alltogether and put these two in /etc/modules.autoload.d/kernel-2.6 in the correct order. But on some boots both modules were already present by the time usbcore registered them, thus leaving the order of registration random again.

The most reliable approach seems to be an file /etc/modprobe.d/touchpad with

 options usbhid pb_fnmode=2
 install usbhid /sbin/modprobe appletouch && sleep 2 && /sbin/modprobe --ignore-install usbhid $CMDLINE_OPTS

in it. This way appletouch always gets loaded 2 seconds before usbhid. Afterwards run update-modules.

Note: Behaviour depending on module load order is considered a bug (See https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=208721 ). This is most likely fixed in vanilla 2.6.21.

How to make Synaptics Touchpad survive suspend/resume

There's more trouble ahead: even if appletouch claims the device before usbhid does and Xorg detects a synaptic device at say /dev/input/event1, after a suspend/resume this can (and often will) change to for example /dev/input/event3. So Xorg still looking at event1 will lose the synaptics device. The solution: create a file /etc/udev/rules.d/70-appletouch.rules with

 SUBSYSTEM=="input",KERNEL=="event*",SYSFS{name}=="appletouch",SYMLINK+="input/appletouchpad"

and reboot. This will create a symlink /dev/input/appletouchpad always pointing to the right device. You have to change the InputDevice section in xorg.conf:

 Option        "Device"        "/dev/input/appletouchpad"
 Option        "Protocol"      "event"

Be sure not to have "Protocol" "auto-dev", or Xorg will automatically pick the event* device instead of appletouchpad.

--87.160.244.206 15:51, 17 November 2007 (UTC) This doesn't work for me, as with udev-117, kernel-2.6.22-suspend2-r2, x11-drivers/synaptics-0.14.6. X reclaims that nothing found on the link /dev/input/appletouch. Best was till now to drop external mouse support in xorg.conf, but occasionally touchpad still don't work. even suspend2ram doesn't wake up always, so i switched to suspend2disk. see also this bugs maybe regarding to this issue: [4] [5]

Alternate Partitioning Method

This method is real handy at removing the 4 partition limit. However it is experimental and has some concerns about upgrading to Leopard...

Alternate Partitioning method 2

Important Informations

It must be noted that bootcamp can only boot on the four first partitions. So if you use this method make sure you install all the OSes that must boot using a bios on the first partitions.

Note: Windows will not be able to see more than these 4 partitions, and the gentoo gentoo live too if you don't launch parted and modify the partition scheme (this will cause issues with grub installation).

I don't know if it works if you do your partitions scheme at the Mac OS X installation.

You must have Bootcamp installed but rEFIt is only needed to dualboot/tripleboot OSX.


Reinstalling completely Mac OS X (and keeping it)

If you don't want to get rid of Mac OS X you should make one small partition with the Mac OS Installer's Diskutility (menu Tools during the installation) to install Mac OS X on it (I haven't tested to make all the partitions directly so I can't guarantee it works, but you can make 3 partitions without any concern).


Not Reinstalling Mac OS X

If you don't want to reinstall Mac OS X, you can use the diskutil program on Mac OS X to resize the partition (or the bootcamp assistant graphical frontend). And continue normally.


Linux only install

You only need to update Mac OS X and install Bootcamp.

You will need rEFIt, so download the bootable iso and burn it to a CD.

Then, after booting the gentoo livecd launch parted and suppress the partition 2 (Do not touch the first partition it is where bootcamp resides !).

Note: If you get rid of the Mac OS X partition you will have a folder with a interrogation mark on it, to suppress it you only need to boot you mac with Mac OS X on an external drive


Gentoo Installation

Note: Remember that bootcamp can only boot the mac from the 4 first partitions (as the first of all is the Apple extension for the EFI you need to install the /boot partition to one of these)

When on the livecd terminal you only need to partition your hard drive using parted and then follow installation instructions with one difference.

When configuring the kernel make sure you have some options activated.

 File systems  --->
   Partition Types  --->
     [*] Advanced partition selection
     [*]   Macintosh partition map support
     [*]   PC BIOS (MSDOS partition tables) support
     [*]   EFI GUID Partition support

Then just before installing grub you will need to use the rEFIt partition tool. So reboot using rEFIt and select partition tool.

Note: If you try to install grub before using the rEFIt tool you will get an error.

Now rEFIt will show you the GUID partitions (all of them) and say that the MBR is different (showing only one entry) and propose you to update with a new MBR showing 4 entries : accept.

Note: If you hold the trackpad button when booting the mac will eject the CD. This is useful if you need to boot the CD version of rEFIt.

Now you can reboot the gentoo livecd chroot to the target like explained in the handbook. And install grub normally.

Troubleshooting s2ram or direct rendering (i810 driver related problems)

I had problems using xorg-server version 1.3.0.0-r2 and xf86-video-i810 version 2.2.0. The first error was direct rendering not able to work, with a similar error in /var/log/Xorg.0.log :

drmOpenDevice: node name is /dev/dri/card0
drmOpenDevice: open result is 9, (OK)
drmOpenByBusid: Searching for BusID pci:0000:00:02.0
drmOpenDevice: node name is /dev/dri/card0
drmOpenDevice: open result is 9, (OK)
drmOpenByBusid: drmOpenMinor returns 9
drmOpenByBusid: drmGetBusid reports pci:0000:00:02.0
(EE) AIGLX error: drmMap of framebuffer failed (Invalid argument)(EE) AIGLX: reverting to software rendering

The second error was when suspending with s2ram; after resuming from suspend, X was not starting, showing the following error :

(WW) intel(0): ESR is 0x00000001, instruction error
(WW) intel(0): PRB0_CTL (0x0001f001) indicates ring buffer enabled
(WW) intel(0): PRB0_HEAD (0x00000000) and PRB0_TAIL (0x00000020) indicate ring buffer not flushed
(WW) intel(0): Existing errors found in hardware state.
Error in I830WaitLpRing(), timeout for 2 seconds
pgetbl_ctl: 0x3ffc0001 pgetbl_err: 0x0
ipeir: 0 iphdr: 10000
LP ring tail: 28 head: 0 len: 1f001 start 0
eir: 0 esr: 1 emr: ffff
instdone: ffc1 instpm: 0
memmode: 306 instps: 2014c0
hwstam: ffff ier: 0 imr: ffff iir: 0
Ring at virtual 0x20612000 head 0x0 tail 0x28 count 10
0001ff80: 00000000

I have fixed those two issues by downgrading xf86-video-i810 to version 2.1.1.

A better solution than downgrading is making sure your Xorg is upgraded to 7.4

Links

Retrieved from "http://www.gentoo-wiki.info/Apple_MacBook"

Last modified: Sat, 11 Oct 2008 14:58:00 +1100 Hits: 171,786

Created by NickStallman.net, Luxury Homes Australia
Real estate agents should list their apartments, townhouses and units in Australia.