overdue-scratch

Author Topic: boot0md: dual boot Windows 7 and Mac OSX from Win7 drive  (Read 48220 times)

0 Members and 1 Guest are viewing this topic.

dmazar

  • Member
  • Posts: 52
boot0md: dual boot Windows 7 and Mac OSX from Win7 drive
« on: July 12, 2011, 12:13:03 PM »
Problem:
I have Win7 on one disk and Mac OSX with Chameleon on the other. Booting with OSX drive (set up as boot drive in BIOS) loads Chameleon and I can start OSX or Win7 from there. But …
If Windows drive is not the boot drive then some things are not working in Win: hybrid sleep, service pack 1 install, win7 disk image backup …

Solution:
Modified boot0 code - boot0md (multi disk) - can be installed in Win7 disk MBR. It can load Chameleon from other disks, or Win7 if Chameleon can not be found.

boot0md - same as boot0 but searches all disks:
- searches all BIOS accessible disks to find bootable HFS partition (with boot1h)
- if one is found then it boots it
- if not found, then searches all disks again but for active partition (e.g. Win7) and boots it

In my case now:
- boot0md is in MBR of Win7 disk and BIOS boots from it
- boot0md loads boot1h from MacOSX disk and loads it
- boot1h loads Chameleon's boot from MacOSX disk
- boot shows menu with MacOSX and Win7
- if Win7 is booted with it then hybrid sleep works

If MacOSX disk is removed, then boot0md loads Win7 directly.


Source attached.
- should be put in i386/boot0/ of Chameleon source tree and compiled with the rest of it because of config options

Compiled boot0md attached.


Install from terminal:
- determine windows disk with
diskutil list
- install with
sudo fdisk440  -f boot0md -u /dev/rdiskX


Notes: It works for me (see test cases), but I have it only for 2 days. So, it's not tested and proved enough.


Other possible solutions:

1. selecting boot drive from bios (F8 on my board) - most simple, ok if you does not switch between OSes too often

2. adding additional HFS partition to Win drive with Chameleon on it - I did not want more partitions

3. using Win boot loader BCD - EasyBCD can add new MacOSX entry (MBR method), boot0md can be put instead of provided MBR file and then this works for me - but I found Chameleon to be nicer

4. and many others, I'm sure …

Anyway, tweaking of boot loader code was the most interesting path to me, so I chosen that route. If nothing else, for fun …

dmazar

  • Member
  • Posts: 52
Re: boot0md: dual boot Windows 7 and Mac OSX from Win7 drive
« Reply #1 on: July 12, 2011, 12:14:51 PM »
Test cases:
-----------
TC 1

Disk0: MBR (boot0md), P1=Win7 (NTFS, bootable, active)
Disk1: GPT, P1=EFI, P2=MacOSX (HFS+, boot1h, boot), P3=MacOSX-Bak (HFS+, boot1h, boot)
Disk2: MBR, P1=Data3 (NTFS), P2=Data4 (exFAT)

Result: Loads Disk1/P2/chameleon; can boot MacOSX, MacOSX-Bak, Win7; Win7 hybrid sleep works

-----------
TC 2

Disk0: MBR (boot0md), P1=Win7 (NTFS, bootable, active)
Disk1: MBR, P1=Data3 (NTFS), P2=Data4 (exFAT)

Result: Loads Win7, hybrid sleep works

-----------
TC 3

Disk0: MBR (boot0md), P1=Win7 (NTFS, bootable, active)
Disk1: GPT, P1=EFI, P2=MacOSX (HFS+, not bootable), P3=MacOSX-Bak (HFS+, not bootable)
Disk2: MBR, P1=Data3 (NTFS), P2=Data4 (exFAT)

Result: Loads Win7, hybrid sleep works

-----------
TC 4

Disk0: MBR (boot0md), P1=Win7 (NTFS, bootable, active)
Disk1: GPT, P1=EFI, P2=MacOSX (HFS+, not bootable), P3=MacOSX-Bak (HFS+, not bootable)
Disk2: MBR, P1=Data3 (NTFS), P2=Data4 (exFAT)
Disk3 (USB): GPT, P1=Boot (HFS+, boot1h, boot)

