Voodooprojects

Chameleon => DevTalk => Patches => Topic started by: dmazar on July 12, 2011, 12:13:03 PM

Title: boot0md: dual boot Windows 7 and Mac OSX from Win7 drive
Post by: dmazar 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 …
Title: Re: boot0md: dual boot Windows 7 and Mac OSX from Win7 drive
Post by: dmazar 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
Title: Re: boot0md: dual boot Windows 7 and Mac OSX from Win7 drive
Post by: Blackosx 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.
Title: Re: boot0md: dual boot Windows 7 and Mac OSX from Win7 drive
Post by: dmazar on July 12, 2011, 09:56:25 PM
Hi dmazar - Welcome to the forum.

Thanks.
Hope this will be of some use to somebody.
Title: Re: boot0md: dual boot Windows 7 and Mac OSX from Win7 drive
Post by: Blackosx 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
Title: Re: boot0md: dual boot Windows 7 and Mac OSX from Win7 drive
Post by: Azimutz 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

Title: Re: boot0md: dual boot Windows 7 and Mac OSX from Win7 drive
Post by: Blackosx 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  (http://forum.voodooprojects.org/index.php/topic,1141.msg5020.html#msg5020)by Zef when boot0hfs was being considered).
Title: Re: boot0md: dual boot Windows 7 and Mac OSX from Win7 drive
Post by: Blackosx 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.
Title: Re: boot0md: dual boot Windows 7 and Mac OSX from Win7 drive
Post by: meklort 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).
Title: Re: boot0md: dual boot Windows 7 and Mac OSX from Win7 drive
Post by: Blackosx 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.
Title: Re: boot0md: dual boot Windows 7 and Mac OSX from Win7 drive
Post by: dmazar 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.
Title: Re: boot0md: dual boot Windows 7 and Mac OSX from Win7 drive
Post by: Blackosx 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 (http://forge.voodooprojects.org/p/chameleon/source/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 (http://forum.voodooprojects.org/index.php/topic,1141.msg5020.html#msg5020), 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.
Title: Re: boot0md: dual boot Windows 7 and Mac OSX from Win7 drive
Post by: dmazar on July 18, 2011, 05:55:37 PM
EDIT: I see our speedy meklort's already applied the change to the trunk. commit 1173 (http://forge.voodooprojects.org/p/chameleon/source/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 (http://forum.voodooprojects.org/index.php/topic,1141.msg5020.html#msg5020), 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.
Title: Re: boot0md: dual boot Windows 7 and Mac OSX from Win7 drive
Post by: Blackosx 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
Title: Re: boot0md: dual boot Windows 7 and Mac OSX from Win7 drive
Post by: Azimutz 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 ;)
Title: Re: boot0md: dual boot Windows 7 and Mac OSX from Win7 drive
Post by: digital_dreamer on July 19, 2011, 02:41:06 AM
Just to clarify and make sure I understand the changes:
From r1173, boot0 now takes on its previous role as just the booter that prefers active partitions first (with no config changes)?
And, the new bootmd is like boot0hfs (which, itself, is no longer being made) - prefers bootable HFS+ partitions first - but with added functionality of searching all disks accessible by BIOS and loading the Chameleon GUI even when the WIN install is the first boot disk?
This eliminates the need to select the Mac OS X drive in the BIOS first <F12>, if a WIN install is first in BIOS list, as previously you needed the Mac OS X install on the first drive in the BIOS priority list for the Chameleon bootloader to load.

Am I on the right track?  :P

Nice to see progress here. Thanks for all the work being done!

regards,
MAJ

P.S. Oh, and I agree about making boot0 and boot0hfs separate. (it's bootmd now, right? Or, boot0md? Shouldn't we name it according to the stage?)
I'm having to add a new portion in my script just to test which booter is actually being used, just to make sure the right one is being compiled and installed. You never know when they share the same name - you have to compare the dump. Here's my test of the installed boot0 booter: a 12-byte dump at offset 105, where the opcodes appear to change:
Code: [Select]
if [[ $(dd if="/dev/disk${DK_ID:0:1}" bs=440 count=1 2>/dev/null | od -A n -j 105 -N 12 -t x | sed 's/ //g') = "803c800af6301475800008e9" ]];then
BOOT0_TYPE="prefers active partitions first"
elif [[ $(dd if="/dev/disk${DK_ID:0:1}" bs=440 count=1 2>/dev/null | od -A n -j 105 -N 12 -t x | sed 's/ //g') = "047c800bb61375af0007e901" ]];then
BOOT0_TYPE="prefers bootable HFS+ partitions first"
else
BOOT0_TYPE="Unknown! Dump at offset 105: "$(dd if="/dev/disk${DK_ID:0:1}" bs=440 count=1 2>/dev/null | od -A n -j 105 -N 12 -t x | sed 's/ //g')
fi
Haven't tested for the bootmd booter, yet, though.
Title: Re: boot0md: dual boot Windows 7 and Mac OSX from Win7 drive
Post by: Azimutz on July 19, 2011, 04:42:13 AM
d_dreamer,
i have the feeling i already explained you about "make config" and default Chameleon build settings, haven't i??
Don't kill your neurons thinking so much :P soon all the boot0 files will have their respective names.
Meanwhile, compile them your self or get them from here (http://forum.voodooprojects.org/index.php/topic,1950.0.html); boot0 is the good old boot0, boot0hfs is the old boot0hfs
and boot0md is explained on this topic ;) try it!
Title: Re: boot0md: dual boot Windows 7 and Mac OSX from Win7 drive
Post by: digital_dreamer on July 19, 2011, 05:19:06 AM
 :lol:

Yes, Azimutz, you've already described the "make and "make config" stuff quite well and I'm using your tips (and meklort's). Thank you!
I was thinking out loud. Really loud.  ;D

best of wishes,
MAJ
Title: Re: boot0md: dual boot Windows 7 and Mac OSX from Win7 drive
Post by: Azimutz on July 19, 2011, 09:20:52 AM
And i was just messing a bit with you ;)

Stay safe
Title: Re: boot0md: dual boot Windows 7 and Mac OSX from Win7 drive
Post by: peter_sm on July 19, 2011, 07:03:32 PM
Hi,

This looks great with the new  boot0md, but how would this be for me ?

I have 2 HD in my laptop, but I can't change what HD I like to boot from in my BIOS,(pressing  esc, F9), it let me chose only primary HD.

I rely like to have the windows 7 back up working  ;D

Should I perhaps shift the 2 hard drive and let the OSX HD be my secondary and W7 HD my primary ?

My spec of my Laptop is below.
Code: [Select]
HP DV8t-1290e0 (WN916EA#UUW) | 1.60 GHz Intel Core i7-720QM | nVidia GeForce GT 230M w/ 1024MB | 18.4" 1920 x 1080 display | 6 GB DDR3 (1 x 2048 MB + 1 x 4096 MB) |2 x 500 GB SATA Hard Disk Drive 7200 rpm| Atheros AR928X Wireless Network Adapter |OS X 10.6.8 & LION GM & Win7 Ult x64 SP1

EDIT

Shifted my 2 HD so my W7 is primary, and my backu up on W7 is just now running  :lol no: :lol:

//Peter
Title: Re: boot0md: dual boot Windows 7 and Mac OSX from Win7 drive
Post by: meklort on July 20, 2011, 06:54:11 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).

