You are not logged in.

#1 2011-04-29 22:12:03

mikezackles
Member
Registered: 2007-09-23
Posts: 41

HOWTO: grub2 Macbook 7,1 pure efi triple boot

This install has been a little painful, so I figured I'd document it as best I can in case others might find it helpful.  I'm going from memory, and I've been working on it off and on over the course of several weeks, so there are probably some gaps/inaccuracies.  There might be easier ways to do some things too.  This was kind of a crash course in efi for me.

This probably goes without saying, but use this information at your own risk.

Follow the macbook wiki entry as far as partitioning and installing Windows.  (I installed Windows 7).  I installed refit first, but I guess there may be other ways to do it.

For the Arch install, I was unable to boot from USB, so I burned a CD.  (The USB boot issue may just be with refit).  I also wasn't able to boot the regular install image, and I had to use the latest archboot iso.  As best I can tell, refit doesn't really fully support this Macbook model yet, so you may have to reboot a few times before it recognizes the CD.  That's OK though because we're going to install grub2 and ditch refit anyway.

I chose ext4 for my arch partition, and I could not get refit to boot from a grub install on this partition at all, efi or not.  My initial solution was to put my grub install on the fat32 efi partition (sda1).  I put the grub files in /efi/grub, and refit picked them up immediately.  I later ended up moving grub to my OSX partition, so you may be able to just put grub there to start with.

Grub has a function called appleloader that allows you to "legacy" boot from CD, HD etc. using the firmware, but it does not work out of the box on this macbook model.  My goal was to boot directly from grub2, so this wasn't acceptable for me.  I poked around in the grub2 source and did some cross-referencing with refit, and I concluded that there was a problem with (I think) the memory map grub uses to interface with the apple firmware.  I was able to extract this data in OSX using some google-fu, and I added support to the grub2 source.  Works great for me.  You can get the patch here.

These grub compilation directions are more or less copied from here, but the site's down right now so I figured I'd just include them:

bzr branch --revision -2 bzr://bzr.savannah.gnu.org/grub/trunk/grub grub
cd grub
./autogen.sh
patch -p1 < appleloader_macbook_7_1.patch
export EFI_ARCH=x86_64
./configure --with-platform=efi --target=${EFI_ARCH} --program-prefix=""
make
cd grub-core
../grub-mkimage -O ${EFI_ARCH}-efi -d . -o grub.efi -p "" part_gpt part_msdos ntfs ntfscomp hfsplus fat ext2 normal chain boot configfile linux multiboot
cp grub.efi *.mod *.lst yourinstalllocation

Here is my grub.cfg:

set debug=video
insmod efi_gop

menuentry "Arch Linux EFI" {
  set root=(hd0,3)
  #search --set -f /boot/vmlinuz26-efi-physical
  loadbios /boot/vbtrace_bios.bin /boot/int10.bin
  linux /boot/vmlinuz26-efi-physical root=/dev/sda3 reboot=pci resume=/dev/sda3 resume_offset=151552
  initrd /boot/kernel26-efi-physical.img
}

menuentry "MacOSX" {
  set root=(hd0,2)
  # Search the root device for Mac OS X's loader.
  #search --set -f /usr/standalone/i386/boot.efi
  # Load the loader.
  chainloader /usr/standalone/i386/boot.efi
}

menuentry "Windows 7" {
  appleloader HD
}

menuentry "Arch Linux" {
  search --set -f /boot/vmlinuz26
  fakebios
  linux /boot/vmlinuz26 root=/dev/sda3 noefi video=efifb reboot=pci
  initrd /boot/kernel26.img
}

menuentry "Boot from CD" {
  appleloader CD
}

menuentry "Boot from USB" {
  appleloader USB
}

Please let me know if you know of a better way to load Windows.  I tried to use the windows efi file, but I got a black screen.  I think that may have been because I didn't build my grub.efi with all the necessary modules the first time though.

In order to boot without the noefi kernel param, I had to apply this patch.

Once you have grub the way you want it, you need to boot OSX, uninstall refit, and bless your grub install.  My grub files are now at /efi/grub on my OSX partition, so I just ran

sudo bless --folder /efi/grub --file /efi/grub/grub.efi

I spent several days trying to get the nvidia blob to work with X.  There's a grub command called loadbios that (I believe) is intended to load a video bios dump from a file, but it didn't seem to help.  In addition, I got a wide array of bios dumps from various methods recommended on the internet.  First I tried using dd.  Grub reported that as loading successfully, but it didn't help as far as running X.  The nouveau project recommends using vbtracetool, and it gave me two different dumps (one from shadow ram).  The vbtracetool dumps would not load in grub, so I investigated the source again.  It turns out that the
minimum size grub will load is 64K, so I changed it to 32K, and the dumps loaded successfully.  But they didn't help with X, so I (finally) gave up on nvidia and moved on to nouveau.  If anyone gets this working, *please* let me know.

