Mactel: Linux on the MacBook Pro

It is much better to use bootcamp, at least if you have a windows install CD!

Please see http://www.sourcepoint.com.au/macintoo/forum for discussion about running linux on macbook pros.
I purchased a 2Ghz MacBook Pro with 1GB RAM and 100GB hard drive at the beginning of April 2006. I used Linux as the primary OS for a while, and have recorded some of my experiences here. I am not updating this site, so it will become out of date.

My email address is [email protected] and I welcome any comments about this website. I've made this as a hopefully-useful supplement to the excellent Wiki http://www.mactel-linux.org (no longer exists). The current website has the potential advantage that it's simpler to read than a Wiki, and the presentation is possibly more coherent.

I upgraded to kernel 2.6.17.6; here are the files I gathered from around the internet for this upgraded.

This website is mainly based on things I learned from http://www.mactel-linux.org, in particular, the (greatly appreciated!) hard work of Edgar Hucek (especially on kernel hacking). If you are considering using Linux on a MacBook Pro, you should definitely visit the above site and the user mailing list and developer mail list archives, and the sites linked to from them. This site on the Macbook (not pro) is very nice. Also this posting is very useful.

Windows XP?: I'm not running Windows XP on this computer. If you want to, you might find Apple's Boot Camp very interesting. Warning -- everything described on my web page here assumes you have not used Boot Camp to do anything; indeed, I wrote most of this before Boot Camp was released.

Warning: Note that you probably shouldn't exactly follow my instructions. They were written pre-bootcamp. There is a new proprietary fast graphics driver for the video card, but it only works if you setup your system using bootcamp (to enable BIOS emulation). Similar remarks apply to the new code that somebody wrote for adjusting the brightness.

NEW: I reconfigured my laptop to tri boot OS X/ XP / Linux. This was the only way I could find to have both OS X and Linux and get legacy BIOS emulation, so that I could get accelerated 3d graphics, etc. I took rough notes which you can find here.

Websites about Linux on Intel Macs

Setting up a Dual Boot OS X / Ubuntu Linux Machine

This is how I recall setting up my MacBook to dual boot to both Linux and OS X. It took me several tries and a lot of time over 3 days, so I probably remember fairly well what I did. However, if you try and find that a detail is slightly different, let me know so I can fix this!

What you need

  1. A MacBook Pro, whose hard drive you don't mind completely deleting. (Probably almost everything in this webpage applies to Intel iMac's. Also, there are ways around deleting the contents of your MacBook Pro's hard drive.)
  2. The install DVD's that come with your MacBook Pro.
  3. The 380MB Ubuntu-based Mactel Linux live-boot CD, specifically the March 26 one from this website, which I think (?) Edgar Hucek created. Everywhere in the rest of this webpage when I refer to the "live boot CD" I'm referring to this one. Things may be easier (or harder?) using a different live CD or version. I just assume the above CD for this website.