I've separated boot0 and boot0hfs into two separate files.
Title: Re: boot0md: dual boot Windows 7 and Mac OSX from Win7 drive
Post by: Enzo on July 20, 2011, 09:22:19 PM
This is great, I would no longer have to unplug the OS X HDD to be able to install SP1 =P.
Title: Re: boot0md: dual boot Windows 7 and Mac OSX from Win7 drive
Post by: dmazar on July 20, 2011, 11:56:08 PM
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 (http://forum.voodooprojects.org/index.php/topic,1141.msg5020.html#msg5020), 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.

It seems it will be possible to make one universal boot0. But before that I'll write down simplified explanation for each boot0 version. It helps me to see what's going on. I hope I did not make mistakes there ...

boot0:
------
for the boot drive only:
- Pass1:
    - searches MBR partition table for an active bootable partition and boots it
    - if not found and disk is actually GPT, then searches for the first HFS+ bootable
      partition (or EFI with boot1f32) in the GPT array and boots it
    - if still not found, then continues with Pass2
   
- Pass2:
    - searches MBR partition table for a first HFS+ bootable partition and boots it
    - if not found and disk is actually GPT, then searches for the first HFS+ bootable
      partition (or EFI with boot1f32) in the GPT array and boots it
    - if still not found, then finishes with "boot0: error"


boot0hfs:
------
for the boot drive only:
- Pass1:
    - searches MBR partition table for a first HFS+ bootable partition and boots it
    - if not found and disk is actually GPT, then searches for the first HFS+ bootable
      partition (or EFI with boot1f32) in the GPT array and boots it
    - if still not found, then continues with Pass2

- Pass2:
    - searches MBR partition table for an active bootable partition and boots it
    - if not found and disk is actually GPT, then searches for the first HFS+ bootable
      partition (or EFI with boot1f32) in the GPT array and boots it
    - if still not found, then finishes with "boot0: error"
   

boot0md:
------
- Pass1:
    - iterates over all drives and for each drive:
        - searches MBR partition table for the first HSF+ bootable partition and boots it
        - if not found and disk is actually GPT, then searches for the first HFS+ bootable
          partition (or EFI with boot1f32) in the GPT array and boots it
        - if still not found, then continues with the next drive
    - if all drives are searched and nothing found, then continues with Pass2

- Pass2:
    - iterates over all drives and for each drive:
        - searches MBR partition table for the first active bootable partition and boots it
        - if not found and disk is actually GPT, then searches for the first HFS+ bootable
          partition (or EFI with boot1f32) in the GPT and boots it
        - if still not found, then continues with the next drive
    - if all drives are searched and nothing found, finishes with "boot0: error"


Bootable partition above means a partition with the boot sector signature (0xAA55) at the end of the partition boot sector.
Drives are searched (boot0md) in the order defined in the BIOS. Drive which is selected as the boot drive is searched first.

Few conclusions from the above:
----
boot0, boot0hfs and boot0md behaves differently only if booted from MBR or hybrid discs, while if booting from GPT disks they do the same: boot first HFS+ partition.

Active partition exists only on MBR or hybrid discs and can be used with boot0. There is no such equivalent on GPT disks. If somebody wants to load Chameleon from some other HFS+ partition, one solution is to make that one bootable (install Chameleon on it) and other HFS+ partitions not bootable by overwriting boot sector signature 0xAA55 with something else. If somebody is inspired, make a script for making some partition bootable/not-bootable and we'll have active partition equivalent on GPT.

There are some redundant steps in the above code (constant check for GTP disk), but that's how it is now. It's redundant, but does not cause any harm.

Later added  "(or EFI with boot1f32)" since I forgot that.
Title: Re: boot0md: dual boot Windows 7 and Mac OSX from Win7 drive
Post by: dmazar on July 20, 2011, 11:57:37 PM
Back to "universal" boot0. I think I can add one more pass to boot0md with minimal changes to the existing code. This would cover searching for active HFS+ partition in MBR plus boot0md (extended boot0hfs) functionality.

boot0work: (work in progress)
------
// part of boot0 special functionality
- Pass1:
    - for the boot drive only:
        - searches MBR partition table for an active HSF+ bootable partition and boots it
        - if not found and disk is actually GPT, then searches for the first HFS+ bootable
          partition (or EFI with boot1f32) in the GPT array and boots it
        - if still not found, then continues with Pass2

// the following is the same as for boot0md which is extended boot0hfs
- Pass2:
    - iterates over all drives and for each drive:
        - searches MBR partition table for the first HSF+ bootable partition and boots it
        - if not found and disk is actually GPT, then searches for the first HFS+ bootable
          partition (or EFI with boot1f32) in the GPT array and boots it
        - if still not found, then continues with the next drive
    - if all drives are searched and nothing found, then continues with Pass3

- Pass3:
    - iterates over all drives and for each drive:
        - searches MBR partition table for the first active bootable partition and boots it
        - if not found and disk is actually GPT, then searches for the first HFS+ bootable
          partition (or EFI with boot1f32) in the GPT and boots it
        - if still not found, then continues with the next drive
    - if all drives are searched and nothing found, finishes with "boot0: error"


I'm 99% sure I can make it. Have code for it which compiles (nasm works on Win laptop), but can not test it until I get back home. If anybody feels adventurous and wishes to mess with MBR boot loader I can post untested code.

Later added  "(or EFI with boot1f32)" since I forgot that.
Title: Re: boot0md: dual boot Windows 7 and Mac OSX from Win7 drive
Post by: D-an-W on July 21, 2011, 07:42:01 PM
Excuse my ignorance here...but  ::)

Does this mean I can have a HD attached with a Windows 7 install via USB2.0 and boot from it should I need to run something that won't work from Parallels (I do have a working Chamelon partition up and running with the latest build thanks to some great work by blackosx)?

Using...where X is the Windows 7 HD?

Code: [Select]
fdisk440 -f boot0md -u -y /dev/rdiskX
Title: Re: boot0md: dual boot Windows 7 and Mac OSX from Win7 drive
Post by: Gringo Vermelho on July 22, 2011, 12:34:38 AM
As long as it's properly detected by your BIOS and can boot by itself if set as primary boot device, your USB hard drive with Windows 7 on it should show in the Chameleon GUI already. You don't have to install anything on your Windows 7 drive. You should be able to boot it from Chameleon installed to your OS X drive, using the boot selector.

This has been possible for a long time but the problem is that when you boot Windows 7 from another HDD (i.e. from your OS X drive with Chameleon installed on it) hibernation and hybrid sleep doesn't work and you can't install Service Pack 1. As I understand it, dmazar's code fixes this.

 



 
Title: Re: boot0md: dual boot Windows 7 and Mac OSX from Win7 drive
Post by: Blackosx on July 22, 2011, 01:10:54 PM
It seems it will be possible to make one universal boot0. But before that I'll write down simplified explanation for each boot0 version. It helps me to see what's going on. I hope I did not make mistakes there ...
Hi dmazar

hmm. At first look, this is a bit of a mind-bender, but I'm interested in your positive approach here. :)
I'm a bit busy right now so I haven't got time to look in detail but I would say your summary looks about right.

Few conclusions from the above:
----
boot0, boot0hfs and boot0md behaves differently only if booted from MBR or hybrid discs, while if booting from GPT disks they do the same: boot first HFS+ partition.
Most (if not all) users will either be using hybrid MBT/GPT or MBR.

Back to "universal" boot0. I think I can add one more pass to boot0md with minimal changes to the existing code. This would cover searching for active HFS+ partition in MBR plus boot0md (extended boot0hfs) functionality.
.../snip/...
I'm 99% sure I can make it. Have code for it which compiles (nasm works on Win laptop), but can not test it until I get back home. If anybody feels adventurous and wishes to mess with MBR boot loader I can post untested code.
This would be a marvellous piece of coding if it works, though I have yet to sit down and actually get my head around your solution. But if you could make a test a binary available then I'll try to find time to run some trials.
Title: Re: boot0md: dual boot Windows 7 and Mac OSX from Win7 drive
Post by: dmazar on July 22, 2011, 10:25:09 PM
Src and binary attached. Work in progress. If it does not work (which would not be a surprise), I'll debug it when I get back home.
Title: Re: boot0md: dual boot Windows 7 and Mac OSX from Win7 drive
Post by: dmazar on July 22, 2011, 10:32:45 PM
Using...where X is the Windows 7 HD?

