Debian EFI mode boot on a Macbook Pro, without rEFIt

Diego’s post got me to switch from grub-pc to grub-efi to boot Debian on my Macbook Pro. But I wanted to go further: getting rid of rEFIt.

rEFIt is a pretty useful piece of software, but it’s essentially dead. There is the rEFInd fork, which keeps it up-to-date, but it doesn’t really help with FileVault. Moreover, the boot sequence for a Linux distro with rEFIt/rEFInd looks like: Apple EFI firmware → rEFIt/rEFInd → GRUB → Linux kernel. Each intermediate step adding its own timeout, so rEFIt/rEFInd can be seen as not-so-useful intermediate step.

Thankfully, Matthew Garrett did all the research to allow to directly boot GRUB from the Apple EFI firmware. Unfortunately, his blog post didn’t have much actual detail on how to do it.

So here it is, for a Debian system:

  • Install a few packages you’ll need in this process:
    # apt-get install hfsprogs icnsutils
  • Create a small HFS+ partition. I have a 9MB one, but it’s only filled by about 500K, so even smaller should work too. If, like me, you were previously using grub-pc, you probably have a GRUB partition, you can repurpose it. In gdisk, it looks like this:
    Number  Start (sector)    End (sector)  Size       Code  Name
       5       235284480       235302943   9.0 MiB     AF00  Apple HFS/HFS+
    
    Partition GUID code: 48465300-0000-11AA-AA11-00306543ECAC (Apple HFS/HFS+)
    Partition unique GUID: AD1F5465-B777-4178-AC4D-1DE8B2EB1B4B
    First sector: 235284480 (at 112.2 GiB)
    Last sector: 235302943 (at 112.2 GiB)
    Partition size: 18464 sectors (9.0 MiB)
    Attribute flags: 0000000000000000
    Partition name: 'Apple HFS/HFS+'
    
  • Create a HFS+ filesystem on that partition:

    # mkfs.hfsplus /dev/sda5 -v Debian

    (replace /dev/sda5 with whatever your partition is)

  • Add a fstab entry for that filesystem:
    # echo $(blkid -o export -s UUID /dev/sda5) /boot/efi auto defaults 0 0 >> /etc/fstab
  • Mount the filesystem:
    # mkdir /boot/efi
    # mount /boot/efi
    
  • Edit /usr/sbin/grub-install, look for « xfat », and remove the block of code that looks like:
    if test "x$efi_fs" = xfat; then :; else
        echo "${efidir} doesn't look like an EFI partition." 1>&2
        efidir=
    fi
    
  • Run grub-install. At this point, there should be a /boot/efi/EFI/debian/grubx64.efi file (if using grub-efi-amd64).
  • Create a /boot/efi/System/Library/CoreServices directory:
    # mkdir -p /boot/efi/System/Library/CoreServices
  • Create a hard link:
    # ln /boot/efi/EFI/debian/grubx64.efi /boot/efi/System/Library/CoreServices/boot.efi
  • Create a dummy mach_kernel file:
    # echo "This file is required for booting" > /boot/efi/mach_kernel
  • Grab the mactel-boot source code, unpack and build it:
    # wget http://www.codon.org.uk/~mjg59/mactel-boot/mactel-boot-0.9.tar.bz2
    # tar -jxf mactel-boot-0.9.tar.bz2
    # cd mactel-boot-0.9
    # make PRODUCTVERSION=Debian
    
  • Copy the SystemVersion.plist file:
    # cp SystemVersion.plist /boot/efi/System/Library/CoreServices/
  • Bless the boot file:
    # ./hfs-bless /boot/efi/System/Library/CoreServices/boot.efi
  • (optional) Add an icon:
    # rsvg-convert -w 128 -h 128 -o /tmp/debian.png /usr/share/reportbug/debian-swirl.svg
    # png2icns /boot/efi/.VolumeIcon.icns /tmp/debian.png
    # rm /tmp/debian.png
    

Now, the Apple Boot Manager, shown when holding down the option key when booting the Macbook Pro, looks like this:

And the Startup disk preferences dialog under OSX, like this:

2012-11-18 11:18:14+0200

debian, p.m.o

You can leave a response, or trackback from your own site.

23 Responses to “Debian EFI mode boot on a Macbook Pro, without rEFIt”

  1. Anonymous Says:

    You could go the next step as well, and ditch GRUB in favor of Linux’s native EFI boot support. Just compile a kernel with CONFIG_EFI_STUB and a built-in command line, and install the kernel in place of grubx64.efi.

  2. Mattias Mattsson Says:

    This post was extremely helpful. Thank you!

  3. glandium Says:

    Anonymous: “Just compile a kernel”. That’s not exactly a very compelling alternative, when my current solution doesn’t require to regularly do something.

  4. Onkar Says:

    Following command syntax looks wrong (without actually checking on a Debian machine).

    > png2icns /boot/efi/.VolumeIcon.icns /tmp/debian.png

    Shouldn’t the png file path be first argument?

  5. glandium Says:

    Onkar: no

  6. Fredrik Larsson Says:

    Thank you Mike, this seems to be just what I needed with a GNU/Linux install on a Mac being just around the corner.

    However, I wonder if you could clarify something for me, I feel a bit unsure. Would this be doable during the installation of Debian, before the first post-install reboot?

    That is, could I install Debian and get it bootable without rEFInd from the start? Or would I need to first install using rEFInd, and then after booting it the first time, use your procedure and then get rid of rEFInd after that?

    It’s not obvious to me if it’s possible to avoid using rEFInd at all. I would appreciate enlightenment. Thanks.

  7. Muammar El Khatib Says:

    I have installed successfully grub-efi in my macbook pro early 2011 following your procedure. If I press the option key, I can see debian logo and boot in grub. But, once in grub if I try to launch Mac OS X, then I get this error:

    error: no video mode activated Booting in blind mode

    And Mac OS X does not boot. I’ll try these options: https://help.ubuntu.com/community/UEFIBooting#Apple_Mac_EFI_systems-1 and I let you know if it works.

  8. Debian EFI on a MacBook Pro (sans rEFIt) « 0ddn1x: tricks with *nix Says:

    [...] http://glandium.org/blog/?p=2830 Leave a Comment TrackBack URI [...]

  9. Tony Says:

    Hi,

    There is this Debian EFI installer CD, that might simplify the installation process:
    http://cdimage.debian.org/cdimage/daily-builds/daily/arch-latest/amd64/iso-cd/
    That installer already installs grub-efi. Of course, then, one will still need some tweaking for using Apple’s firmware.

    Cheers,

  10. Raf Says:

    Hey, Do you think you can do guide for booting archlinux from efi boot?

  11. Jameson Williams Says:

    This worked beautifully with Ubuntu 12.10 and OS X Mountain Lion.

  12. Dual Booting Linux and OS X on a MacBook Air Says:

    [...] Debian EFI mode boot on a Macbook Pro, without rEFIt [...]

  13. Michael Greenberg Says:

    Replaced OS X With Ubuntu 12.10, on MacBook Air 3,2.
    This procedure woked like a charm!

    Thanks!

  14. winston smith Says:

    great guide sir thanks very much for the info. wheezy install on my macbook air 3,2 is going down a little differently tho…

    my wheezy install sets up an efi boot by default, and so some of the steps here would be a little different for me. using disk utility i created 4 partitions: 12GB hfs+ for os x, 600MB vfat for boot, 234GB vfat for /, and 4GB vfat swap. then installed debian. using partman i fixed up those vfat parts to be: 600MB ext3 for boot, 234GB ext4 for /, and 4GB swap. after the debian install my macbook air 3,1 boots right into debian via grub, with no need for refit or anything. so this system is already halfway there fresh out of the box i figure. my fstab file ends up showing apple’sefi partition mounted at /boot/efi and the 600MB partition i created for the debian install is mounted at /boot. weird. if i unmount those and remount them seperately elsewhere to explore them separately i see that /boot/efi/EFI/debian ended up being installed to apple’s boot partition, /dev/sda1, along side the /boot/efi/EFI/APPLE. only the the grub folder (containing grub.conf etc) gets installed to /dev/sda3.

    so any tips on how i can convert this setup to show me boot startup disk options in os x, and debian options at the apple firmware boot menu. currently the machine boots right into grub automagically, but if i hold option at boot then the os x disk is the only option.

    this is sort of ok anyhow, but i’d like to polish this thing off. i tried the following:

    # apt-get install hfsprogs icnsutils vim gdisk build-essential
    # cp -Rp /boot /tmp/
    # umount -lf /boot/efi
    # umount -lf /boot
    # mkfs.hfsplus /dev/sda1 -v “EFI System Partition”
    # mount /dev/sda1
    # echo $(blkid -o export -s UUID /dev/sda1) /boot/efi auto defaults 0 0 >> /etc/fstab
    # mount /dev/sda1 /boot
    # cp -Rp /tmp/boot/* /boot/
    now i thought i’d recreated the hfs fs that apple installs on the efi partition and i can just pick up following the guide again.
    # mkdir -p /boot/efi/System/Library/CoreServices
    # ln /boot/efi/EFI/debian/grubx64.efi /boot/efi/System/Library/CoreServices/boot.efi
    # echo “This file is required for booting” > /boot/efi/mach_kernel
    etc….everything was looking good, but when i got to blessing the boot.efi file i got this error: “Unable to bless filesystem: Inappropriate ioctl for device boot.efi”

    oouch! any idea where i went wrong or what i can do to fix this up? i think i’ll start over and hang out with the two os’ bootable and await further instruction, lol.

    tia gentlemen!

  15. winston smith Says:

    sorry edit above: after creating the partitions in disk utility i installed mac os x 10.8, then began the wheezy install.

  16. glandium Says:

    winston smith: The partition I place under /boot/efi is actually *not* an EFI System Partition. It is a partition that the Apple firmware considers as one it can boot, which is different.
    As for the bless error, it means your linux kernel is too old.

  17. winston smith Says:

    thanks for the info, really appreciate it. i did eventually fall back to following your directions more closely, and only the bless error was hanging me up. i’ll update my kernel and give it another go!

  18. Wes Says:

    What version of the kernel is needed? I am running up to date testing and getting the same bless error.

  19. PO8 Says:

    Wes: Had the same problem you have. Looks like 3.8-trunk from kernel experimental (deb http://mirrors.kernel.org/debian/ experimental main) works; also fixes the applesmc read bug. It also doesn’t look like you need to bless boot.efi to boot off it, which is interesting. (If you still have MacOS installed, you might also be able to boot the Recovery partition and use the bless command from there to bless this also. But I’d say just use this year’s kernel.)

    glandium: Thanks huge for the very informative instructions! My new MacBook Air (mid-2012 core i5) is booting stock Debian testing (w/ experimental kernel) now.

  20. PO8 Says:

    BTW, for anyone who wants it, I’ve made a basic Debian drive icon for my machine. http://fob.po8.org/bart/swirl-drive.png and http://fob.po8.org/bart/swirl-drive.icns .

  21. PO8 Says:

    er, http://po8.org/bart/swirl-drive.png and http://po8.org/bart/swirl-drive.icns . Sorry.

  22. Erik Says:

    This! This is exactly what I was looking for! I found your post last night as I was about to give up and take the inelegant road with rEFInd. May the god(((dess)e)s) bless you!

    I now have a mid-2011 MacBook Air booting OS X Lion and crunchbang linux using the native efi boot manager and I am so happy I could spit.

    Of course, I did modify this method slightly (partially unwittingly, but I’ll take dumb luck if it turns out to be of the good sort) and so I will post what I did over at: http://crunchbang.org/forums/viewtopic.php?id=25629

    Right now it is just me doing a little dance and linking back here, but I hope to be able to put together a nice narrative over the weekend.

  23. Dual Booting Crunchbang Linux and OS X Lion on a MacBook Air 4,1 « blog@ Says:

    [...] EFI boot mode on a Macbook Pro: http://glandium.org/blog/?p=2830 This link showed me the light, dropped the scales from my eyes, and pointed out that the [...]

Leave a Reply