Result: Loads Disk3 (USB)/P1/chameleon; can boot MacOSX, MacOSX-Bak, Win7; Win7 hybrid sleep works

Blackosx

  • Forum Moderator
  • Posts: 1150
Re: boot0md: dual boot Windows 7 and Mac OSX from Win7 drive
« Reply #2 on: July 12, 2011, 04:43:38 PM »
Hi dmazar - Welcome to the forum.

Your changes here look interesting and I think will help many users wanting to use Chameleon to boot Windows where it resides on a separate HDD. As you've mentioned already, opting to choose to boot the Windows HDD from BIOS (F8) is the simplest method for this situation, but your mod could prove to be favourable.

I don't currently have Windows installed anywhere on my system so I can't test that part of it immediately, though I can test the booting of OS X. I'll try it out tonight.

Thanks for your contribution.
« Last Edit: July 12, 2011, 04:46:07 PM by Blackosx »
10.10.5 / 10.11 GM1 | Asus Maximum IV Gene-Z | i7-2600 3.40GHz | 4GB | Radeon 5770 1GB

dmazar

  • Member
  • Posts: 52
Re: boot0md: dual boot Windows 7 and Mac OSX from Win7 drive
« Reply #3 on: July 12, 2011, 09:56:25 PM »
Hi dmazar - Welcome to the forum.

Thanks.
Hope this will be of some use to somebody.

Blackosx

  • Forum Moderator
  • Posts: 1150
Re: boot0md: dual boot Windows 7 and Mac OSX from Win7 drive
« Reply #4 on: July 16, 2011, 10:26:20 PM »
Hi dmazar

I've finally got round to installing Windows 7 and have just tested your boot0md file.

Test details:
Disk0: MBR (boot0md), P1=System Reserved (NTFS, bootable, active), P2=Win7 (NTFS)
Disk1: GPT, P1=EFI, P2=Boot (HFS+, boot0hfs, boot1h, Boot), P3=MacOSX 10.6 (HFS+), P4 MacOSX 10.7 (HFS+)
Disk2 (USB): GPT, P1=Mac OSX Install DVD (HFS+, boot0, boot1h, boot)

- Selecting to boot Disk0 from BIOS (F12), boot0md finds Chameleon on Disk1/P2 and presents GUI where selecting to boot Disk0/P1 (System Reserved) boots Windows and hibernation works.

- Selecting to boot Disk1 from BIOS (F12), boot0hfs finds Chameleon on Disk1/P2 and presents GUI where Selecting to boot Disk0/P1 (System Reserved) boots Windows and hibernation fails as expected.

- Selecting to boot Disk0 from BIOS (F12), boot0md finds Chameleon on Disk1/P2 and presents GUI where selecting to boot Disk1/P3 works as expected.

- Selecting to boot Disk0 from BIOS (F12), boot0md finds Chameleon on Disk1/P2 and presents GUI where selecting to boot Disk1/P4 works as expected.

- Selecting to boot Disk0 from BIOS (F12), boot0md finds Chameleon on Disk2/P1 and presents GUI where selecting to boot Disk2/P1 works as expected.

Conclusion:
This works great. I'm more than happy to recommend this and use it on a separate HDD with Windows as the main system. Good work dmazar  ;D
« Last Edit: July 16, 2011, 10:37:52 PM by Blackosx »
10.10.5 / 10.11 GM1 | Asus Maximum IV Gene-Z | i7-2600 3.40GHz | 4GB | Radeon 5770 1GB

Azimutz

  • VoodooLabs
  • Posts: 420
  • Paranoid Android
Re: boot0md: dual boot Windows 7 and Mac OSX from Win7 drive
« Reply #5 on: July 17, 2011, 03:43:22 AM »
Hi Dmazar,

still didn't had time to test, but it's close.
Looking at the test cases you and BlackOSX posted, this looks very promising indeed.
Am i missing something here or this in fact renders boot0hfs useless!? :) am i?
Because i'm dying to throw the damn thing to the trash! :P
What do you say BlackOSX?