Code: [Select]
fdisk440 -f boot0md -u -y /dev/rdiskX

I agree with Gringo Vermelho. I got the impression that you would boot that USB Win rarely, so you probably do not need hybrid sleep and stuff. You should be able to boot it from Chameleon or by selecting USB drive from BIOS. I see no need to install anything additionally.
Title: Re: boot0md: dual boot Windows 7 and Mac OSX from Win7 drive
Post by: Azimutz on July 23, 2011, 05:03:12 AM
Ok, i'm on to it :P in fact, i already have; been without network for last couple of days so,
i dedicate the extra free time to put some stuff up to date.

Will post details later... so far so good, looks promising.
Title: Re: boot0md: dual boot Windows 7 and Mac OSX from Win7 drive
Post by: dmazar on July 27, 2011, 12:30:20 AM
Since boot0 and variants need to fit into 440 bytes of MBR it's good to know where to find more space if it would be needed for future requirements. Since I'm messing with boot0 currently, I'll write some ideas. Do not know where to put it, so I'll put it here. May be of some use to somebody in the future.



Shrinking of "user interface"
--------------------------
I'll try not to go too deep into the code here to make this useful to decision makers who do not need to know coding details.

boot0 writes some messages if compiled in VERBOSE mode which is default:
boot0: GPT - after positive check fo GPT and right before scanning GPT array for HFS+ partition
boot0: test - right before checking HFS+ partition for HFS+ signature
boot0: done - after bootable partition is found and before passing control to it's boot loader
boot0: error - if no bootable partition is found

Some space may be made free by removing or shrinking those messages. I'll list some examples here to help get some feeling about what can be done.

Example 1: setting VERBOSE=0 leaves only "boot0: error" message
= releases 32 bytes

Example 2: removal of "boot0: GPT" and "boot0: test" messages
and leaving done and error messages
= releases 21 bytes

;LogString(gpt_str) ; 6 bytes
;LogString(test_str) ; 6 bytes
...
;gpt_str         db  'GPT', 0 ; 4 bytes
;test_str      db  'test', 0 ; 5 bytes

= releases 6 + 6 + 4 + 5 = 21 bytes

Example 3: extreme: no messages at all by removing all "UI" code and data
= releases 84 bytes in current boot0 (19% of the total 440 bytes space).

Example 4: remove all messages and just write character '-' in case of error
by removing all UI code except print_char and using it to print '-'
= releases 69 bytes


I think that playing with "UI" is the most easier and most effective way of getting more space. This should be considered first if more space for code would be needed.
Title: Re: boot0md: dual boot Windows 7 and Mac OSX from Win7 drive
Post by: dmazar on July 27, 2011, 12:35:27 AM
GPT disk check
--------------
I'll need to try to explain this with some pseudo code. Do not know how to do it without that.

Currently, checking if disk is GPT works like this:

Code: [Select]
// following is part of MBR partition table scanning
// iterating over MBR records:
BL = 0; // flag if protective MBR entry (type 0xEE) is found
for i = 0 to 3 {
    ...
    // if protective entry is found then set it inactive
    // and set flag BL = 1
    if (partition[i].type == 0xEE) {
        partition[i].flag = inactive;
        BL = 1;
    }
    ...
}
// if protective MBR entry was found then call checkGPT()
if (BL == 1) {
    checkGPT();
}
...
// checkGPT()
// checks if sector 1 starts with "EFI PART"
// and then scans GPT partitions
checkGPT() {
    if (sector 1 does not start with "EFI PART") {
        return;
    }
    ...
}

It seems to me that checking for "EFI PART" in sector 1 is enough and the code could be made smaller by removing BL flag. This means checkGPT would be called even on pure MBR disk, but there is no harm in this - "EFI PART" will not be found.

Code: [Select]
// MBR partition table scanning
for i=0 to 3 {
    ...
    if (partition[i].type == 0xEE) {
        partition[i].flag = inactive;
    }
    ...
}
// always call checkGPT(), it will do it's own checking
// no harm in doing that check even on pure MBR disk
checkGPT();
...
// and checkGPT() as before
checkGPT() {
    if (sector 1 does not start with "EFI PART") {
        return;
    }
    ...
}

this releases 6 bytes.

And, if we assume that in normal setups protective MBR entry will always be inactive (it's nonsense to put it active, but this should be investigated more), then code can be further reduced:

Code: [Select]
// MBR partition table scanning
for i=0 to 3 {
    ...
    // no MBR protective enrty checking at all
    ...
}
// always call checkGPT(), it will do it's own checking
checkGPT();
...
// and checkGPT() as before
checkGPT() {
    if (sector 1 does not start with "EFI PART") {
        return;
    }
    ...
}

this releases 15 bytes in total.
Title: Re: boot0md: dual boot Windows 7 and Mac OSX from Win7 drive
Post by: KillerJK on August 02, 2011, 07:34:43 PM
This is a minor thing, as I suppose boot0 and boot0hfs will eventually be replaced by boot0md, but anyway...

In boot0hfs.s, line 357
Code: [Select]
.switchPass2:
    ;
    ; Switching to Pass 2
    ; try to find a boot1h aware HFS+ MBR partition

That's good for boot0.s. Pass2 in boot0hfs.s is however checking for an active partition

Also, if you really really need a couple of extra bytes after all those optimizations, some jmp can be changed by a jmp short. This is automatically done by the assembler if you use -Ox. There are some problems with this because xcode has an obsolete assembler, different versions use different default arguments and -O2 in the version used by xcode has a bug that was preventing it from successfully assembling boot0. If you ever need it I documented those things in the .swithPass2 patch http://forum.voodooprojects.org/index.php/topic,1813.0.html (http://forum.voodooprojects.org/index.php/topic,1813.0.html).

So, because the optimization flag wasn't in the makefile, I added a few shorts and some other changes. My lazy way of finding jmps I could replace was comparing the optimized and unoptimized hex dumps, and also moving code around.

Title: Re: boot0md: dual boot Windows 7 and Mac OSX from Win7 drive
Post by: dmazar on August 03, 2011, 10:44:01 AM
Hi KillerJK. Thanks. I've seen your posts - made me realize that one jump in boot0md was not optimized. That was fixed in the "work" version.

Regarding optimizations and my previous post:
Quote
And, if we assume that in normal setups protective MBR entry will always be inactive (it's nonsense to put it active, but this should be investigated more), then code can be further reduced:

It seems that part can not be removed:
http://forum.voodooprojects.org/index.php?topic=572.0
Title: Re: boot0md: dual boot Windows 7 and Mac OSX from Win7 drive
Post by: dmazar on August 03, 2011, 05:06:42 PM
I wanted to finish what was started and done some tests with boot0work code. It does it's job as planned, although I do not have enough experience to judge if this would cover all installations. I'll leave it to you guys.

New src and bin attached. Different debugging added. If compiled with DEBUG=0 gives the same code as previous version. DEBUG=1 gives the code with debug output (info in the src).


Test cases:  :o
-----------

A) boot0md functionality

Disk0: MBR (boot0work), P1=Win7 (NTFS, bootable, active)
Disk1: GPT (boot0work), P1=EFI, P2=MacOSX Lion (HFS+, boot1h, boot), P3=MacOSX Lion Inst (HFS+, boot1h, boot), P4=MacOSX SL (HFS+, boot1h, boot)

TC 1: boot from Disk0, loads Cham. from Disk1/P2, can boot all, Win7 hybrid sleep works - OK
debug: P Dptppp P Dptppp DptpppGll+ => Pass2, GPT found, loading from second GPT partition

TC 2: Disk1 removed, boot from Disk0, loads Win7 from Disk0/P1, Win7 hybrid sleep works - OK
(to test what would happen with Win7 if Cham is not available any more)


B) boot0 functionality: search active HFS+ on boot disk only
note 1: orig. boot0 searches for any active partition. boot0work can not do that since this would break boot0md functionality
note2: tests were done by loading Chameleon installs from USB disk and loading OSes from other disks. USB partitions contained only Cham. and not full OSes. I was testing if stage 0 code can find valid partition to load stage 1 and stage 2. OS loading is stage 2 job, anyway.

