Friday, April 15, 2011

HOWTO: Chainload Grub2 into Chameleon

I recently started playing with OSx86 again on my laptop that also runs Bodhi Linux. OSx86 uses the Chameleon boot loader to boot into the OSX kernel and handle easily passing on boot arguments at startup. If you are a Linux user like myself, odds are you prefer the Grub boot loader, which supports just about every operating system you can think of.

While I like grub, it does not do a good of a job of passing boot arguments to the OSX kernel. Beyond this some of the EFI strings Chameleon has happen at boot don't work properly with grub. The solution is to have Grub simply chainload into Chameleon instead of booting directly into the OSX kernel (which it does by default).

Doing this is fairly simple, first boot into your Linux operating system that is responsible for grub2, then open your favorite terminal and run the following:

sudo mkdir /boot/chameleon
cd /boot/chameleon
wget http://downloads.bodhilinux.com/jeff91/misc/boot0


Or if you don't trust a file provided by myself, the boot0 file is part of the chameleon boot loader, search for it on your own hard drive and move the file over.

Next, open your grub.cfg, as root, located at /boot/grub/grub.cfg with your favorite text editor and paste in the following chunk of code just below the last menu entry:

menuentry "Mac OS X Boot Loader" {
insmod hfsplus
set root='(hd0,1)'
search --no-floppy --fs-uuid --set ca2159244a8b0fc3
parttool (hd0,1) boot+
chainloader (hd0,5)/boot/chameleon/boot0
}

Note in the above chunk of code you will need to change hdX,Y to match your particular hard drive layout. On my system OSx86 is installed to sda1 (which equates to hd0,1) and Bodhi, which manages Grub2, is installed to sda5 (which equates to hd0,5). Also be sure you make the uuid match that of your OSX drive (you can copy it from the grub2 entry for booting directly into the OSX kernel).

Have any questions feel free to drop a comment below and I will lend a hand.

Cheers,
~Jeff Hoogland