Will try to test it this night or tomorrow... bbl

 System & Patches: http://goo.gl/i961
 Chameleon:
- trunk builds: http://goo.gl/9G1Hq
- pref pane: http://goo.gl/OL2UT

Blackosx

  • Forum Moderator
  • Posts: 1150
Re: boot0md: dual boot Windows 7 and Mac OSX from Win7 drive
« Reply #6 on: July 17, 2011, 10:47:18 AM »
Am i missing something here or this in fact renders boot0hfs useless!? :) am i?
Because i'm dying to throw the damn thing to the trash! :P
Lol.. 

I think boot0hfs might be still necessary for dual booting OSX and Windows from the same HDD?
but then again Dmazar's opening post reads:

boot0md - same as boot0 but searches all disks:
- searches all BIOS accessible disks to find bootable HFS partition (with boot1h)
- if one is found then it boots it
- if not found, then searches all disks again but for active partition (e.g. Win7) and boots it

So that's the same as boot0hfs does? in which case this could replace boot0hfs.
Dmazar, please confirm if I read this correctly?

In the mean time, let me run another test or two.....

Though I think we will still need the original boot0 to load an HFS partition flagged active (See this post by Zef when boot0hfs was being considered).
« Last Edit: July 17, 2011, 12:29:15 PM by Blackosx »
10.10.5 / 10.11 GM1 | Asus Maximum IV Gene-Z | i7-2600 3.40GHz | 4GB | Radeon 5770 1GB

Blackosx

  • Forum Moderator
  • Posts: 1150
Re: boot0md: dual boot Windows 7 and Mac OSX from Win7 drive
« Reply #7 on: July 17, 2011, 12:29:33 PM »
Well further testing complete :)

Test 1 details:
Disk0: GPT, P1=EFI, P2=Boot (HFS+, boot0hfs, boot1h, Boot), P3=WIN7 (NTFS, bootable, active), P3=MacOSX 10.6 (HFS+), P4 MacOSX 10.7 (HFS+)

With Windows now on the same HDD, and boot0md written using fdisk440 to MBR, booting Disk0 works as expected allowing me to boot all installed OS's. Windows 7 happily sleeps/wakes and hibernates/resumes. I can't test updating to SP1 as SP1 was the version I installed.

Test 2 details (reconnect other HDD)
Disk0: MBR (boot0md), P1=System Reserved (NTFS, bootable, active), P2=Win7 (NTFS)
Disk1: GPT, P1=EFI, P2=Boot (HFS+, boot0hfs, boot1h, Boot), P3=WIN7 (NTFS, bootable, active), P3=MacOSX 10.6 (HFS+), P4 MacOSX 10.7 (HFS+)

- Selecting to boot Disk1 from BIOS (F12), boot0md finds Chameleon on Disk1/P2 and presents GUI where Selecting to boot Disk0/P1 (System Reserved) boots Windows and hibernation fails. (Same result as seen using boothfs when tested previously)

Conclusion:
Boot0md behaves as boot0hfs with regard to booting the first bootable HFS partition it finds while allowing Windows be on the same HDD and remain the active partition. So based on the above tests, I would say yes, boot0md can replace boot0hfs.
« Last Edit: July 17, 2011, 12:55:14 PM by Blackosx »
10.10.5 / 10.11 GM1 | Asus Maximum IV Gene-Z | i7-2600 3.40GHz | 4GB | Radeon 5770 1GB

meklort

  • VoodooLabs
  • Posts: 65
Re: boot0md: dual boot Windows 7 and Mac OSX from Win7 drive
« Reply #8 on: July 18, 2011, 12:57:40 AM »
I've merged this in with trunk (it's compiled separately from boot0 right now). Let me know if you feel that boot0 can be replaced in it's entirety with boot0md (I'd prefer this).
return c ? c : !c;

Blackosx

  • Forum Moderator
  • Posts: 1150
Re: boot0md: dual boot Windows 7 and Mac OSX from Win7 drive
« Reply #9 on: July 18, 2011, 08:37:38 AM »
Fantastic..
Well done with your work dmazar.