Disk0 and Disk1 as above, plus
USB Disk: MBR (boot0work), P1=exFAT, P2=HFS+ (boot1h, boot), P3=HFS+ (boot1h, boot)

TC 3: USB/P3 set active, boot from USB, loads Cham. from USB/P3, can boot all - OK
debug: P Dptptptl+ => Pass1, loading active P3

TC 4: USB/P2 set active, boot from USB, loads Cham. from USB/P2, can boot all - OK
debug: P Dptptl+ => Pass1, loading active P2


C) boot0hfs functionality: find first bootable HFS+
disk setup as in B)

TC 5: USB/P1 set active, boot from USB, loads Cham. from USB/P2, can boot all - OK
debug: P Dptptptp P Dptptl+ => Pass2, loading first bootable HFS+, USB/P2

TC 6: boot from Disk1, loads Cham. from Disk1/P2, can boot all - OK
debug: P DptpppGll+ => Pass1, GPT found, loading from first HFS+ bootable partition


D) boot from EFI

TC 7: USB Disk: GPT (boot0work), P1=EFI (boot1f32, boot), P2=HFS+ (not bootable), P3=HFS+ (not bootable)
USB formatted to GPT, Cham. added to EFI, boot from USB, loads Cham. from USB/P1 EFI, can boot all - OK
debug: P DptpppGl+ => Pass1, GPT disk, loading from EFI

TC 8: USB Disk: GPT (boot0work), P1=EFI (HFS+, boot1h, boot), P2=HFS+ (not bootable), P3=HFS+ (not bootable)
USB formatted to GPT, EFI formatted to HFS+, Cham. added to EFI, boot from USB, loads Cham. from USB/P1 EFI, can boot all - OK
debug: P DptpppGl+ => Pass1, GPT disk, loading from EFI - OK
Title: Re: boot0md: dual boot Windows 7 and Mac OSX from Win7 drive
Post by: Azimutz on August 22, 2011, 03:54:59 PM
Ok, i found my previous notes from testing boot0work (thought they were lost);
i'm testing again and the results so far match the previous ones, which are not exactly as i recalled.

In case someone read my previous post (replaced by this one), i'll post it again, this time
with fresh info :P
Title: Re: boot0md: dual boot Windows 7 and Mac OSX from Win7 drive
Post by: dmazar on August 22, 2011, 10:46:58 PM
I just came back here to write a reply to your previous post, and found out that I do not need to do that. Well,  this saves me some minutes ;D
Title: Re: boot0md: dual boot Windows 7 and Mac OSX from Win7 drive
Post by: Azimutz on August 23, 2011, 02:12:26 PM
Ok, glad i posted the warning ;D
I have most of the testing done. Checking now against your results; i have some conflicting results so,
i'm repeating some of the test cases, in case i messed up something or didn't noticed other/s.
I'll post results later today; this time will not stop until this is done :)
Title: Re: boot0md: dual boot Windows 7 and Mac OSX from Win7 drive
Post by: Azimutz on August 25, 2011, 03:01:47 PM
Hi Dmazar, here i am... sorry for the delay, was caught in traffic :P

So, at the time of this post
Ok, i'm on to it :P in fact, i already have; been...

Will post details later... so far so good, looks promising.
i had done a ton of testing with boo0work (http://forum.voodooprojects.org/index.php/topic,2091.msg10427.html#msg10427), but the notes i had taken where lost and i was posting from memory;
after finding the notes, i realized that my memory was too optimistic regarding the Hibernation feature.
Since i was going to repeat the tests, i decided to delete the "too hib optimistic" post, which i'm now editing.

Straight to the point, my test scheme is a bit diff, but confirms your results;
first my device layout:
Code: [Select]
/dev/disk0
    #:                       TYPE NAME                    SIZE       IDENTIFIER
    0:     FDisk_partition_scheme                        *320.1 GB   disk0
    1:               Windows_NTFS Windows 7               64.4 GB    disk0s1 <- active
    2:                      Linux                         32.2 GB    disk0s2
    3:                  Apple_HFS empty                   17.2 GB    disk0s3 <- test, OS X installer, etc...
    4:                  Apple_HFS Hyperspace              206.3 GB   disk0s4 <- data/boot1h
 /dev/disk1
    #:                       TYPE NAME                    SIZE       IDENTIFIER
    0:      GUID_partition_scheme                        *500.1 GB   disk1
    1:                        EFI                         209.7 MB   disk1s1
    2:                  Apple_HFS Snow                    100.0 GB   disk1s2 <- main system/boot1h
    3:                  Apple_HFS Home                    200.0 GB   disk1s3
    4:                  Apple_HFS Leo                     25.0 GB    disk1s4
    5:                  Apple_HFS Tiger                   25.0 GB    disk1s5
    6:                  Apple_HFS Lab                     25.0 GB    disk1s6
 /dev/disk2
    #:                       TYPE NAME                    SIZE       IDENTIFIER
    0:     FDisk_partition_scheme                        *2.0 GB     disk2
    1:                 DOS_FAT_32 PAPPS                   1.8 GB     disk2s1
    2:                  Apple_HFS Chazi                   213.6 MB   disk2s2 <- active
disk2 is my usual rescue usb stick, others are the local disks.
Disk0 is the first bios device, but disk1 is usually the first device selected on bios.
They all have boot0work installed (now V2) since those first tests, meaning that i've been using it
on a day to day basis, which is already a good test result :)

Booting from disk0:
Quote
active = win

-----//-----
usual setup
stage1 = d0s4, d1s2, d2s2 Finds: d0s4 - hib Ok
PD pt pt pt pt
PD pt pt pt L pt L

-----//-----
finds stage1 on the other disks?
stage1 = none, d1s2, none/d2s2 Finds: d1s2 - hib Ok
PD pt pt pt pt
PD pt pt pt L pt L
  D pt ppp G L L

stage1 = none, none, d2s2 Finds: d2s2 - hib Ok
PD pt pt pt pt
PD pt pt pt L pt L
  D pt ppp G L L L L L L
  D pt pt L

stage1 = none, none, none Finds: boots windows directly - hib Ok
PD pt pt pt pt
PD pt pt pt L pt L
  D pt ppp G L L L L L L
PD pt pt L

Booting from disk1:
Quote
active = doesn't apply on GPT

-----//-----
usual setup
stage1 = d0s4, d1s2, d2s2 Finds: d1s2 - hib No - resume/hib Ok
PD pt ppp G L L

-----//-----
finds stage1 on the other disks?
stage1 = d0s4, none, none/d2s2 Finds: d0s4 - hib No - resume/hib Ok
PD pt ppp G L L L L L L
PD pt ppp G L L L L L L
  D pt pt pt L pt L

stage1 = none, none, d2s2 Finds: d2s2 - hib No - resume/hib Ok
PD pt ppp G L L L L L L
PD pt ppp G L L L L L L
  D pt pt pt L pt L
  D pt pt L

stage1 = none, none, none Finds: boots windows directly - hib No - resume/hib Ok
PD pt ppp G L L L L L L
PD pt ppp G L L L L L L
  D pt pt pt L pt L
PD pt ppp G L L L L L L
  D pt L

Booting from disk2 (external USB):
Quote
active = s2

-----//-----
usual setup
stage1 = d0s4, d1s2, d2s2 Finds: d2s2 - hib No - resume/hib OK
PD pt pt L

