Author Topic: Removing the requirement for Chameleon (boot1h/boot) to be on active partition  (Read 41161 times)

0 Members and 1 Guest are viewing this topic.

r0m30

  • Forum Moderator
  • Posts: 98
    • r0m30's OSX86 site
If I'm out of line just let me know and I'll back off.

In my wonderings I noticed that the proposal to let Chameleon boot off a partition that wasn't the active partition didn't make it into the repo.  As Win7 penetrates the market (and we all know it will) I think Chameleon will run into more conflicts in multi-boot setups unless it allows Windows to own the active partition.  The biggest bully gets the best corner.

I've looked at the boot0 code and it looks like the feature was there but then it was commented out, not sure why.

I've attached what I think is needed to re-enable Chameleon booting from a non active partition, but I'm a 1 OS 1 Drive kind of guy, and I don't hve Win7 or use sleep, so I can't test it, maybe Blackosx can help there?
--- r0m30 ---
HP Mini 1033CL (Costco) OSX Retail 10.6 Chameleon-2.0-RC3-r658
HP m9077c -  ASUS IPIBL-LA MoBo with Core 2 Quad Q6600
    Retail 10.6.2 Chameleon-2.0-RC4-r684

Blackosx

  • Forum Moderator
  • Posts: 1150
maybe Blackosx can help there?
Hi r0m30

I can try and hep out here and I have played with dual booting before so I am happy to try things out, but I need you to let me know exactly how to do this.  Here's exactly what I have now so we can work out what the next step should be..

I have two HDD's each formatted with a GPT and each disk has Chameleon installed on to it's own separate partition.
Here's my diskutil list result, and Disk1 is my Snow Leopard install and I don't intend changing that one:

Code: [Select]
blackys-imac:~ blacky$ diskutil list
/dev/disk0
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        *465.8 Gi   disk0
   1:                        EFI                         200.0 Mi   disk0s1
   2:                  Apple_HFS Chameleon               896.0 Mi   disk0s2
   3:                  Apple_HFS Macintosh               120.0 Gi   disk0s3
   4:       Microsoft Basic Data                         64.0 Gi    disk0s4
   5:                  Apple_HFS Backup                  16.0 Gi    disk0s5
   6:                  Apple_HFS Vault                   264.3 Gi   disk0s6
/dev/disk1
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        *465.8 Gi   disk1
   1:                        EFI                         200.0 Mi   disk1s1
   2:                  Apple_HFS Cham                    1.0 Gi     disk1s2
   3:                  Apple_HFS SnowLeopard             120.0 Gi   disk1s3
   4:       Microsoft Basic Data WIN7                    80.0 Gi    disk1s4
   5:                  Apple_HFS BackupSL                16.0 Gi    disk1s5
   6:                  Apple_HFS Data                    248.1 Gi   disk1s6

For this trial I am using disk0 and I have just installed Windows7 on to disk0s4 and as things stand:
• If I select disk0 in BIOS, Windows 7 owns the system and takes over.
• If I select a bootable Chameleon USB stick from BIOS, I can boot the Macintosh partition on disk0s3.
• If I select disk1 in BIOS, Chameleon from disk1s2 loads and I can boot the Macintosh partition on disk0s3.

I have made the edit to boot0.s as shown in your diff file, recompiled Chameleon then written the new boot0 to disk0, and while at it also wrote boot1h back to disk0s2. This expectedly, results in the Windows Boot Manager complaining the drive is inaccessible, giving error STATUS: 0xc000000e. This I can easily repair with the Windows 7 CD and now Windows 7 is back to owning the system again.

I know I can use fdisk to set disk0s2 to the active partition and Chameleon will boot but I guess that's not the point of this trial. So my question is how do I trial the new boot0 file?
« Last Edit: January 30, 2010, 08:16:28 PM by Blackosx »
10.10.5 / 10.11 GM1 | Asus Maximum IV Gene-Z | i7-2600 3.40GHz | 4GB | Radeon 5770 1GB

r0m30

  • Forum Moderator
  • Posts: 98
    • r0m30's OSX86 site
I know I can use fdisk to set disk0s2 to the active partition and Chameleon will boot but I guess that's not the point of this trial. So my question is how do I trial the new boot0 file?