What to do

  1. Boot from the OS X install DVD. Delete all the partitions (and hence all your data, so beware!! -- if you do not want to lose all your data, backup first, or possibly use the parted program from the live linux boot CD to shrink your OS X partition). Create a 20GB OS X HFS+ journaled not-case sensitive first partition, then a 5GB OS X HFS+ not-journaled case-sensitive second partition. The first will be used for OS X, and the second for sharing a limited set of files between OS X and Linux.
  2. Run the OS X installer (use custom mode!) and install a reasonable subset of the software. I installed just the minimum along with the X server.
  3. After finishing the OS X install, boot your MacBook with the Linux live-boot CD in the drive whilst holding down the option key. Select Linux and boot it up.
  4. From the root prompt use parted (an excellent tool!) to create a 2GB Linux swap partition (using mkpart) and a 71GB ext2 partition (using mkpartfs). Don't worry about activating the swap partition.

    This is the output of parted on my computer after I got everything setup nicely.

    root@sha:/home/was/computer/macbook# parted /dev/sda
    GNU Parted 1.7.0rc1
    Using /dev/sda
    Welcome to GNU Parted! Type 'help' to view a list of commands.
    (parted) print
    
    Disk /dev/sda: 100GB
    Sector size (logical/physical): 512B/512B
    Partition Table: gpt
    
    Number  Start   End     Size    File system  Name     Flags
     1      20.5kB  210MB   210MB   fat32        primary  boot
     2      210MB   21.6GB  21.3GB  hfs+         primary
     3      21.6GB  27.0GB  5450MB  hfsx         primary
     4      27.0GB  29.0GB  2000MB  linux-swap   primary
     5      29.0GB  100GB   71.0GB  ext3         primary
    
  5. Format the ext3 partition, mount it, and copy over the contents of the live boot CD to it:
       $ mkfs.ext3 /dev/sda5
       $ mount /dev/sda5 /mnt
       $ cd /
       $ time cp -arv bin data  etc  lib media opt  sbin  srv  tmp  var boot  dev  \
               home root share  usr
    
    This will take a while and copies everything except the /proc and /sys filesystems, which are specially mounted by the kernel (and it makes no sense to copy them over). (If somebody does this, please email me with how long it took, since it should be the same for everyone.)
    (From Nathalie Casati)
    Just to say I followed your howto to install linux on a macbook
    pro. Here are my results for point 5 :
    
    real 2m57.428s
    user 0m0.236s
    sys 2m34.002s
    
  6. Type
       $ mkdir /mnt/share
       $ mkswap /dev/sda4
    
    then edit /mnt/etc/fstab so it looks as follows:
    # /etc/fstab: static file system information.
    # $Header: /home/cvsroot/gentoo-src/rc-scripts/etc/fstab,v 1.14 2003/10/13 20:03:38 azarah Exp $
    #
    # noatime turns off atimes for increased performance (atimes normally aren't
    # needed; notail increases performance of ReiserFS (at the expense of storage
    # efficiency).  It's safe to drop the noatime options if you want and to
    # switch between notail and tail freely.
    
    
    /dev/sda5		/		ext3		defaults 		0 1
    /dev/sda4		none		swap		sw			0 0
    
    /dev/sda2               /osx            hfsplus         auto,ro                 0 0
    /dev/sda3               /share          hfsplus            rw,users                 0 0
    
    #/dev/loop/0		/		squashfs	ro			0 0
    #/dev/cdroms/cdrom0	/mnt/cdrom	iso9660		noauto,ro		0 0
    #/dev/fd0		/mnt/floppy	auto		noauto			0 0
    
  7. Reboot your computer into OS X. Then set it up so it can dual boot both OS X and Linux as follows:
    1. Download rEFIt, and extract it to the root of your HFS+ OSX partition, then "bless" it (note that osx below may be different for you):
      $ cd /Volumes/osx
      $ sudo bless --folder . --file refit.efi --setBoot --labelfile refit.volicon
      
      Also, create a directory /Volumes/osx/Linux by copying the directory /efi/elilo from the Linux live boot CD. IMPORTANT! You must edit /Volumes/osx/Linux/elilo.conf or Linux won't be able to mount the root device when it boots up. In particular, you must have root=/dev/sda5 in your kernel append options (or /dev/sdax for approproriate x if you set things up differently than I did). Also, you can safely delete the initrd's, which are only needed for the live boot CD (as far as I can tell). But if you do that make sure not to list them in elilo.conf.
    2. Reboot. You should now have the choice of booting into either OS X or Linux. If you do not make a selection in 20 seconds, OS X will automatically boot up. As of 2006-04-03, the boot menu, options, and timeout seem to not be configurable (except probably by building your own custom rEFI boot program). Select Linux and boot up. You should boot up into your new hard-drive-installed Linux system. At this point typing startx should take you to a Gnome session.
    3. Configure your new Linux system, e.g., to get the machine to automatically start your favorite window manager with you logged in, etc. This is outside of the scope of this webpage, since it has nothing in particular to do with MacBooks. I do make a few MacBook-relevant remarks below though.

Compiling my own kernel