-----//-----
finds stage1 on the other disks?
stage1 = d0s4, d1s2, none Finds: d0s4 - hib No - resume/hib OK
PD pt pt L pp
PD pt pt L pp
  D pt pt pt L pt L

stage1 = none, d1s2, none Finds: d1s2 - hib No - resume/hib OK
PD pt pt L pp
PD pt pt L pp
  D pt pt pt L pt L
  D pt ppp G L L

stage1 = none, none, none Finds: boots windows directly - hib No - resume/hib Ok
PD pt pt L pp
PD pt pt L pp
  D pt pt pt L pt L
  D pt ppp G L L L L L L
PD pt pt L pp
  D pt L
I did small variations from the above, that only confirmed these results (and others):
- active partition with boot1 is always found
- first hfs partition with boot1 is always used
- Windows always hibernates if it was launched by the boot0 on it's device

This time i'm not going to be so optimistic :)
Just going to say that from my point of view, i see no reason for not using boot0work as the only boot0.
The compromise between debug/verbose is acceptable, since the booter couldn't be compiled with both
enabled before. Any technical problems on the horizon?
There's already an issue (http://forge.voodooprojects.org/p/chameleon/issues/142/) filed on the forge; i recommended that we keep boot0 around, at least while we test,
but i think boot0hfs can be wiped out for good.




About bugs, going to mention this situation mostly to get your opinion and because i think it has to do with boot0!?

I came across this, one time i messed up the GPT table on disk1, and tested it a couple of times after that.
The outcome in this situation is that i'm no longer able to boot, even from the usb stick,
since the damaged table seems to be always checked and the boot just hangs (if i do recall...).
The obvious question is, can we make the booter fall back to one of the undamaged disks in a situation like this?

Just as info, the GPT table corruption was caused by Testdisk, while testing on Windows,
after a quick ride on OS X were it runs on read only mode by default, which seems not to be the case on Windows >:(
The solution at the time was, use SuperGrub to load grub on disk0s2 and boot to both Linux or Windows to look for a
solution; it didn't took long to find gdisk, but it took hours of reading to use it to fix the table.
In the end, i managed to edit the table, all came out good and it turned into an educational experience ;D
Needless to say that, these days i make sure everything is properly backed up on the usb stick, before i do such tests.
 
Ok, be back later...
And thanks for your work :)
Title: Re: boot0md: dual boot Windows 7 and Mac OSX from Win7 drive
Post by: Blackosx on August 26, 2011, 12:26:57 PM
Hi dmazar

Well done for finishing up here and posting your revised work. I've been busy with other stuff lately and haven't really had the time to run any thorough tests at my end, though I've been using the boot0work v2 for a little while now and have had no issues.

The tests both you and Azi have conducted show success in all areas. This is great and maybe this could become the one and only boot0?  I'll try to run some tests of my own this weekend.
Title: Re: boot0md: dual boot Windows 7 and Mac OSX from Win7 drive
Post by: dmazar on August 28, 2011, 11:10:21 AM
Hi Azimutz. Thanks for this. I'm not the only one with long hard-to-read posts here any more.  ;D

I've only changed few lines in existing boot0 (99% is already existing code) and it took me more time for testing then actual coding. So I guess you also spent more time testing it then I did coding. Thanks.

There's already an issue (http://forge.voodooprojects.org/p/chameleon/issues/142/) filed on the forge
I did not understand this one. What's the issue here?

I'll write an answer on "About bugs" part later after checking the code.

This is great and maybe this could become the one and only boot0?
That was the plan. At least for me when I realized it could be done with just few tweaks. But my Hackintosh/OSX experience is limited to few months and I do not know if it covers all situations. I do not have experience with RAID, for example.

Regarding one and only boot0: somebody will have to add support for Advanced format 4K disks (not AF 512 emulation) soon, and who knows ... maybe this will require two separate boot0 again.
Title: Re: boot0md: dual boot Windows 7 and Mac OSX from Win7 drive
Post by: Azimutz on August 28, 2011, 07:39:46 PM
Hi Azimutz. Thanks for this. I'm not the only one with long hard-to-read posts here any more.  ;D
yeah, i have a natural tendency for those ;D

... So I guess you also spent more time testing it then I did coding. Thanks.
yep, your guess is right... i guess :lol:
You're welcome :) it's for a good cause. Sorry for taking so long to feedback...

I did not understand this one. What's the issue here?
aah... there's no real issue; in this case the issue on the forge is just a "todo".

I'll write an answer on "About bugs" part later after checking the code.
No hurries...

... I do not have experience with RAID, for example.