Yes, the object is to update the MBR boot code without changing the active partition from the win7 partition. I'm still a little vague about OSX device numbers, in linux disk0 (sata) would be sda and the partitions would be sda1 thru sda6.  If I understand OSX device numbering rdisk0 = sda and disk0s1...disk0s6 = sda1...sda6.  So, I think what you need to do is
Code: [Select]
sudo dd if=boot0 of=/dev/rdisk0 bs=440 count=1 Then boot from disk0 and see if Win7 will boot/sleep.
« Last Edit: January 31, 2010, 07:24:45 AM by r0m30 »
--- r0m30 ---
HP Mini 1033CL (Costco) OSX Retail 10.6 Chameleon-2.0-RC3-r658
HP m9077c -  ASUS IPIBL-LA MoBo with Core 2 Quad Q6600
    Retail 10.6.2 Chameleon-2.0-RC4-r684

Blackosx

  • Forum Moderator
  • Posts: 1150
So, I think what you need to do is
Code: [Select]
sudo dd if=boot0 of=/dev/rdisk0 bs=440 count=1 Then boot from disk0 and see if Win7 will boot/sleep.
Okay, I understand you now.. We are only going to write to the first 440 bytes of the MBR.

I wrote the modifed boot0 with this slightly amended command as using rdisk failed.
Code: [Select]
sudo dd if=boot0 of=/dev/disk0 bs=440 count=1 which completed successfully, and Windows7 still boots and sleeps fine though Windows7 is still the active partition and takes over. I have exactly the same results when using the unmodified boot0.

However, I did have some strange side effects earlier when having the modified boot0 installed:

• BIOS thinking my DVD drive was another HDD? selecting it from BIOS then showed me the 'Verifying DMI Pool Data....' message I get from my Gigabyte BIOS, then a flashing '_' symbol for about 30 seconds until finally reporting 'DISK BOOT FAILURE, INSERT SYSTEM DISK AND PRESS ENTER'. Pressing enter then proceeded to boot Windows7.
• Selecting to boot my Snow Leopard HDD (disk1) from BIOS also presented me with the 'Verifying DMI Pool Data....' message I get from my Gigabyte BIOS, then a flashing '_' symbol for about 30 seconds until finally reporting "EBIOS read error: Device timeout" then on then next line "Block 0x0 Sectors 0". This scan then looped every 30 seconds.
• Even selecting to boot from my bootable Chameleon USB stick from BIOS also entered the same loop as above.

This must be because the change to boot0 now instructs it to search for an HFS+ partition regardless of whether it's active or not, but it fails to ever find Chameleon. I will try more tests....
« Last Edit: January 31, 2010, 12:31:34 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
Okay I have it working :)

Windows is the active partition and the modified boot0 is installed in to the first 440bytes of the MBR. When I boot, Chameleon runs and I can select either Windows7 or OS X. Windows7 boots fine and also sleeps.

But I had to modify boot0 further. What I did was comment out .Pass1 and just leave .Pass2
I don't know if there are any negative effects of doing this, but it works.
« Last Edit: January 31, 2010, 05:26:44 PM by Blackosx »
10.10.5 / 10.11 GM1 | Asus Maximum IV Gene-Z | i7-2600 3.40GHz | 4GB | Radeon 5770 1GB

r0m30

  • Forum Moderator
  • Posts: 98
    • r0m30's OSX86 site
Okay I have it working :)
Great  8)
But I had to modify boot0 further. What I did was comment out .Pass1 and just leave .Pass2
I don't know if there are any negative effects of doing this, but it works.
I know better than to ever say "small change" and I don't know of any ill effects either but I hope one of the Devs does.
--- r0m30 ---
HP Mini 1033CL (Costco) OSX Retail 10.6 Chameleon-2.0-RC3-r658
HP m9077c -  ASUS IPIBL-LA MoBo with Core 2 Quad Q6600
    Retail 10.6.2 Chameleon-2.0-RC4-r684

Blackosx

  • Forum Moderator
  • Posts: 1150
I have spoken to Rekursor since this and after looking at the change he suggested we keep the code for the first pass but just swap the pass2 code with the pass1 code so it checks first for a boot record regardless of it being active or not.

Code: [Select]
.testPass:
    cmp     bh, 1
    jne     .Pass2

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

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

    DebugChar('*')
That works just fine :)

I have attached the revised DIFF and also the actual boot0 file that works for me when written to the first 440 bytes of the MBR.
« Last Edit: February 01, 2010, 08:56:43 AM by Blackosx »
10.10.5 / 10.11 GM1 | Asus Maximum IV Gene-Z | i7-2600 3.40GHz | 4GB | Radeon 5770 1GB

