Apple Macbook Pro Retina (early 2013)

Macbook Retina Models
The 13 and 15 inch models are slightly different. The 15 inch model is more complicated, as it has both an Intel and an nVidia graphics card. The setup steps common to both are here, and specifics are separated off below:


 * Macbook Pro Retina 13inch 10,x
 * Macbook Pro Retina 15inch 10,x

In theory, the steps here should be very similar to the 11,x model.

Installation Steps
These instructions will perform a Dual Boot setup with MacOS. A single boot installation could be performed, but you will need to use the rEFIt instructions for installing rEFIt to the EFI system partition using bless instead of to the MAC partition (which is the default). I have not tried this yet but you can read about it on the rEFIt website.

Preparation
We will be bootstrapping using Ubuntu. Grab a mac image and flash it to a USB drive. SD cards don't seem to work.

To connect to ethernet, you'll need a thunderbolt adapter, which will have to be plugged in from boot (hotplugging doesn't seem to work).

Use MacOS Disk Utility to resize the MacOS partition on the fly, which by default takes up most of the disk, and behind it create your Linux root partition of the size you desire. Note: if you have full disk encryption, you will need to temporarily disable it (takes a while) to make any changes to the partition table.

Now, choose a bootloader so that you can boot the liveUSB and the kernel we'll be making later.

Bootloader
Now you must choose your a EFI boot manager. Currently Apple's Bootcamp doesn't support linux. However there are two option for you: rEFIt and rEFInd.

Using Refit
Refit it is very easy to install however be aware that it is dead. There is longer any active development for it. I can confirm that is works well with OSX Mountain Lion however it's untested on OSX Mavericks which it hasnt been tested on. If you want to install it go here.

A major drawback of this method is that you cannot use an initramfs, so if you have lvm or encryption then you must use rEFInd.

You cannot pass kernel arguments using rEFIt, so it is useless on 15 in macbooks where kernel arguments are required (unless you hardcode all arguments, which is very cumbersome).

In this method, the Mac app rEFIt will act as the boot manager/boot loader and it will boot the kernel directly.

Use at least a 3.7 Kernel. The wireless drivers you need later do not compile with a kernel greater than 3.8 at the present time.

Complete the rest of the gentoo installation, and reboot. rEFIt should show Gentoo_37_x64.efi as an option in the boot menu.

Using Refind
Refind which is a fork of Refit and is being actively development and maintained. For installation see follow this link.

This option is recommended for 15 inch versions, as it allows for passing kernel parameters.

Setting up rEFInd must be done from OSX. Essentially it boils down to:

Getting rEFInd
 * Go to http://sourceforge.net/projects/refind/files/
 * Get the latest binary zip
 * Extract it

Installing rEFInd

Configuring rEFInd

Later, once you've built a kernel, you'll need to edit (from within Linux) to add your kernel, as you would with GRUB

You can (and probably should) have several entries, and can edit this file from within linux.

Just compile your kernels normally and install them to EFI/gentoo on the efi partition.

LiveUSB Bootstrap
Now that the bootloader has been installed and the disk is prepared, we are ready to start bootstrapping.

Shut down the Mac, and boot it up twice (Requirement for rEFIt). You should start seeing the rEFIt or rEFInd boot menu after the second reboot.

Now, plug the Ubuntu USB stick into the Mac and boot the Mac. Select the new option in the menu which should be the USB stick. If there are multiple options, keep trying until you get one that boots. At the Ubuntu boot screen, press to disable apic, or you may experience random crashes.

When it boots, most everything should work except the sound on the liveCD.

Proceed with a standard Gentoo install using the Ubuntu live environment. Install your snapshot into the root partition you created (Probably ) and configure it per the installation instructions but do not install the boot loader. Note that by default the EFI system partition will be, Apple root will be and Apple recovery will be.

Kernel Configuration
If you are going to use rEFIt, make sure you

I've included my 3.14 kernel config as a reference, which supports:
 * Open source intel and nvidia drivers
 * Apple magic mouse
 * LVM
 * LUKS encryption
 * Bluetooth
 * Everything below

These options are in addition to the standard options you would select for Intel based PC's

Configure your kernel as normal, but add the following options for EFI Stub (needed for rEFIt or rEFInd), More details about Kernel configuration for EFI stub are here: EFI stub kernel:

Ensure the following options are NOT set (required for proper Broadcom wireless):

If and only if you are using rEFIt, specify the root hardcoded in the kernel:

Processor type and features ---> [*] Built-in kernel command line (root=/dev/sda4)

Make sure the root= line on your kernel command line configuration is correct.

Once configured, compile the kernel as normal but do not copy it to /boot. Once it is compiled, do the following:

Required for Audio: Add the following to the bottom of /etc/modprobe.d/alsa: options snd_hda_intel model=mbp101

Installing the kernel
Your built in Macbook SSD should be /dev/sdb if you booted from the Ubuntu USB which will probably be /dev/sda. Assuming it is /dev/sdb, your "EFI System Partition" will be /dev/sdb1, in which case, copy it to the EFI partition as such:

mkdir /mnt/efi mount /dev/sdb1 /mnt/efi cp /usr/src/linux/arch/x86_64/boot/bzImage /mnt/efi/EFI/Boot/Gentoo_37_x64.efi

If you used rEFInd and need an initramfs, copy it over too, and update refind.conf to have a matching menu entry.

It's a good idea with rEFInd to keep a few working kernels around, in case you bork one - this way you can get back in to rescue the system.

