Installing Linux on a mid-2010 MacBook Pro

From WTFwiki
Jump to navigation Jump to search

Notes on installing Arch linux on a mid 2010 macbook pro, because I don't like OSX.

Partition the disk

  • Applications->Utilities->Disk Utility
  • Select your *drive*, not the 'Macintosh HD' partition
  • Click on the 'Partition' tab along the top
  • Drag and drop or type the size in the box to resize your OSX partition
  • Click apply

Install rEFIt

Change default boot order, optional

If you don't want refit to boot to OSX by default, edit /efi/refit/refit.conf and uncomment the 'legactfirst' option.

Installing Linux

I'm using Arch Linux. If you don't want to use that then things may become increasingly out of sync for you from now on.

Also note that you will want to use wired networking for setup, the wireless card probably won't work (yet).

After installing refit and burning a linux CD, *shutdown* the computer, a reboot is not good enough.

When you boot it back up, the refit bootsplash should show up. Use the partition inspector to sync the EFI partition table with the MBR.

Reboot from the refit menu and hold C down to boot from the linux CD.

Arch linux will display a GRUB prompt, just pick whatever the default is.

When you get a shell, run parted, you have to partition things manually.

 parted /dev/sda

Use 'print' to view the current partition table, and 'mkpart' to create partitions. You'll probably want to make a swap and a main partition, more if you feel ambitious, although I think having more than 4 partitions can cause headaches.

After doing this, you need to reboot and use refit's partition utility again to sync EFI and the MBR.

Reboot back into the Arch installer and do /arch/setup. Walk through the setup until it gets to 'Prepare Hard Drive'. Chose the 'Manually configure block devices' option and setup your swap and / partitions (they should be sda3 and sda4). Chose the right filesystems and mount points.

Continue on with the installation, chose GRUB as the bootloader when prompted. If you want to view detailed progress you can use fn-alt-f7 to switch to that virtual terminal, and fn-alt-f1 to switch back. I didn't bother installing anything other than the 'base' metapackage.

Do *NOT* setup the bootloader. Exit the installer and go back into refit and sync the partitions again (last time, I promise). Then boot back into the arch shell:

 mount /dev/sda4 /mnt
 mount -o bind /dev /mnt/dev
 chroot /mnt
 grub

At the grub shell, do the following (I assume your linux / partition is sda4):

 root (hd0,3)
 setup (hd0,3)
 quit

Reboot again, and the linux option should boot you into grub, from whence you can boot into linux.

2012 macbook

Make sure you use a recent ArchLinux install CD. You may run into a bug where, during partition selection, you get duplicate entries. The way to fix this kind of sucks, but it works.

Right before you go to the part where you have to choose the existing partitions (the menu item above that, disk selection or whatever) you need to switch to a different virtual terminal (fn-ctrl-alt-f2) and edit /tmp/aif/aif-blockdata to remove the duplicate entries. See https://bbs.archlinux.org/viewtopic.php?id=141795 for more information. I couldn't stop the installer and restart it to to fix it like suggested there, I had to do it live.

Configuring all the hardware