28 comments:

  1. How do I Install grub without a linux installed?

    ReplyDelete
  2. What use would you have for grub without a Linux install? Chameleon should boot into Windows just fine.

    ReplyDelete
  3. How would I go about finding the hdX,Y? I am sort of new at this.

    ReplyDelete
  4. Install the tool gParted on your Linux install and it should be able to tell you via a GUI what is install where.

    ReplyDelete
  5. Thanks very much for this. I'm useless at chainloading. It works a treat apart from an odd message when choosing the Mac bootloader from the grub(2) menu
    Error no arguments specified
    partition 2 is now active (Mac is on /dev/sda3)
    then it waits for about 5 seconds and then Chameleon starts :-)
    Very nice! I couldn't add boot arguments before, but I can now.

    Just a heads-up.
    If you are using grub2, editing the /boot/grub/grub.cfg file manually will lead to your changes being over-written any time grub is updates.
    A better way is to edit (as root) /etc/grub.d/40_custom
    by including Jeff's stanza above (after edits of course) then running sudo update-grub afterwards.
    This way the new menu entry will never be removed when grub is updated.

    This won't work with grub legacy (the original grub) - only grub2.
    Thanks again.

    ReplyDelete
  6. oops I forgot my name, I'm not called anonymous :-)

    ReplyDelete
  7. is sda1 hd0,0 and sda7 hd0,6??? or is it like you said sda7 = hd0,7 ???

    ReplyDelete
  8. Hi, I'm glad to see there is a way to boot everything from grub2. I want to use this method to boot my macos hdd chainloading chameleon. The only problem is that I don't know where to find boot0 file to make a copy of it. I don't know what the extension of that file is. I have 2 hdd: 1 with Ubuntu 11.04 and Windows7 and the other one with macos leopard.
    Could you please tell me how to find that boot0 file please? thanks!

    ReplyDelete
  9. Just download the one I provide.

    ReplyDelete
  10. Hi! Great guide! I was searching for a solution like this and it seems viable. But I installed OSX on a bootable logical partition which creates the famous boot0:testing and boot0:error errors after using your solution.
    Interesting thing is, I can still boot OSX using the OSX LiveCD.

    The question is - is there a way to modify grub further, so that chameleon chainloads correctly from a logical partition?

    Thanks!

    ReplyDelete
  11. Hey, thanks for your tutorial it's helped! I'm having a problem now. After I installed Lion, when I click on my menu entry, it takes me to my Windows partition instead...

    ReplyDelete
  12. Jeff,
    do you have any idea of how to boot in Chameleon only?
    I dont have OSX installed yet, and I need to boot Chameleon ( so it can set the environment for installation )
    So im not after booting into my OSX immidealty, but only to the bootloader.

    Greetings,

    Rowan

    ReplyDelete
  13. The setup this guide does takes you into Chameleon

    ReplyDelete
  14. I have linux on my sda1 partition, and after I installed OSx86 on sda4, I can't see grub anymore, boot goes straight to chameleon. Any ideas how to get around this?

    ReplyDelete
  15. Search for how to restore grub2 after installing Windows. Same thing applies here.

    ReplyDelete
  16. I did just that, and now everything is good. Thanks.

    PS: I use Bodhi on one of my older PCs, great job :)

    ReplyDelete
  17. Hey Jeff,

    I figured out my problem. In my com.apple.boot.plist Quiet Boot was set so it skipped the Chameleon bootloader menu and booted the first menu entry it saw (which was Windows).

    What I did to fix this was to chainload grub to boot0hfs instead of boot0, remove Quiet Boot and add Instant Menu=yes.

    Thanks either way. I hope this helps someone else!

    ReplyDelete
  18. Damnated,

    To restore grub back you'll have to boot from your linux CD.
    Open a terminal and type:
    sudo mount /dev/sda1 /mnt
    This mounts the linux partition for you to access. I'm assuming that sda1 is where grub is installed! If not, mount that partition!

    sudo grub-install --recheck --root-directory=/mnt /dev/sda
    This reinstalls grub back to the partition.

    Once it says installation completed:
    sudo umount /mnt
    Unmounts the sda1 partition.

    Then reboot. It should work then! =)

    ReplyDelete
  19. Thanks Jon, but I got it already :)

    ReplyDelete
  20. Great tip. Thanks. Since I'm booting many OSes, grub2 is the best way for me. I could use "multiboot /boot" for S-L but Lion needs boot0 it seems. The "Error no arguments specified" is likely caused by the "search ..." line which has "--set" with no arguments. That line is superfluous. Remove it and Chameleon will load almost instantly.

    ReplyDelete
  21. Nice post.Do note though that with newer versions of grub, you need to replace --set in the menuentry with --set=root or else it will spit out an error message "No argument specified"

    ReplyDelete
  22. Do you think that this can work with a hard disk using a MBR partition table format?

    I always get this error:

    boot0:test
    boot0:error.

    I'm using this configuration:

    menuentry "Mac OS X Boot Loader" {
    insmod hfsplus
    set root='(hd0,msdos1)'
    search --no-floppy --fs-uuid --set cds3423423d23
    parttool (hd0,msdos1) boot+
    chainloader (hd0,msdos5)/boot/chameleon/boot0
    }

    I have also installed chameleon (boot1h and copy boot to /) to the bootsector of the msdos1 partition.

    So it seems that chameleon is booting but having problems... any idea? thanks!

    ReplyDelete
  23. Jeff: Thank you!!!!!!. Two days trying until I see your blog.

    For if it helps to others, I changed the following:

    Having win7 in sda1, ubuntu 11.10 in sda2, osx 10.6.8 in sdb2 and chameleon in sdb1. The code that i put in /etc/grub.d/40_custom so it could be write in /boot/grub/grub.cfg via sudo update-grub2 and works for me was this:

    menuentry "Mac OS X Boot Loader" {
    insmod part_gpt
    insmod hfsplus
    set root='(hd1,gpt2)'
    search --no-floppy --fs-uuid --set=root b47b98437e42addb
    # parttool (hd1,gpt2) boot+
    chainloader (hd0,2)/boot/chameleon/boot0

    I explain errors I've got until get this.
    1-putting set xxxxxx instead of set root= xxxxx give me " ...no argument ...."
    2- the line i commented (...parttool etc) give me boot + was not recognize as command
    3- the "insmod part_gpt" and '(hd1,gpt2)' etc for what i read has someting to do with gui partition of second drive (where osx is), I have before error that " ..no partition ..."
    4- finally "file not found" was mine, stupid that I forget that I put your boot0 in my ext4 linux partition.I was chainloading to EFI (sdb1)

    One more thing, the UUID i've got from sudo blkid was wrong, I had to copy the one in grub.cfg generated by grub2

    Once more: thanks !!!!!!!!!!!!!!!!!

    Pablo Taramelli ptaramelli@gmail.com
    Sorry, my english is terrible.....

    ReplyDelete
    Replies
    1. Thank you, Anonymous January 4, 2012 9:47 PM (Pablo)! I wouldn't have been able to get it to work without your post. Here's what my /etc/grub.d/40_custom file looks like for (K)Ubuntu 11.10/12.04:

      menuentry "Mac OS X Boot Loader" {
      insmod part_gpt
      insmod hfsplus
      set root='(hd2,gpt2)'
      search --no-floppy --fs-uuid --set=root 777eaee489759bd8
      chainloader (hd0,5)/boot/chameleon/boot0
      }

      Note that my Snow Leopard (GPT) install is on /dev/sdc2 (=grub hd2,gpt2) and my boot0 file is located at /boot/chameleon/boot0 on my Linux partition /dev/sda5 (=grub hd0,5)

      Delete
    2. FYI, if you use the Unibeast install method (http://www.tonymacx86.com/61-unibeast-install-os-x-mountain-lion-any-supported-intel-based-pc.html) to install OSX, the syntax for your GRUB2 chainload is MUCH easier, since chameleon is already installed for you on the OSX disc:

      menuentry "Chainload Mac OS X Lion" {
      set root=(hd3)
      chainloader +1
      }

      ...where hdx is the location of your OSX drive. Note, no partition information is needed!

      Delete
  24. I installed Grub2 and couldn't find a way to boot into OS X ... I tried to follow the tutorial and get Grub2 to boot into Chameleon, I failed. What I did do is while in the Grub2 bootloader screen, I hit 'ESC', this brought up a very minimal terminal, I typed exit, this quit Grub2 and brought up Chameleon bootloader. Maybe this will help someone :)

    ReplyDelete