Regarding one and only boot0: somebody will have to add support for Advanced format 4K disks (not AF 512 emulation) soon, and who knows ... maybe this will require two separate boot0 again.
Yes, we do need some RAID testing (can't do it my self atm); i also didn't tested boot1f32 but will soon.
And you're probably right on the 4k disks... we'll see...
Title: Re: boot0md: dual boot Windows 7 and Mac OSX from Win7 drive
Post by: dmazar on August 28, 2011, 11:47:06 PM
About bugs, going to mention this situation mostly to get your opinion and because i think it has to do with boot0!?

I came across this, one time i messed up the GPT table on disk1, and tested it a couple of times after that.
The outcome in this situation is that i'm no longer able to boot, even from the usb stick,
since the damaged table seems to be always checked and the boot just hangs (if i do recall...).
The obvious question is, can we make the booter fall back to one of the undamaged disks in a situation like this?

As far as I can see, boot0work searches/checks for valid HFS+ partition type (in MBR and GPT), for GPT signature and boot signature (for boot0 and boot1) before loading and jumping to boot1.

In case of disk corruption, proper way would be to check GPT table CRC and then use backup GPT table, but this is not an option due to limited code size.

What happens currently is: if above checks are not present, boot0work will skip to the next disk. But in some cases it will just write boot0: error and stop. This will happen if partition types and/or GPT signature are ok, but some LBA (GPT array LBA or partition start LBA) are invalid for this disk (pointing to non existing blocks). And this will happen on my hard disk only - on my usb it gets over it and skips to another disk (I could not resist to test it).

This could lead to a non-booatable system in some cases. For example on my current setup:
disk0: windows with boot0work in MBR
disk1: GPT disk with OSX
If disk1 GPT gets corrupted in a way that boot0 stops with boot0: error, then I can not boot windows also any more (phase1: hfs+ not found on disk0, phase2: stops on disk1 and never gets to phase 3 to load windows from disk0 as active partition).
My options then would be to disconnect disk1 (boot0work would load windows in that case), or use usb/cd/dvd to boot windows, linux or other to recover GPT disk. And then to spend 2 hours on trying to fix it with iBored, find out that it does not work properly for some reason and then to realize that gdisk for windows exists which is able to do the job. Excellent. Well ... this could all happen. Or happened.  :lol no:

Anyway, this stopping of disk scanning can be resolved by changing two lines of the boot0work code:

line 533 in checkGPT: (old code commented with ; new added)
;jc       error
jc       .exit


and line 606 in loadBootSector
;jc      error
or   dl, dl ; to set flag Z=0
jc      .exit

I could not resist to test it, and it seems to work. But full testing requires going through all normal tests again plus corrupting GPT table in various ways and make more tests. That's not easy, and … hm, not very interested in doing it. It does not look so important to me, or …?

Hm, wanted to make small post, but it turned into large one again. Maybe next time ...  :)
Title: Re: boot0md: dual boot Windows 7 and Mac OSX from Win7 drive
Post by: Azimutz on September 06, 2011, 08:47:24 AM
Back :)
Dmazar, just came from testing the GPT corruption and it seems my memory may have done it again..!?
Well, i also understand this stuff a little better now and the debug build helps spotting the problem.
So, i patched boot0work as you instructed and installed it to the usb stick.
Then booted windows and with gdisk, backup + print + verify GPT:
Code: [Select]
Command (? for help): p
Disk /dev/disk1: 976773168 sectors, 465.8 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): 68E983C6-1E81-4FC3-ACF1-3C8455A5413F
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 976773134
Partitions will be aligned on 8-sector boundaries
Total free space is 243941613 sectors (116.3 GiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1              40          409639   200.0 MiB   EF00  EFI System
   2          409640       195722143   93.1 GiB    AF00  Snow
   3       195984288       586609287   186.3 GiB   AF00  Home
   4       586871432       635699559   23.3 GiB    AF00  Leo
   5       635961704       684789831   23.3 GiB    AF00  Tiger
   6       685051976       733880103   23.3 GiB    AF00  Lab

Command (? for help): v

No problems found. 243941613 free sectors (116.3 GiB) available in 6
segments, the largest of which is 242893031 (115.8 GiB) in size.
Note that i have unpartitioned space after part 6.
Next to mess the GPT, used Testdisk to change EFI partition type to EFI, FAT32;
it's the closest i can get to the original circumstances and never fails ;D the result:
Code: [Select]
Command (? for help): p
Disk \\.\physicaldrive1: 976773168 sectors, 465.8 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): CABED121-6A46-7F44-ACA5-6F75B0703CB3        <---
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 976773134
Partitions will be aligned on 8-sector boundaries
Total free space is 146285357 sectors (69.8 GiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1              40          409639   200.0 MiB   EF00
   2          409640       195722143   93.1 GiB    AF00
   3       195984288       586609287   186.3 GiB   AF00
   4       586609288       635437415   23.3 GiB    AF00            <---
   5       635440902       684269029   23.3 GiB    AF00
   6       684527684       733355811   23.3 GiB    AF00
   7       733617956       782446083   23.3 GiB    AF00
   8       782970372       831798499   23.3 GiB    AF00

Command (? for help): v

Problem: The CRC for the backup GPT header is invalid. The backup GPT header
may be corrupt. Consider using the main GPT header to rebuild the backup GPT
header ('d' on the recovery & transformation menu). This report may be a false
alarm if you've already corrected other problems.

Caution: Partition 5 doesn't begin on a 8-sector boundary. This may
result in degraded performance on some modern (2009 and later) hard disks.

Caution: Partition 6 doesn't begin on a 8-sector boundary. This may
result in degraded performance on some modern (2009 and later) hard disks.

Caution: Partition 7 doesn't begin on a 8-sector boundary. This may
result in degraded performance on some modern (2009 and later) hard disks.

Caution: Partition 8 doesn't begin on a 8-sector boundary. This may
result in degraded performance on some modern (2009 and later) hard disks.

Consult http://www.ibm.com/developerworks/linux/library/l-4kb-sector-disks/
for information on disk alignment.

Identified 1 problems!
Like this i can't boot from any device.
It get's passed the boot0 debug output and hangs at the first spin or two of the cursor,
which means boot0 is not involved, right!? If so, sorry to make you waste time with this.

Thanks. See ya later...
Title: Re: boot0md: dual boot Windows 7 and Mac OSX from Win7 drive
Post by: dmazar on September 10, 2011, 04:26:20 PM
Quote
Like this i can't boot from any device.
It get's passed the boot0 debug output and hangs at the first spin or two of the cursor,
which means boot0 is not involved, right!?
Seems so. If you are booting from this drive, then I guess boot0 will find boot1 on 2nd partition and continue with booting, but since GPT is not valid, maybe Chameleon stage 3 gets confused. Anyway, I guess you would not be able to boot anything from this drive, but if the issue here is in the stage 3, then this could be fixed to allow to boot from some other drive.

boot0 fix from my previous post would deal with the  corruption of LBAs (GPT array LBA or partition start LBA), but only if those LBAs are out of the range for the current disk. This is just to avoid boot0 from stopping in case of errors and to allow it to continue with boot1 search on other partitons and disks.
Title: Re: boot0md: dual boot Windows 7 and Mac OSX from Win7 drive
Post by: Azimutz on September 11, 2011, 05:00:03 AM
Seems so. ...
Definitely is. I gave it another try and i can clearly see "boot1:/boot" before the spinning cursor.
I really only mentioned this because it seemed a boot0 thing; as i mentioned the debug build helps...
it's the first time i see any debug on boot0; boot1 also fails to compile with debug enabled.

If you are booting from this drive, then I guess boot0 will find boot1 on 2nd partition and continue with booting, but since GPT is not valid, maybe Chameleon stage 3 gets confused.
yep, your guess is right, just it fails from any drive.
You mean stage2 (/boot), right!?

Anyway, I guess you would not be able to boot anything from this drive, but if the issue here is in the stage 3, then this could be fixed to allow to boot from some other drive.
 
Super Grub does load a OS X, not sure which one though... will check again, got me curious now.
If you say it can be fixed on stage2, i believe :P i'm pretty noob at this stuff and
this falls on an area of the code i don't know that well.

boot0 fix from my previous post would deal with the  corruption of LBAs (GPT array LBA or partition start LBA), but only if those LBAs are out of the range for the current disk. This is just to avoid boot0 from stopping in case of errors and to allow it to continue with boot1 search on other partitons and disks.
I got it, but don't know how to test this specific scenario.
Title: Re: boot0md: dual boot Windows 7 and Mac OSX from Win7 drive
Post by: dmazar on September 11, 2011, 08:45:46 AM
You mean stage2 (/boot), right!?
stage2, yes. sorry.

boot0 fix from my previous post would deal with the  corruption of LBAs (GPT array LBA or partition start LBA), but only if those LBAs are out of the range for the current disk.
I got it, but don't know how to test this specific scenario.
I was using iBored to write large numbers to those LBAs. Was doing that from Windows, but had some problems with it. I got the impression that Windows or iBored is making some changes to GPT header also in the background and it get hard to make desired corruption. It would be ideal to boot in some os that does not understand GPT and use disk editor from there, I guess.
Title: Re: boot0md: dual boot Windows 7 and Mac OSX from Win7 drive
Post by: Azimutz on September 17, 2011, 05:21:27 PM
Well, i will get back to this from time to time; it's not a major fatality so...

About boot0work, think you already know my opinion; i'm using it and pretend to keep using ;)
Title: Re: boot0md: dual boot Windows 7 and Mac OSX from Win7 drive
Post by: Blackosx on September 18, 2011, 10:54:04 AM
Quick update from me just to say I have been using boot0workV2 (http://forum.voodooprojects.org/index.php/topic,2091.msg10551.html#msg10551) for a month now with no issues whatsoever. The other day I made dmazar's amends (http://forum.voodooprojects.org/index.php/topic,2091.msg10804.html#msg10804) and have not seen anything untoward. I'll keep running this version from now on and report if I ever come across any issues (which I don't expect), though I won't be corrupting any GPT tables here  :P.
Title: Re: boot0md: dual boot Windows 7 and Mac OSX from Win7 drive
Post by: Azimutz on September 18, 2011, 01:42:41 PM
... though I won't be corrupting any GPT tables here  :P .
:lol no: why not?1... it's so funny :P
yeah, my only doubt is RAID; i don't expect problems with it, but it would be nice having someone testing it.
Title: Re: boot0md: dual boot Windows 7 and Mac OSX from Win7 drive
Post by: Blackosx on September 19, 2011, 12:50:15 PM
:lol no: why not?1... it's so funny :P
Lol.. maybe one day if I get bored.  :P

I agree to the need to having dmazar's latest amends tested by a RAID user. Maybe we can create a topic somewhere for RAID users to test and give feedback?
Title: Re: boot0md: dual boot Windows 7 and Mac OSX from Win7 drive
Post by: dmazar on September 19, 2011, 06:30:46 PM
... though I won't be corrupting any GPT tables here  :P .
:lol no: why not?1... it's so funny :P
People are eating bugs, making tattoos all over the body, having S/M sex, joining political parties and all kind of stuff ... but corrupting GPT tables ... that's weird man.  :P
Title: Re: boot0md: dual boot Windows 7 and Mac OSX from Win7 drive
Post by: Azimutz on September 19, 2011, 09:08:28 PM
People are eating bugs, making tattoos all over the body, having S/M sex, joining political parties and all kind of stuff ... but corrupting GPT tables ... that's weird man.  :P
That's why i'm leaving it alone for now :P before it turns to some weird obsession...

Lol.. maybe one day if I get bored.  :P
;D

I agree to the need to having dmazar's latest amends tested by a RAID user. Maybe we can create a topic somewhere for RAID users to test and give feedback?
 
No more topics, please :P someone with a RAID volume will eventually stumble with this one, or be forced to ;)
I meant to set up one, but i can't find a WD5000AACS (500GB caviar green, 16MB cache) anymore on the stores
to pair with the one i have and i ain't gonna pay 75€ for one over the net, when the new 1TB (32MB cache) ones
are cheaper in the store (around 60€). Also, the new 500GB ones don't even use 16MB cache anymore.
Just need to get my budget a tad fatter :)
Title: Re: boot0md: dual boot Windows 7 and Mac OSX from Win7 drive
Post by: Blackosx on October 30, 2011, 10:41:47 AM
Quick update from me just to say I have been using boot0workV2 (http://forum.voodooprojects.org/index.php/topic,2091.msg10551.html#msg10551) for a month now with no issues whatsoever. The other day I made dmazar's amends (http://forum.voodooprojects.org/index.php/topic,2091.msg10804.html#msg10804) and have not seen anything untoward. I'll keep running this version from now on and report if I ever come across any issues (which I don't expect), though I won't be corrupting any GPT tables here  :P.
I've applied these changes to the boot0md code in the trunk.
Title: Re: boot0md: dual boot Windows 7 and Mac OSX from Win7 drive
Post by: presley on November 04, 2011, 09:00:51 PM
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
Hi,

I can't make to boot W7...
-Source files must be puted in i386/boot0/ of Chameleon source tree and compiled... I have puted files boot0md.s and Makefile, but how to compile it?
-MBR has updated with boot0md.

My configuration now:

Disk0: MBR (boot0md), P1=Win7 (NTFS, bootable, active)
Disk1: P1=MacOSX 10.7.2

BIOS boots from Disk0 with Win7:
-boot shows Chameleon menu with MacOSX and Win7:
  if select MocOSX it boot
  if select W7 - don't boot (BOOTMGR IS MISSING)
BIOS boots from Disk1 with MacOSX:
 the same situation.

If removing Disk1 with MacOSX - Windows7 boot.
I think it happens because chameleon not compiled.
Title: Re: boot0md: dual boot Windows 7 and Mac OSX from Win7 drive
Post by: Blackosx on November 04, 2011, 10:05:55 PM
if select W7 - don't boot (BOOTMGR IS MISSING)
How did you install boot0md?
Did you use fdisk440?
Title: Re: boot0md: dual boot Windows 7 and Mac OSX from Win7 drive
Post by: presley on November 05, 2011, 07:28:37 AM
Yes, I've used
sudo fdisk440  -f boot0md -u /dev/rdisk0 (Disk with Win7)

Mode Edit: Quote removed as there's no need to quote from a post directly above.
Title: Re: boot0md: dual boot Windows 7 and Mac OSX from Win7 drive
Post by: Blackosx on November 05, 2011, 08:45:57 AM
Have you a System Reserved partition? if so you need to select from that Chameleon to boot Windows 7.

I think it happens because chameleon not compiled.
It must be compiled as:
1) You can boot in to Chameleon from disk0, then in turn boot OS X on disk1.
2) You can boot Windows from disk0 when you disconnect disk1 (which is default behaviour for boot0md if it can't find a stage 1 booter).
Title: Re: boot0md: dual boot Windows 7 and Mac OSX from Win7 drive
Post by: dmazar on November 05, 2011, 09:30:48 AM
Presley, I would like to help, but do not know how.
Since you can boot OSX that means you are using Chameleon. This means that boot0 is done it's job (finding and starting Chameleon). This also means that you have it compiled.

As Blackosx said, maybe you are not choosing System reserved partition if you have one?
Title: Re: boot0md: dual boot Windows 7 and Mac OSX from Win7 drive
Post by: presley on November 05, 2011, 11:16:00 AM
I dont know why, but I've removed and reinstalled chameleon to newest version 2.1, puted mod files again and now Windows boot from Reserved partition  8)
Thanks Dmazar for great job!
Title: Re: boot0md: dual boot Windows 7 and Mac OSX from Win7 drive
Post by: dmazar on November 06, 2011, 12:17:36 AM
I'm glad you did it. And forwarding your thanks to guys who are working on Chameleon.  ;)
Title: Re: boot0md: dual boot Windows 7 and Mac OSX from Win7 drive
Post by: CoolFX on November 09, 2011, 10:13:44 PM
Hello...

Sorry to ask you guys for this ,but i just can't do it by myself.....

I have Chimera 1.6 and Lion on one drive and Windows 7 on the other (i dont have the system reserved partition).

This is my diskutil list:

/dev/disk0
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:     FDisk_partition_scheme                        *1.0 TB     disk0
   1:               Windows_NTFS Windows 7               150.0 GB   disk0s1
   2:                  Apple_HFS Downloads               450.1 GB   disk0s2
   3:                  Apple_HFS Time Machine            399.9 GB   disk0s3
/dev/disk1
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        *400.1 GB   disk1
   1:                        EFI                         209.7 MB   disk1s1
   2:                  Apple_HFS Lion                    399.7 GB   disk1s2

I downloaded boot0workV2 and in terminal i did :
sudo fdisk440 -f /Users/CoolFX/Downloads/boot0workV2/boot0md -u /dev/rdisk1

Now my windows dont boot by it self.... it only boots if i select it from chimera bootloader.

What am i doing wrong?
Please help me, this is driving me crazy!!!

Thank you!
Title: Re: boot0md: dual boot Windows 7 and Mac OSX from Win7 drive
Post by: Blackosx on November 09, 2011, 11:31:48 PM
So you have Chameleon already installed on disk1, along with your Lion partition, and you have written boot0md (boot0workV2) to the MBR of disk1. But from the diskutil list you posted, disk1 is your Lion installation?

Boot0md can be used in this way and that's how I use it, but from the OP, the main point of boot0md is:
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.
So didn't you mean to write boot0md to the first 440 bytes of the MBR for disk0?

For reference, the most recent version of the boot0md code (boot0workV2) is now in the Chameleon trunk code. I've attached it for reference:

If you feel you've damaged your MBR for Windows, then you can always repair your boot sector by booting from the Windows DVD.
Title: Re: boot0md: dual boot Windows 7 and Mac OSX from Win7 drive
Post by: CoolFX on November 10, 2011, 11:59:42 AM
Thanks for the quick reply Blackosx.

i downloaded your file and did the following:

computer-2:~ CoolFX$ diskutil list
/dev/disk0
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:     FDisk_partition_scheme                        *1.0 TB     disk0
   1:               Windows_NTFS Windows 7               150.0 GB   disk0s1
   2:                  Apple_HFS Downloads               450.1 GB   disk0s2
   3:                  Apple_HFS Time Machine            399.9 GB   disk0s3
/dev/disk1
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        *400.1 GB   disk1
   1:                        EFI                         209.7 MB   disk1s1
   2:                  Apple_HFS Lion                    399.7 GB   disk1s2
computer-2:~ CoolFX$ sudo fdisk440 -f /Users/CoolFX/Downloads/boot0md -u /dev/rdisk0
Password:

   -----------------------------------------------------
   ------ ATTENTION - UPDATING MASTER BOOT RECORD ------
   -----------------------------------------------------

Do you wish to write new MBR? [n] y
computer-2:~ CoolFX$ exit
logout

and the result is :
 - when i boot with the lion hard drive disabled on my bios: i get Boot0:Error
 - when i boot with the lion hard drive enabled on my bios: chimera loads up and i can boot both operating systems.

(remember Chimera is installed on Lion Hdd).

Your file is already compiled so i just have to do the command in terminal right?? do i have to reinstall chimera?
I'm completely lost here... Don't know what i'm doing wrong!
Thanks again...
Title: Re: boot0md: dual boot Windows 7 and Mac OSX from Win7 drive
Post by: dmazar on November 10, 2011, 12:44:26 PM
I guess the problem is because you have HFS partitions on Win drive. The first phase for boot0md is: search first drive for hfs+ bootable partition (partition with boot sector signature) - if found it will try to load from there

Can you try with debug version on disk0? it should write some letters which you can post here and we'll see what's happening. I'm attaching here some version from earlier post in this thread - can not build fresh one right now.
Title: Re: boot0md: dual boot Windows 7 and Mac OSX from Win7 drive
Post by: CoolFX on November 10, 2011, 08:33:41 PM
Ok Dmazar... Here it is!!

/dev/disk0
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:     FDisk_partition_scheme                        *1.0 TB     disk0
   1:               Windows_NTFS Windows 7               150.0 GB   disk0s1
   2:                  Apple_HFS Downloads               450.1 GB   disk0s2
   3:                  Apple_HFS Time Machine            399.9 GB   disk0s3
/dev/disk1
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        *400.1 GB   disk1
   1:                        EFI                         209.7 MB   disk1s1
   2:                  Apple_HFS Lion                    399.7 GB   disk1s2
computer-2:~ CoolFX$ sudo fdisk440 -f /Users/CoolFX/Downloads/boot0workDBG -u /dev/rdisk0
Password:

   -----------------------------------------------------
   ------ ATTENTION - UPDATING MASTER BOOT RECORD ------
   -----------------------------------------------------

Do you wish to write new MBR? [n] y


Now the results:

Bios with Lion hdd drive disabled:
PDptptlptpPDptptlptlpPDptptlptpE

Bios with Lion hard drive enabled but boot from windows hard drive:
PDptptlptpPDptptlptlpDptpppGll+

Bios with Lion hard drive enabled but boot from lion hard drive:
Both Operating Systems boot fine but windows don't have hibernation.

Hope this helps.... :)
Thanks...
Title: Re: boot0md: dual boot Windows 7 and Mac OSX from Win7 drive
Post by: dmazar on November 10, 2011, 09:40:32 PM
I think it helps.