I'll look further in to seeing whether or not boot0 could be replaced.
10.10.5 / 10.11 GM1 | Asus Maximum IV Gene-Z | i7-2600 3.40GHz | 4GB | Radeon 5770 1GB

dmazar

  • Member
  • Posts: 52
Re: boot0md: dual boot Windows 7 and Mac OSX from Win7 drive
« Reply #10 on: July 18, 2011, 04:34:06 PM »
Hi guys. You are fast. Thanks for testing this Blackosx.
I'm on a vacation for 2 weeks, do not have Mac with me and can not connect too often - that's why I did not reply sooner.

I can confirm that it behaves as boot0hfs if installed on the disk with bootable HFS partition. It's the same code: first bootable HFS partition will be used and no additional disk scanning will be done. But you find out that already. Nice.

I saw that you added it to the trunk. There's one issue here: I was not aware that you are compiling boot0 once with BOOT0_HFSFIRST=n and then with BOOT0_HFSFIRST=y. I wanted to make minimal changes to the existing code and I left that part of the code with config switch untouched in boot0md. Compiling boot0md wit BOOT0_HFSFIRST=y will give correct output, while compiling with BOOT0_HFSFIRST=n would not. Sorry, I'm still new to this.

So, to avoid any confusion and mistakes, please change the following code in boot0md (remove dependency on BOOT0_HFSFIRST and make the code as BOOT0_HFSFIRST is set):
Code: [Select]
.Pass1:
%if CONFIG_BOOT0_HFSFIRST
    cmp     BYTE [si + part.type], kPartTypeHFS ; In pass 1 we're going to find a HFS+ partition
                                                    ; equipped with boot1h in its boot record
                                                    ; regardless if it's active or not.
    jne     .continue
  mov dh, 1                ; Argument for loadBootSector to check HFS+ partition signature.
%else
    cmp     BYTE [si + part.bootid], kPartActive ; In pass 1 we are walking on the standard path
                                                    ; by trying to hop on the active partition.
    jne     .continue
    xor   dh, dh                ; Argument for loadBootSector to skip HFS+ partition
        ; signature check.
%endif

    jmp     .tryToBoot

.Pass2:   
%if CONFIG_BOOT0_HFSFIRST
    cmp     BYTE [si + part.bootid], kPartActive ; In pass 2 we are walking on the standard path
                                                    ; by trying to hop on the active partition.
    jne     .continue
    xor dh, dh                ; Argument for loadBootSector to skip HFS+ partition
        ; signature check.
%else
    cmp     BYTE [si + part.type], kPartTypeHFS ; In pass 2 we're going to find a HFS+ partition
                                                    ; equipped with boot1h in its boot record
                                                    ; regardless if it's active or not.
    jne     .continue
  mov dh, 1                ; Argument for loadBootSector to check HFS+ partition signature.
%endif

    DebugChar('*')

with
Code: [Select]
.Pass1:
    cmp     BYTE [si + part.type], kPartTypeHFS ; In pass 1 we're going to find a HFS+ partition
                                                    ; equipped with boot1h in its boot record
                                                    ; regardless if it's active or not.
    jne     .continue
  mov dh, 1                ; Argument for loadBootSector to check HFS+ partition signature.

    jmp     .tryToBoot

.Pass2:   
    cmp     BYTE [si + part.bootid], kPartActive ; In pass 2 we are walking on the standard path
                                                    ; by trying to hop on the active partition.
    jne     .continue
    xor dh, dh                ; Argument for loadBootSector to skip HFS+ partition
        ; signature check.

    DebugChar('*')

To avoid retesting it again, it would be enough to make sure:
- that new code compiles without errors
- and that resulting binary is the same as the one attached in the opening post
    - do from the terminal in sym/i386> md5 boot0md /path/to/original/file/boot0md
      should give the same fingerprint