Nouveau is working quite well for me so far, but dri does not work without the git packages from AUR.  If I remember correctly, you can get it all as split packages from mesa-git.  There are a few artifacts around the edges of my transparent urxvt terms, but it's not a huge deal.

The macbook wiki suggests using xf86-input-multitouch-git, but this driver has zero configuration options without recompiling it, and (for me) has serious issues with false clicks registered from palm touches.  Luckily, there is a recent fork of this driver that is in my opinion a *huge* improvement.  I set up an AUR package at xf86-input-mtrack-git.  By default /etc/X11/xorg.conf.d/10-mtrack.conf is vanilla, but I'm really happy with the following additional options:

Option "Thumbsize" "50"
Option "ScrollDistance" "100"

This driver has palm touch detection, but there are still some false click issues.  I have a guess as to why, but this post is already really long smile That said, the developer seems quite active at the moment, and I think it is already quite usable.

I had to make this change to pommed.conf to get the brightness keys working better:

# sysfs backlight control
# nVidia machines, will fall back to nv8600gmt if not supported by the kernel
lcd_sysfs {
    # The sysfs backlight control is a generic interface provided
    # by the Linux kernel for backlight control on most graphic cards.
    # The brightness range can differ depending on the hardware.

    # initial backlight level [12] (0 - 15, -1 to disable)
    init = -1
    # step value (1 - 2)
    #step = 1
    step = 800
    # backlight level when on battery [6] (1 - 15, 0 to disable)
    on_batt = 1800
}

I still need to fiddle with it, because it thinks the maximum brightness is way too high, so you have to hit the decrease key a bunch of times before it starts having any effect.  Other than that, pommed pretty much just works for me so far (brightness, volume, and eject).

I'm sure I've left stuff out.  Please feel free to add!

Offline

#2 2011-04-29 23:28:46

Haptic
Member
Registered: 2009-09-03
Posts: 149

Re: HOWTO: grub2 Macbook 7,1 pure efi triple boot

You should move this over to the wiki. Much easier to find that way.

Offline

#3 2011-04-30 00:26:23

mikezackles
Member
Registered: 2007-09-23
Posts: 41

Re: HOWTO: grub2 Macbook 7,1 pure efi triple boot

Thanks for the tip, Haptic.  I'll try to set something up tomorrow.

Offline

#4 2011-04-30 16:19:11

mikezackles
Member
Registered: 2007-09-23
Posts: 41

Re: HOWTO: grub2 Macbook 7,1 pure efi triple boot

I've done my best to add most of this to the main Macbook wiki.

Offline

#5 2011-05-02 18:16:54

staticnature
Member
Registered: 2011-04-23
Posts: 7

Re: HOWTO: grub2 Macbook 7,1 pure efi triple boot

Theres no need to compile Grub2, you can use the binary package Arch Linux provides by the name of `grub2-efi-x86_64` works just as well (on a MBP 6.2 + 7.1). You can also name the EFI image to `/efi/EFI/BOOT/BOOTX64.EFI` to boot directly from the Apple Bootloader without using bless (under Apple BL its picked up as EFI Root).

Most of the Macbook drivers seem to be fairly unstable under EFI though, especially 3d graphics with the Nvidia chip.

Last edited by staticnature (2011-05-02 18:38:18)

Offline

#6 2011-05-03 13:47:39

mikezackles
Member
Registered: 2007-09-23
Posts: 41

Re: HOWTO: grub2 Macbook 7,1 pure efi triple boot

Thanks, staticnature -- I will try that out if I get a chance.  I would like to use a binary package, but I also don't really like the idea of chaining extra bootloaders together if I can avoid it.

Offline

#7 2011-05-03 13:51:02

mikezackles
Member
Registered: 2007-09-23
Posts: 41

Re: HOWTO: grub2 Macbook 7,1 pure efi triple boot

That should probably be included in the wiki though.

Offline

#8 2011-05-05 21:46:01

mikezackles
Member
Registered: 2007-09-23
Posts: 41

Re: HOWTO: grub2 Macbook 7,1 pure efi triple boot

Update:

I ended up going for bios emulation because the nouveau dri wasn't cutting it for running vms.  As best I can tell, the apple firmware loader just loads the first partition marked as bootable in the hybrid mbr, so I couldn't get the efi grub to boot both windows and linux.  The same thing happens for me in refit -- it sees both the windows and linux installs, but selecting either one just boots the first partition marked as bootable.  Maybe that's just something screwy particular to my system though.

The problem above made me come to the conclusion that I've pretty much got to chain bootloaders together if I want to triple-boot.  I guess grub-bios needs it's own partition on a gpt disk, and I also noticed a note on the gentoo wiki that recommends using lilo, so I went with lilo for booting both arch and windows.  It works great.  (I also didn't want to try to deal with more than 4 partitions with the hybrid mbr setup).

This setup works with the apple bootloader, but I wasn't able to set it as my startup disk in os x (I guess because lilo is installed to my linux partition).  I didn't want to get stuck booting into os x every time I forget to hold down the option key, so I stuck with my original grub-efi install.  That way I can also still boot arch in efi mode without jumping through any extra hoops/bootloaders.  I guess refit would probably be fine too, but I didn't see an entry for this particular model in it's source, and it's behaved kind of erratically for me, so I'm sticking with grub for now.

The appleloader patch has been accepted into grub, so it may be possible to just use the bzr version.

I also noticed that after I upgraded to 4GB memory, linux only reports 3702MB, even though the graphics card should only be using 256MB.  I'm not sure what's up with that, but maybe it's normal.  OS X and Windows both report the correct amount.  And memtest86+ reports 3836M if I remember correctly.

Offline

#9 2011-05-07 13:14:14

staticnature
Member
Registered: 2011-04-23
Posts: 7

Re: HOWTO: grub2 Macbook 7,1 pure efi triple boot

mikezackles wrote:

Thanks, staticnature -- I will try that out if I get a chance.  I would like to use a binary package, but I also don't really like the idea of chaining extra bootloaders together if I can avoid it.

Directly booting from the Apple Loader to Grub2 is the best way to go since its the only loader on a mac that needs to happen (like the BIOS on a PC), even rEFit boots from the Apple Loader -> rEFIt (you can hold 'alt' whilst booting and reach the Apple Loader selection before rEFIt will load).

mikezackles wrote:

I ended up going for bios emulation because the nouveau dri wasn't cutting it for running vms.  As best I can tell, the apple firmware loader just loads the first partition marked as bootable in the hybrid mbr, so I couldn't get the efi grub to boot both windows and linux.  The same thing happens for me in refit -- it sees both the windows and linux installs, but selecting either one just boots the first partition marked as bootable.  Maybe that's just something screwy particular to my system though.

I reached the same conclusion as yourself yesterday and reverted my Macbook 7.1 back to BIOS booting, as nice as it is to have both GPU's working the stability seems to take a massive hit. I was hoping to boot via Grub2 EFI and then use the noefi kernel option to load in legacy mode so I could keep the same install whilst playing with EFI and fallback to legacy when I need a stable system, but there still seems to be stability issues. So for now its back to Legacy booting from the Apple Loader, hopefully EFI support on the Mac's will be improved in the future!

Offline

#10 2011-05-07 13:43:39

mikezackles
Member
Registered: 2007-09-23
Posts: 41

Re: HOWTO: grub2 Macbook 7,1 pure efi triple boot

staticnature wrote:

I was hoping to boot via Grub2 EFI and then use the noefi kernel option to load in legacy mode so I could keep the same install whilst playing with EFI and fallback to legacy when I need a stable system, but there still seems to be stability issues.

This is why I've kept my grub install.  I boot directly to grub, and from there I can either boot OS X, boot Arch in efi mode, boot from CD/USB, or launch lilo.  Then from lilo I can either boot arch in bios mode or boot windows.  I'll admit it's kind of ugly, but it gives me the most flexibility.

staticnature wrote:

you can hold 'alt' whilst booting and reach the Apple Loader selection before rEFIt will load

I'm going to try this now with my grub install and see what happens.  It loads grub pretty quickly though.  Either way I think I'll keep grub just so I don't have to remember to hit the option/alt key all the time.  (99 times out of 100 I want to boot Arch and not OS X).

Edit: Yup, this works.  I think I'd consider dropping grub for this if I could get it to boot lilo by default.

staticnature wrote:

So for now its back to Legacy booting from the Apple Loader, hopefully EFI support on the Mac's will be improved in the future!

Amen to that!  It'd be nice if Apple would move to EFI 2.0 too so that we could avoid this hybrid mbr nonsense altogether.

Last edited by mikezackles (2011-05-07 13:50:29)

Offline

Board footer

Powered by FluxBB