Bios with Lion hdd drive disabled:
PDptptlptpPDptptlptlpPDptptlptpE
If I'm reading it correctly, active partition on first disk is disk0s2 but this one is not bootable. Make Win7 partition active and win7 should load if only this disk is enabled.

Bios with Lion hard drive enabled but boot from windows hard drive:
PDptptlptpPDptptlptlpDptpppGll+
This one boots from Win7 disk and is finding disk1s2 partition bootable. If you have Chameleon installed there it should allow you to boot win7 and hibernation should work. Is it working?

I'm attaching debug description. Hope this helps.
Title: Re: boot0md: dual boot Windows 7 and Mac OSX from Win7 drive
Post by: Blackosx on November 10, 2011, 09:47:05 PM
Hey dmazar. Thanks for helping out.
@CoolFX - you're in good hands now  :P
Title: Re: boot0md: dual boot Windows 7 and Mac OSX from Win7 drive
Post by: CoolFX on November 11, 2011, 12:44:36 AM
GREAT!!!! IT WORKED!!!!  ;D ;D ;D

I don't know how the hell did my windows partition got inactive!!!!
I've just marked has active on windows and boom, everything is working has it should now!!!!
I have a perfect dual boot Lion and Windows 7 fully working thanks to you guys!!!

I'm glad there are people like you guys helping us out!!!