scrax

  • Member
  • Posts: 61
Hi to all,
i've added your boot0 to the RC5pre6 version posted by rek at insanely and modded the install script to use dd instead of fdisk. I cant test if it works 'cause i don't have any win installation only osx on my hack so
here you are.
Note that probably you can't select the active volume, DrHurt is working on this problem i think...
« Last Edit: February 01, 2010, 07:38:56 PM by scrax »

Blackosx

  • Forum Moderator
  • Posts: 1150
Hi to all,
i've added your boot0 to the RC5pre6 version posted by rek at insanely and modded the install script to use dd instead of fdisk. I cant test if it works 'cause i don't have any win installation only osx on my hack so
here you are.
Hi scrax

Thanks for the test installer, but it doesn't work.

When I install boot0 by hand I need to unmount the target HDD, but your installer just runs and says successful. And when I reboot after running your installer, Windows flashes up the error STATUS: 0xc000000e which indicates the MBR has been messed up. This is what happens when I write the unmodified boot0 file, but I see the new boot0 in your installer. So somethings not right..

Note that probably you can't select the active volume, DrHurt is working on this problem i think...
I look forward to see what Dr Hurt comes up with, but I would also like to try the installer that he made where it said it failed because of resource busy..

Thanks

EDIT: I would be happy to try out another version of your installer if you want to supply a revised version :)
« Last Edit: February 01, 2010, 09:50:18 PM by Blackosx »
10.10.5 / 10.11 GM1 | Asus Maximum IV Gene-Z | i7-2600 3.40GHz | 4GB | Radeon 5770 1GB

smith@@

  • Member
  • Posts: 49
Hi folks and hi rek.

I think I have solved the problem of "resource busy" of boot0. Trying to install from terminal this morning for the first time boot0 amended i stumbled in this error.
I realized after some evidence that the error is due to the mounted disk, trying to unmount the disk error disappears and the installation is successful.
Then I modified the script with the same commands used in the terminal, I've remove the preflight, I recreated the installer and the installation ends perfectly

Code: [Select]
diskutil unmountDisk "$disk" //Added

echo "DDing...."
dd if="${resourcesPath}/boot/boot0" of="$disk" bs=440 count=1 // change from fdisk command
dd if="${resourcesPath}/boot/boot1h" of="$rdev" bs=512 count=2

diskutil mountDisk "$disk" // Added

In attached the package installer with last rc5pre8 and new boot0, it works amazing for me on usb stick.  I need to test on the primary disk.   
What you think?
« Last Edit: February 04, 2010, 10:45:56 AM by smith@@@ »

Blackosx

  • Forum Moderator
  • Posts: 1150
Re: Removing the requirement for Chameleon (boot1h/boot) to be on active partit
« Reply #10 on: February 04, 2010, 10:21:24 AM »
Hi smith@@

This is great, I will have a try this evening when I get back to my hack. :)

I have also been playing with this myself and you're right we can't dd back to the MBR without unmounting the drive first, so I have thought about reading the MBR to file with dd, patching the first 440 bytes in the file, then writing a complete MBR back using fdisk which doesn't require us to unmount the disk.

However, I am no expert at shell scripts so any ideas are welcome..
So far it looks something like this.
Code: [Select]
#! backup the MBR:
echo "Backing up existing MBR....."
sudo dd if=/dev/disk0 of=mbrbackup bs=512 count=1

#! create file to work on:
echo "Creating working file....."
sudo dd if=/dev/disk0 of=mbrhybrid bs=512 count=1

#! write 440 bytes of boot0 in to working file:
echo "Injecting modified code in to working file....."
sudo dd if=boot0 of=mbrhybrid bs=440 count=1

#!write MBR back using fdisk:
echo "Rewriting MBR code....."
fdisk -f mbrhybrid -u -y /dev/rdisk0

echo "Done....."

But note the 'Injection part' needs working on as it needs to just replace the first 440bytes of the MBR leaving the remainder as it was,  where at the moment it writes the 440 bytes only then stops. Maybe there is a shell command to do this properly?

Note: It's only set to disk0 at the moment but with some added logic it can be automated further.