Here's how I compiled my own kernel from scratch. This is not strictly necessary, and is only needed if you want to attempt to improve support for the Linux kernel on the MacBook if you have time (i.e., if you are a kernel hacker).
  1. Download the "plain vanilla" linux kernel 2.6.16.1 (say) from www.kernel.org.
  2. Extract it to a directory and patch it with imac-2.6.16.patch, which is available here:
       cd linux-2.6.16.1
       patch -p1 < path-to-the-patch/imac-2.6.16.patch
    
  3. Grab the file config-2.6.16-imac from /boot on the live boot CD and put it as .config in the linux kernel directory, then type make oldconfig. Finally, build and install the kernel with
       make -j4
       make install
       make -j4 modules
       make modules_install
    
  4. Copy the resulting /boot/vmlinuz-2.6.16.1 file to your /share partition.
  5. Boot into OS X and copy the vmlinuz-2.6.16.1 file you just made to /efi/Linux and add the following to the elilo.conf file as the first entry:
    image=vmlinuz-2.6.16.1
            label=l
            description="Custom Linux 2.6.16.1"
            append="video=imacfb:i17 root=/dev/sda5 acpi=force libata.atapi_enabled=1 gpt"
    
The reason for the contortion above involving booting into OS X is that I don't consider this too big of an inconvenience, given how rarely I change the kernel.

Screen Brightness

The screen brightness buttons are not supported under Linux. If you turn the computer on from its off state, it boots into Linux at full brightness, which is incredibly bright. The first day I used the laptop I had to wear sunglasses to avoid getting a headache! (Fortunately the light is polarized in such a way that I can still see the screen through my polarized sunglasses.) Fortunately, there is a trick to reduce the screen brightness:
  1. Boot into OS X.
  2. Adjust the screen brightness.
  3. Apple Menu -- > Reboot (not Shutdown)
  4. Startup in Linux
The brightness should still be as you left it in OS X.

Obviously, I would be very happy if somebody figures out how to control the screen brightness directly in Linux! This would also be very good for improving battery life.

NewThere is now a new program that can be used to adjust the backlight.

Sharing Files Between OS X and Linux