Many many thanks Blackosx and dmazar.
Title: Re: boot0md: dual boot Windows 7 and Mac OSX from Win7 drive
Post by: dmazar on November 11, 2011, 10:40:49 AM
Good  :) Glad it works.

Hi Blackosx. This is the piece of puzzle I'm familiar with so ...  I'll try to help if I can.
Title: Re: boot0md: dual boot Windows 7 and Mac OSX from Win7 drive
Post by: CoBrA2168 on August 09, 2012, 12:49:26 AM
I just wanted to say that I signed up on these forums specifically to thank you guys for this work.

I was in a similar situation - I had Windows 7 on an SSD, OSX Mountain Lion on another, and I was trying to find an elegant way to pick my OS upon restart.  Chimera is great, but I found that my sleep wasn't working (and I spent hours trying to install Windows 7 SP1, don't get me started on that...).

This modification did the trick.  Thanks again!!
Title: Re: boot0md: dual boot Windows 7 and Mac OSX from Win7 drive
Post by: NaG8toR on February 21, 2013, 04:33:41 PM
this is my setup
Disk0: P1=System Reserved (NTFS, bootable, active), P2=Win7 (NTFS), , P3=MacOSX 10.8 (HFS+)
and i was trying dmazar(http://forum.voodooprojects.org/index.php/topic,2091.msg10290.html#msg10290) solution to fix win 7 hibernate/sleep problem. now i wrote the boot0md file from dmazar attached file to the System Reserved partition MBR and set Partition 2(win7) as active now when i try to boot to windows from chameleon it display some dummy characters on the screen and nothing but the Mac OSX still works fine.
so is it that i should have written the boot0md to the Partition 2(Win7) instead of the System Reserved one or is it some other problem.
thanks.
Title: Re: boot0md: dual boot Windows 7 and Mac OSX from Win7 drive
Post by: dmazar on February 21, 2013, 06:52:38 PM
Well, you do not need this solution (boot0md) if you have Win and OSX on the same disk. boot0md can help when Chameleon (and OSX) is on one disk and Windows on the other.

Plus you incorrectly installed boot0md to System Reserved partition PBR (Partition Boot Record = first sector of the partition) and by this destroyed Windows PBR boot code. boot0md is meant to be installed to disk MBR (Master Boot Record = first sector of the disk).

You'll have to boot with Windows install CD or USB and repair Windows boot. This would probably overwrite your Chameleon's boot0 (or boot0hfs) code in MBR and you will not be able to boot from the HD. You'll have to have USB with Chameleon to be able to boot OSX, and then you would be able to reinstall Chameleon's boot0 (I can recommend boot0hfs).
So:
1. make sure you have USB with Chameleon which you can use to boot OSX
2. boot from Win install and repair Win boot records
3. boot OSX from USB and repair Chameleon (use boot0hfs for MBR)
4. make System Reserved partition as active
Title: Re: boot0md: dual boot Windows 7 and Mac OSX from Win7 drive
Post by: NaG8toR on February 22, 2013, 07:29:13 AM
My Bad :-[ i figured that out yesterday and repaired windows with bootrec then redo ur method but this time
fdisk440  -f boot0md -u /dev/rdisk0 instead of fdisk440  -f boot0md -u /dev/disk0s1  :)
finally make System Partition active.
now everything works. Thank you dmazar for this awesome solution!!!
PS i needed this because if the System Reserved partition is the active one, it will go straight to windows and it'll never load Chameleon. but now with the boot0md on the MBR everything is working.
Title: Re: boot0md: dual boot Windows 7 and Mac OSX from Win7 drive
Post by: dmazar on February 22, 2013, 10:54:38 PM
Ok. Note that there are:
- boot0 - loads active partition from the disk
- boot0hfs - loads first bootable HFS+ (or EFI) partition from the disk, even if not marked active
- boot0md - similar to boot0hfs, but scans multiple disks