One additional suggestion: please consider making boot0.s and boot0hfs.s code as separate source files to allow one 'make' to do all the job without switching config flags.
Compiling with make is done by many users very often and would be better to make this as easy as possible. Boot0 code changes are made by developers not more then once per year, I guess, and in that rare case developers should/could take care of that duplicate code (copy the change to the other file as well).

Cheers guys. You are a good team.

Blackosx

  • Forum Moderator
  • Posts: 1150
Re: boot0md: dual boot Windows 7 and Mac OSX from Win7 drive
« Reply #11 on: July 18, 2011, 05:22:09 PM »
Hi dmazar

Thanks for coming back with further details, code cleanups and suggestions etc.
I'll have to leave the code stuff to meklort, but I do agree that running make once to produce both boot0 and boot0hfs (boot0md) would make things easier.

EDIT: I see our speedy meklort's already applied the change to the trunk. commit 1173  ;D

EDIT2: I see with rev1173 that boot0 and boot0md are both made with the default 'make'. Great.. Did that happen before? as I never checked.  Also, md5 for both latest boot0md and original one in OP match.

Let me know if you feel that boot0 can be replaced in it's entirety with boot0md (I'd prefer this).
The only reason I know for using the original boot0 is as Zef posted, in that if the user has an HDD with two HFS partitions both installed with boot1h/boot then they could choose which partition to use by setting the active flag. In this case two versions of boot0 are still required and I can't see how one boot0 could cater for all situations.
« Last Edit: July 18, 2011, 05:51:23 PM by Blackosx »
10.10.5 / 10.11 GM1 | Asus Maximum IV Gene-Z | i7-2600 3.40GHz | 4GB | Radeon 5770 1GB

dmazar

  • Member
  • Posts: 52
Re: boot0md: dual boot Windows 7 and Mac OSX from Win7 drive
« Reply #12 on: July 18, 2011, 05:55:37 PM »
EDIT: I see our speedy meklort's already applied the change to the trunk. commit 1173  ;D
That was really quick. And looks ok.

Let me know if you feel that boot0 can be replaced in it's entirety with boot0md (I'd prefer this).
The only reason I know for using the original boot0 is as Zef posted, in that if the user has an HDD with two HFS partitions both installed with boot1h/boot then they could choose which partition to use by setting the active flag. In this case two versions of boot0 are still required and I can't see how one boot0 could cater for all situations.
I'll think about it, but it seems you'll have to keep boot0 as is.

Blackosx

  • Forum Moderator
  • Posts: 1150
Re: boot0md: dual boot Windows 7 and Mac OSX from Win7 drive
« Reply #13 on: July 18, 2011, 11:37:57 PM »
I'm on a vacation for 2 weeks, do not have Mac with me and can not connect too often - that's why I did not reply sooner.
I forgot to say; Enjoy your vacation.  ;D
10.10.5 / 10.11 GM1 | Asus Maximum IV Gene-Z | i7-2600 3.40GHz | 4GB | Radeon 5770 1GB

Azimutz

  • VoodooLabs
  • Posts: 420
  • Paranoid Android
Re: boot0md: dual boot Windows 7 and Mac OSX from Win7 drive
« Reply #14 on: July 19, 2011, 02:09:56 AM »
One additional suggestion: please consider making boot0.s and boot0hfs.s code as separate source files to allow one 'make' to do all the job without switching config flags.
Compiling with make is done by many users very often and would be better to make this as easy as possible. Boot0 code changes are made by developers not more then once per year, I guess, and in that rare case developers should/could take care of that duplicate code (copy the change to the other file as well).
Totally agree! :) I mentioned this to Mek at the time, but the solution wasn't clear to me.
Now i think we should just add a "separate boot0hfs.s file/Cconfig option" and compile it by default;
people that compile the booter, can use "make config" to suit their build needs.

Still didn't tested boot0md, but my feedback on the efficiency of the file is not important;
i'm just curious if it fixes some problems i detected with boot0hfs ;)
« Last Edit: July 19, 2011, 02:17:00 AM by Azimutz »
 System & Patches: http://goo.gl/i961
 Chameleon:
- trunk builds: http://goo.gl/9G1Hq
- pref pane: http://goo.gl/OL2UT