You might have to fiddle around with the GPG stuff for pacman (arch linux's package manager). You can look here for details: https://wiki.archlinux.org/index.php/Pacman-key Basically I had to pacman-key --init and then run pacman-key --populate archlinux. Alternatively you can edit /etc/pacman.config and set SigLevel=Never for everything.

X11

I prefer openbox as a window manager, so here's how I got it going

 pacman -S xorg-server xorg-xinit xterm nvidia

For the 2011 macbook you'll want xf86-video-ati instead of the nvidia module.

You'll need to reboot after installing the nvidia module, apparently.

Then you should be able to start an ugly default X11 environment with 'xinit'.

Touchpad

The better driver for the apple touchpad is the xf86-input-mtrack package from the AUR. The AUR are user-contributed package recipes you build yourself:

 pacman -S base-devel

And the dependencies for this actual package:

 pacman -S git xorg-server-devel mtdev

Download the tarball from https://aur.archlinux.org/packages.php?ID=48505 untar it, cd into the created directory and run 'makepkg'. A package tarball should be created, which you can install by doing

 pacman -U xf86-input-mtrack-git-20120604-1-x86_64.pkg.tar.xz

This is what my /etc/X11/xorg.conf.f/10-mtrack.conf looks like:

 Section "InputClass"
   MatchIsTouchpad "on"
   Identifier "Touchpads"
   Driver "mtrack"
   Option "Sensitivity" "0.5"
   Option "TapButton1" "0"
   Option "TapButton2" "0"
   Option "TapButton3" "0"
   Option "TapButton4" "0"
 EndSection

It makes things less squirrely and disables tapping to trigger a button click, you have to actually press down.

Audio

Make sure you're in the 'audio' group. Audio pretty much works out of the box. You might want to install pommed to get the audio shortcuts on the keyboard working.

Backlight control and other hotkeys

Pommed is a little tool that lets you use the F-row keys to do the secondary functions like on OSX, adjust volume, brightness, etc. You can find it in the AUR at http://aur.archlinux.org/packages.php?ID=14833

Pommed doesn't work with the 2011 macbook pro, however, nor does the backlight driver work out of the box.

For the backlight, you'll need https://aur.archlinux.org/packages.php?ID=57128 from the AUR.

To control the brightness of the backlight and the keyboard backlight, I wrote a little sh script:

#!/bin/sh

if [ $# -ne 2 ]; then
  echo "USAGE $0 </sys/device> <up|down>"
  exit 1
fi

echo `whoami`

DEVICE=$1
DIRECTION=$2

if [ ! -d $DEVICE ]; then
  echo "$DEVICE is not a directory"
fi

if [ -f $DEVICE/brightness ]; then
  BRIGHTNESS=`cat $DEVICE/brightness`
  #BRIGHTNESS=0
else
  echo "$DEVICE/brightness does not exist"
  exit 1
fi

if [ -f $DEVICE/max_brightness ]; then
  MAX_BRIGHTNESS=`cat $DEVICE/max_brightness`
else
  echo "$DEVICE/max_brightness does not exist"
  exit 1
fi

echo "$DEVICE brightness is $BRIGHTNESS/$MAX_BRIGHTNESS"

#STEP=`awk "BEGIN{ printf(\"%d\n\", $MAX_BRIGHTNESS / 30) }"`

#echo "Step is $STEP"

if [ "x${DIRECTION}" = "xup" ]; then
  #NEW_BRIGHTNESS=`awk "BEGIN{ print $BRIGHTNESS + $STEP }"`
  if [ $BRIGHTNESS -lt 1 ]; then
    NEW_BRIGHTNESS=`awk "BEGIN{ printf(\"%d\n\", $MAX_BRIGHTNESS / 128) }"`
  else
    NEW_BRIGHTNESS=`awk "BEGIN{ print $BRIGHTNESS * 2 }"`
  fi
else
  if [ "x${DIRECTION}" = "xdown" ]; then
    #NEW_BRIGHTNESS=`awk "BEGIN{ print $BRIGHTNESS - $STEP }"`
    NEW_BRIGHTNESS=`awk "BEGIN{ printf(\"%d\n\", $BRIGHTNESS / 2) }"`
  else
    echo "Direction $DIRECTION is invalid"
    return 1
  fi
fi

echo "New brightness is $NEW_BRIGHTNESS"

if [ $NEW_BRIGHTNESS -gt $MAX_BRIGHTNESS ]; then
  NEW_BRIGHTNESS=$MAX_BRIGHTNESS
fi

if [ $NEW_BRIGHTNESS -lt 0 ]; then
  NEW_BRIGHTNESS=0
fi

echo $NEW_BRIGHTNESS > $DEVICE/brightness

And added a sudo line to let me run that command as root with no password prompt:

andrew ALL=(root) NOPASSWD: /usr/local/bin/brightness.sh * *

Finally, I bound a bunch of the keys in openbox in rc.xml:

    <keybind key="XF86MonBrightnessDown">
      <action name="Execute"><execute>sudo /usr/local/bin/brightness.sh /sys/class/backlight/gmux_backlight down</execute></action>
    </keybind>
    <keybind key="XF86MonBrightnessUp">
      <action name="Execute"><execute>sudo /usr/local/bin/brightness.sh /sys/class/backlight/gmux_backlight up</execute></action>
    </keybind>

    <keybind key="XF86KbdBrightnessDown">
      <action name="Execute"><execute>sudo /usr/local/bin/brightness.sh /sys/class/leds/smc::kbd_backlight down</execute></action>
    </keybind>
    <keybind key="XF86KbdBrightnessUp">
      <action name="Execute"><execute>sudo /usr/local/bin/brightness.sh /sys/class/leds/smc::kbd_backlight up</execute></action>
    </keybind>

    <keybind key="XF86AudioMute">
      <action name="Execute"><execute>amixer set Master toggle</execute></action>
    </keybind>
    <keybind key="XF86AudioLowerVolume">
      <action name="Execute"><execute>amixer set Master 10%-</execute></action>
    </keybind>
    <keybind key="XF86AudioRaiseVolume">
      <action name="Execute"><execute>amixer set Master 10%+</execute></action>
    </keybind>

    <keybind key="XF86Eject">
      <action name="Execute"><execute>eject</execute></action>
    </keybind>

You could also bind the media-player keys if you wanted, I just didn't bother since I never use them.

Wireless

Recent kernels support the broadcom chipset used in the mid-2010 macbooks out of the box, to deal with WPA you can use something like wicd, which makes dealing with wpa-supplicant less agonizing.

The 2011 macbook wifi doesn't work out of the box, I had to use http://aur.archlinux.org/packages.php?ID=21690 from the AUR instead.

Power Saving

There's a lot of things you can do here. I'll focus more on the 2011 macbook since I don't use the 2010 one much anymore.

Video card powersaving: echo low > /sys/class/drm/card0/device/power_profile

...