What do you think?
10.10.5 / 10.11 GM1 | Asus Maximum IV Gene-Z | i7-2600 3.40GHz | 4GB | Radeon 5770 1GB

smith@@

  • Member
  • Posts: 49
Re: Removing the requirement for Chameleon (boot1h/boot) to be on active partit
« Reply #11 on: February 04, 2010, 10:37:54 AM »
Hi black, also i like you i'm not expert of shell script, but your idea seems good, and i believe that it works. I think that the result is the same, maybe my way is more simple, maybe but works the same i think.
Fot set the $disk you can use this part of code:

Code: [Select]
targetVolume="$3"                            #  this $3 is the target volume name passed from the installer
....
OF=`mount | grep " on $3 " | awk -F " " '{print $1}'`
....
devprefix=`echo ${OF:0:5}`
devpostfix=`echo ${OF:5}`
diskpostfix=${devpostfix%s*}
dev=`echo $devprefix$devpostfix`
rdev=`echo $devprefix"r"$devpostfix`
disk=`echo $devprefix$diskpostfix`

Hi ;)
« Last Edit: February 04, 2010, 11:05:03 AM by smith@@@ »

Blackosx

  • Forum Moderator
  • Posts: 1150
Re: Removing the requirement for Chameleon (boot1h/boot) to be on active partit
« Reply #12 on: February 04, 2010, 11:00:39 AM »
Hi black, also i like you i'm not expert of shell script, but you idea seems good, and i believe that it works. I think that the result is the same, maybe my way is more simple, maybe but works the same i think.
Thanks for the feedback smith@@

I think either method could work, depending on whether of not you want to unmount the drive.

It can be part of a complete installation package for Chameleon where boot0 is only injected to the first 440 bytes of the MBR. So if there is already a Windows install present, it will leave the existing Windows code intact.

If the user add's Windows7 to a separate partition at a later date, after OS X is already installed. Then just the boot0 needs to be modified. This could be done with an installer, or maybe have the shell script in Rekursor's Pref pane which can be run at the click of a button?
« Last Edit: February 04, 2010, 11:08:51 AM by Blackosx »
10.10.5 / 10.11 GM1 | Asus Maximum IV Gene-Z | i7-2600 3.40GHz | 4GB | Radeon 5770 1GB

smith@@

  • Member
  • Posts: 49
Re: Removing the requirement for Chameleon (boot1h/boot) to be on active partit
« Reply #13 on: February 04, 2010, 02:18:23 PM »
Thanks for the feedback smith@@

I think either method could work, depending on whether of not you want to unmount the drive.
I can not be more agree ;)  I've do other test and always the boot0 is written correctly, also if from log can read sometimes "failed mounted disk", the boot0 is written perfectly. I have the sensation that the disk in some way be seen like unmounted ;)

It can be part of a complete installation package for Chameleon where boot0 is only injected to the first 440 bytes of the MBR. So if there is already a Windows install present, it will leave the existing Windows code intact.
Sure, you are right ;)

If the user add's Windows7 to a separate partition at a later date, after OS X is already installed. Then just the boot0 needs to be modified.
Like up;)

This could be done with an installer, or maybe have the shell script in Rekursor's Pref pane which can be run at the click of a button?

With a script in Rek panel would be amazing ;)

Blackosx

  • Forum Moderator
  • Posts: 1150
Re: Removing the requirement for Chameleon (boot1h/boot) to be on active partit
« Reply #14 on: February 04, 2010, 04:25:05 PM »
But note the 'Injection part' needs working on as it needs to just replace the first 440bytes of the MBR leaving the remainder as it was,  where at the moment it writes the 440 bytes only then stops. Maybe there is a shell command to do this properly?
Just looking in to this a bit further I have found the command I need to only replace the 440 bytes of the MBR file read to disk, and leave the remainder as it was. It's with the conv=notrunc operand added to the dd command. So the command now reads..
Code: [Select]
#! write 440 bytes of boot0 in to working file:
echo "Injecting modified code in to working file....."
sudo dd if=boot0 of=mbrhybrid bs=440 conv=notrunc count=1
This now works :)

I just need to find time back on my hack to put the code together and test it, then hopefully I'll be a step nearer having a runtime script.
« Last Edit: February 04, 2010, 04:26:54 PM by Blackosx »
10.10.5 / 10.11 GM1 | Asus Maximum IV Gene-Z | i7-2600 3.40GHz | 4GB | Radeon 5770 1GB