The Linux kernel version 2.6.16.1 has a driver for providing read/write access to non-journaled HFS+ partitions. For copying and working with a few files it seems to work fine. But every time I tried anything really nontrivial, e.g., copying a large directory onto an HFS+ partition, the partition became hopelessly corrupted (so that the fsck and OS X disk utility programs couldn't repair it).

I highly recommend using only a small HFS+ partition for sharing files. There seems to currently (as of 2006-04-03) be no robust trustworthy file system that is supported by both Intel OS X and Linux 2.6.16.1, except FAT32, which doesn't support symlinks, users, etc. Since your personal data is probably extremely important, keep it in an ext3 partition.

Mapping the apple key to Alt (or whatever)

Use the command xev to find that the key codes for the left and right apple keys are 115 and 116. I just made them Alt keys by adding this to my $HOME/.xmodmap file:
keycode 115 = Alt_L
keycode 116 = Alt_R
You then have to run
   xmodmap $HOME/.xmodmap
to make this take effect. (You should add this somewhere that is run when you start X windows. What's a good place??)

NOTE: For some reason in KDE alt-tab works differently if I use the apple key instead of the actual alt(/option) key. I don't understand why. By differently, I mean that with the apple key alt-tab automatically switches to the last window, whereas with the alt(/option) key I get a list of windows and can page through them. Fortunately, Itai Seggev told me that the following more complicated xmodmap file does works perfectly for me. I've also put some bindings so function keys work.

       clear mod1
       clear mod4
       keycode 64 = Alt_L
       ! Set Enter to switch langujage group while depressed
       keycode 108 = Mode_switch
       ! Turn Command into Alt and Meta.
       keycode 115 = Alt_L Meta_L
       ! set modifier keys
       add mod1 = Alt_L Meta_L

       keycode 101 = F1
       keycode 212 = F2
       keycode 160 = F3
       keycode 174 = F4
       keycode 176 = F5
       keycode 214 = F7
       keycode 215 = F8
       keycode 216 = F9
       keycode 217 = F10

Gotchas

  1. To use the function keys press fn and the corresponding function key. Just pressing the function key sends the code for the hardware control (e.g., brightness, etc.), just like under OS X. However, under Linux none of the hardware controls actually do anything, so this can be a surprise (and took me a while to figure out).
  2. The middle mouse button is F11 (without pressing fn) and the right mouse button is F12.

X11

This is my xorg.conf file. Relevant mailing list discussion:
From: "Roberto Griso"
To: [email protected]
Subject: [Mactel-linux-devel] Another time to Ati Driver Question
Date: Fri, 21 Apr 2006 06:35:44 -0700

Hello, i try to install new ati driver on my linux system. The installation
on Xorg and the modprobe action for the fglrx module works very well, but
wharn i try to start an X session, it exits with the follow error message :

(EE) fglrx(0): No V_BIOS found
(EE) fglrx(0): PreInitInt10 failed
SetVBEMode failed
(EE) fglrx(0): R200PreInit failed
(EE) Screen(s) found, but none have a usable configuration.

Anyone has the same problem?

-------------
From: Matthew Garrett
To: Roberto Griso
Cc: [email protected]
Subject: Re: [Mactel-linux-devel] Another time to Ati Driver Question
Date: Fri, 21 Apr 2006 15:36:14 +0100

The ATI driver will only work under the legacy CRM, because it's horrid.
Please do bitch at ATI about this.

-------------
From: gimli
To: Roberto Griso
Cc: [email protected]
Subject: Re: [Mactel-linux-devel] Another time to Ati Driver Question
Date: Fri, 21 Apr 2006 16:36:57 +0200

You must boot with BootCamp to get the ATI driver work.

Suspend to Disk (or Hibernate or suspend2 or software suspend)

I got it to work robustly and reasonably quickly (after switching to using BIOS emulation via bootcamp). Here's a directory with some relevant config files. (Many thanks to Michael Kaufmann for help on this.) This is very nice since I can hibernate Linux and boot into either OS X or Windows, then resume where I left off in Linux. Now I get things like:
was@sha:~/install/macbook$ uptime
 12:36:07 up 4 days, 23:46,  1 user,  load average: 1.29, 0.71, 0.28
And I've booted into both OS X and Windows in the meantime!

No Support: Suspend to RAM

It works for me but not reliably; it will suspend and resume 3 or 4 times and totally hang on the fifth. I don't use this, since I want something robust. Also after resuming the acpi event detection is all messed up. With hibernate (see above) this isn't a problem.

Display to an external monitor

This works fine now (with bootcamp), even with accelerated 3d graphics. Here's my xorg.conf file.

No Support: Sound

I have not succeeded in playing any sound whatever under Linux, even by plugging in headphones. People are rumored to have got sound on the external output on some mactel machines.

CD/DVD Reader/Writer

The CD/DVD driver is a Matshita DVD-R UJ-857. It seems to be very well supported under Linux (via e.g., k3b). (But it's slow under Linux.??)

Virtual Machines

Virtual Machines Running on Linux

My copy of VMware runs perfectly under Linux on the MacBook Pro. Note that I had to compile my own kernel (as explained above) in order to configure VMware. So far I've run Linux, Windows, Solaris, etc. as virtual machines under VMware on my MacBook (which I use for software development).

Virtual Machines Running on OS X

The company Parallels makes a program for OS X that is a sort of stripped-down version of VMware. One can install Linux into it and run Linux in a window under OS X with not too much performance degredation. I would very much like to use this some but I can't right now because: I very much hope vmware is ported to OS X.

The Dreaded Whine? Yes

Many MacBook Pro users complain of hearing a horrible whine when using their MacBooks on battery power under OS X. This problem does occur on my MacBook under OS X (it's indeed awful!), but fortunately under OS X I deal with it using the C program here. Under Linux with Kernel 2.6.16.1 patched as described above the whine does occur when running on battery power, though it is not as bad as under OS X. Also, the script from the above website doesn't help.

Email

On Tue, 04 Apr 2006 02:15:16 -0700, Ryan Newton wrote:
> I am writing in response to your statement on the site that:
>
> "I highly recommend using only a small HFS+ partition for sharing
> files. There seems to currently (as of 2006-04-03) be no robust
> trustworthy file system that is supported by both Intel OS X and
> Linux 2.6.16.1, except FAT32, which doesn't support symlinks, users,
> etc. Since your personal data is probably extremely important, keep
> it in an ext3 partition."
>
> I'm curious, among the things you've tried, have you tried this
> implementation of ext2 for Mac OS?
>
> http://sourceforge.net/projects/ext2fsx/

I very much wanted to use that, but it didn't work for me.
I tried the binary available there, but was unable to get it to mount
any ext2 partition on my laptop (I tried a number of
different things with no success at all).  The program lists my
ext2 partitions, but always says they have errors that must be
fixed before they can be mounted (though they don't). I was
careful to try this with an ext2 (not ext3) partition.  My
guess is that perhaps the ext2fsx program has not been
completely adapted to work on Intel Macs, but I'm not sure.

In fact, the last update to the ext2 drivers on the sourceforge
website was in February and added support for OS X 10.4.  The comment
is that:

"1.4d1 is now available from the Files section (ext2fsx_dev package).
Read only support (for now) and be prepared for kernel panics
and/or system hangs.   I've been spending quite a few weekends
working on this, so any appreciation is welcome."

So even if the ext2 drivers did work they would be read-only right now,
and there would be system hangs.

 -- William


Notes from People

On Tue, 16 May 2006 10:17:28 -0700, Christopher Zwach wrote:

> I was looking through your site on running GNU/Linux on the MacBook
> Pro line of laptops from Apple  while doing some research into
> possible linux-usable laptops to take with me to college.  First off,
> I want to comment on how informative and helpful your site has been in
> my research.  I also wanted to mention that during additional research
> I was able to find an update that you may find useful regarding audio
> playback on the MacBooks.  Apparently, audio can be enabled to play
> through the headphone jack on the MacBook Pro by loading the
> snd-hda-intel module
> (http://forums.gentoo.org/viewtopic-p-3287309-highlight-sound.html#3287309).
>  However, playback through the built-in speakers still appears to
> remain unsolved.
> Enjoy!

Thanks for the tip.  Does it work for you with kernel 2.6.16.16
(which is what I'm using to get hibernate working).   Somebody who
got hibernate to work emailed to the list that sound worked with
2.6.16.9 but stopped working with 2.6.16.14, for some reason (?).

REGARDING VMWARE:

hello, big thanks for http://modular.math.washington.edu/macbook/
I won't bother you too long.
just want to know which build of vmware have you been able to
work with kernel 2.6.16.16 ?
everything works fine ? no crash ?
I have same macbook as you and want to work with linux everyday but
needs windows xp virtualization.

I am using kernel 2.6.16.16.  It's the latest VMware, build 19175 for
Linux.  It has been absolutely 100% rock solid for me so far; it's the best
VMware install/environment I've used.   And having a dual core processor
really makes things much nicer, since I can let something build on the
vmware machine while using Linux and not notice a slowdown.

On Mon, 22 May 2006 11:18:27 -0700, Chris Spencer wrote:
> Thank you very much for the time you spent to create the tutorial.  I now
> have an almost fully functional copy of Ubuntu working on my MacBook.  I
> have one problem that I'm curious if you encountered, and if you did how you
> resolved it.
>
> Currently whenever I boot, I automatically log in as root, and whenever I
> try to "logout" I, again, am automatically logged in as root.  I'm fairly
> new to the linux environment, so it may be an obvious fix that I am just not
> familiar with.
>
> Did you face this challenge when you made this tutorial?  If so did you find
> a resolution?

I had this problem (which is with the live boot CD) and I resolved it.
I don't remember at all what I did, except that it was fairly standard
(but possibly not at all obvious) Linux sysadmin work.   Once you have
KDE (say) up you can use the GUI to configure it to autologin as
a given user on startup.  That might solve your problem, assuming you've
made another user account.

Another problem is that sudo seems totally broken on the liveboot CD.
I got around this by downloading the source code to sudo and building
from source.  Much to my surprise that worked perfectly first try.

Date: Wed, 07 Jun 2006 16:43:23 -0400
From: Chris Tartamella
Subject: MBP Linux

First, I wanted to thank you for the useful info you've put on your
site.  It's been invaluable to me over the past week or so as I've
gotten Linux going on my MBP.  A few comments that might help the
novices/clear up some uncertainties:

1) After installing OSX and BootCamp, it is a REALLY good idea to
install rEFIt.  I know its not necessary, but it works so flawlessly
that I wouldn't install without it.

2) I haven't done this yet, but some notes on creating a swap file
under Linux?  3) Rather than use the mount --bind, I used chroot'd to
/mnt and installed lilo there through apt-get.  This might be cleaner?

4) If you use rEFIt, the part about doing the MBR in Windows is
unnecessary.

Some of these things i learned by combining your directions and others
on the mactel-linux site and probably a few others google unearthed
for me.  Alas, I have no links.

I do have a question though.  I'm trying to get my mouse buttons
mapped properly.  I've recompiled the kernel with the latest imac
patch from the site, and the keys in sysctl.conf are being read
properly.  However, when I read a keycode from xev and put that in
sysctl.conf and reboot, that key does not have the proper mapping.  In
fact, I've found that sometimes other keys get that mapping.  Did you
have this problem?  What keys are you bound to now (and what number if
I may ask.)

I had found a kernel patch (It's small and I've atached it here) meant
for ppc Macs.  This enables the Ctrl-Click and Option-Click as it is
found in Mac OS.  Some hacking is still required though.  I tried it
with mine and after rebooting with the new kernel my keyboard didn't
work at all.  Maybe this is of use to you?

Finally, have you had any luck with sound?

Thanks again for all the invaluable information.

Date: Fri, 9 Jun 2006 23:38:10 -0400
To: [email protected]
Subject: Re: Gentoo on the MacBook Pro

Hello William,
  I had finally committed to fixing my broken graphics support as I
do a considerable amount of professional and academic 3d development
and your site helped out a great deal.  Just sending a thank you!

Regards,
  Brandon Nardone
On Sun, 18 Jun 2006 03:32:52 -0700, Ludovic Rousseau
> I found your very nice page [1] and have some comments. I also have a
> Mac Book Pro (17").
>
> - If you have a file ~/.Xmodmap (note the capital X) it should be
> loaded automatically. At least I have this Under Debian.

Thanks!

> - Linux does not support HFS+ in write mode if the journalisation is
> used. I had to remove journalisation ("diskutil disableJournal /"
> under Mac OS X) to be able to write to my HFS+ partition. See [2].

I did this as well 3 times.    Each time after a few days of normal
uses I completely *trashed* my HFS+ partition.  It would work fine
from Linux but not OS X, and seemed beyond repair.  I had to completely
restart the entire install process to recover.   So use HFS+ in
write mode at your own risk.   (Things may have improved since April, though!)

> Bye,
>
> [1] http://modular.math.washington.edu/macbook/
> [2] http://gentoo-wiki.com/HOWTO_hfsplus#Disable_Journaling
Date: Mon, 26 Jun 2006 21:02:18 -0700
To: "Damien Sandras"
Subject: Re: Sound support
Reply-To: [email protected]
From: "William Stein"
Organization: University of Washington

On Mon, 26 Jun 2006 10:46:23 -0700, Damien Sandras wrote:
I would like to buy a new laptop, and would also like the Macbook Pro.

It's a great laptop!

However, I've read in your report that sound doesn't work. Does it work
now or are you still having problems?

It doesn't work for me yet, but other people report success.  I haven't
done anything to try though.  It probably works with sufficient work;
things are confusing and unstable though, since Linux support is new,
and work on it is pretty random.   I haven't actually had time to try
any of the new kernel patches since I've been so busy with my job
lately.

Also, have you been able to try the isight in the laptop?

I don't think anybody has had success with it yet under Linux.  Of course
it works fine under OS X.

william



I release this web page under the Gnu Free Documentation License.