Wireless Drivers
There are two driver options for wifi.

- The BCM 4331 is supported by opensource in kernel driver B43. NOTE: Only B/G modes are supported by the in-kernel driver. 802.11n is not supported. To install disgrade the up listed kernel option for wireless and follow this https://wiki.gentoo.org/wiki/Wifi

- You can use Broadcom closed source driver. In which case please disable kernel as detailed above. This driver supports 802.11n. NB broadcom driver must be verison 6.30.223.30 or higher

NB: Only broadcom-sta supports 802.11n at time of writing (Aug 1 2013).

The broadcom-sta driver will have to be recompiled each time you upgrade your kernel.e

Media keys
We will control the media keys using xbindkeys. Create an .xbindkeysrc in your home directory with the options mentioned. You can also use xbindkey -k to generate new mappings. To install, add "xbindkeys" to your .xinitrc. You can access function keys by holding the "fn" modifier in the bottom left of the keyboard.

We'll also need to create a local.d script:

/etc/local.d/01-keyboard.start : /usr/bin/setpci -v -H1 -s 00:01.00 BRIDGE_CONTROL=0 #http://askubuntu.com/questions/370857/cant-adjust-screen-brightness-on-macbook-pro-10-1- ubuntu-13-10 /bin/chmod a+w /sys/devices/platform/applesmc.768/leds/smc\:\:kbd_backlight/brightness /bin/chmod a+w /sys/class/backlight/gmux_backlight/brightness
 * 1) !/bin/bash

Keyboard backlight
Install xbindkeys and add the following to your xbindkeysrc

"/usr/bin/kb-brightness down" m:0x0 + c:237

"/usr/bin/kb-brightness up" m:0x0 + c:238

kb-brightness: kbdb='/sys/devices/platform/applesmc.768/leds/smc::kbd_backlight/brightness' step=25 current=`cat $kbdb` new=$current if [ "$1" == "up" ];then new=$(($current + $step)) elif [ "$1" == "down" ];then new=$(($current - $step)) fi if [ $new -le 0 ];then new=0 fi echo $new > $kbdb
 * 1) !/bin/bash

Display backlight
Note: this will not work with the proprietary Nvidia graphics driver by any known method.

Add the following tho .xbindkeysrc:

"/usr/bin/bl-brightness down" m:0x0 + c:232

"/usr/bin/bl-brightness up" m:0x0 + c:233

bl-brightness: bldb='/sys/class/backlight/gmux_backlight/brightness' step=25 current=`cat $bldb` new=$current if [ "$1" == "up" ];then new=$(($current + $step)) elif [ "$1" == "down" ];then new=$(($current - $step)) fi if [ $new -le 0 ];then new=0 fi echo $new > $bldb current=`cat $bldb`
 * 1) !/bin/bash

Audio control keys
This assumes you are using alsa, and have your card properly configured:

Add the following to your .xbindkeysrc:

"amixer set Master playback 1+ unmute" XF86AudioRaiseVolume "amixer set Master playback 1-" XF86AudioLowerVolume "amixer set Master toggle" XF86AudioMute
 * 1) Increase volume
 * 1) Decrease volume

Keeping retina resolution
If you plan to use the retina display at native resolution on the 13" or 15" MBP, you probably want to make it a little more readable. To do this, most toolkits have DPI configuration. In KDE, you can find it in systemsettings>Application appearance>Font>DPI, set it at 160 for 1.5x resolution and 220 for 1.0x resolution (letting it at 96 will be equal to 2.0x resolution). For terminals such as xterm and urxvt, edit ~/.Xdefaults to add

Xft.dpi:      160 Xft.antialias: 1 Xft.hinting:  1 Xft.hintstyle: hintfull Xft.rgba:     rgb urxvt*font: xft:DejaVu Sans:pixelsize=16

For GTK, font size can be set in ~/.gtkrc-2.0. It can also share KDE settings when using oxygen-gtk.

Downscaling resolution
This will just globally cut the resolution in half, and provides a much more "normal" experience, while sacrificing the additional resolution. IMHO, this is totally worth it and actually works way better.

Add the following to your .xinitrc:

monitor=`xrandr | grep -i edp | cut -d " " -f 1` xrandr --newmode "1440x900_60.00"  106.50  1440 1528 1672 1904  900 903 909 934 -hsync +vsync xrandr --addmode $monitor 1440x900_60.00 xrandr --output $monitor --mode 1440x900_60.00

Turn off backlight when screen closed
The hardware does not automatically shut off the backlight like other laptops. Make the following change. Edit /etc/acpi/default.sh and find the commented #lid) section, the lid) case should look like this: lid)  xset -display :0 dpms force off   ;;

In addition, edit /etc/X11/xinit/xinitrc.d/00-xhost and add the following line to the bottom of the file. This gives root permission to run xset.

xhost +local:0 > /dev/null 2>&1

Restart ACPID and the X server for this to take effect.

What's Not Yet Working
Everything I can think to test works, except the following: [16032.337737] mmc0: Switching to 1.8V signalling voltage failed, retrying with S18R set to 0 [16049.257421] mmc0: error -110 whilst initialising SD card
 * Thunderbolt does not work with hotplug. Boot with the adapter connected.
 * The SD card reader is giving me some troubles. It works fine with some cards but I am having errors with other cards. But it does seem to work sometimes. I get the following:

Resources
The arch linux wiki is a very good reference If you're interested in setting up an encripted rootfs on lvm funtoo has a great article.