On 17 February 2010 10:31, Willie Wong <ww...@math.princeton.edu> wrote:
> On Wed, Feb 17, 2010 at 06:58:16AM +0000, Mick wrote:
>> On Wednesday 17 February 2010 01:12:08 Peter Humphrey wrote:
>> > On Monday 15 February 2010 23:45:23 Mick wrote:
>> > > If I were to [tell] GRUB to chainload W7 [which} should I point it
>> > > to? Dell's partition 2 which has the boot flag, or the main W7 OS
>> > > partition 3?
>> >
>> > The one with W7 on it, I should have thought, as that's the one you want
>> > to start. Why not just try it? And when you find out which partition is
>> > which, why not set the bootable flag on the right one? I.e. the one with
>> > grub in it.
>>
>> I am not sure that I would want to do this.  I recall that MSWindows used to
>> be and it possible still is rather sensitive with needing the boot flag on 
>> its
>> partition.  Linux on the other hand is a more advanced OS which does not care
>> where the boot flag is.
>
> If you were to go with the GRUB -> W7 route, I don't think just trying
> out the two configurations (don't change boot flags, just try each
> partition) would've hurt. The worst that I can imagine is an error
> thrown about OS not found.
>
>> Nope.  I mean use the Windows 7 bootloader as the primary bootloader to
>> chainload GRUB from the Gentoo partition.  The MSWindows stays in the MBR as
>> it is now, the GRUB is installed in the Gentoo /boot partition.  MSWindows
>> bootloader chainloads GRUB.
>>
> I wish you good luck with your project.
>
>> PPS.  I am making some progress with this (at least in terms of googling) and
>> will report back as soon as I have achieved this MSWindows --> chainloading 
>> --
>> > Gentoo thing.
>
> Please do write a page on the Wiki (or at least a summary of what you
> did to this mailing list). This will be some handy information to
> have.

I have now succeeded at achieving what I wanted:  to use the Windows 7
boot manager (bootmgr.exe) which is the successor to NTLDR to
chainload GRUB from it and so leave the Windows installation intact
(at least until the warranty expires) ;-)

I very briefly detail here the steps that I followed - if you need
more please contact me and I will help if I can, or if I get some time
I will sign up to edit a Wiki page.

First the necessary WARNING:  You can render your MSWindows OS
unbootable and without an installation CD things can get hairy.  So
research the necessary steps to recover a borked MSWindows boot system
using the facilities offered by the OEM *before* you start and use
partimage to make a back up, just in case.

There's two or three gotchas that make this more difficult than
chainloading GRUB from NTLDR.exe under Win2k and WinXP:

1.  Disk and partition signatures in the MBR are used by Vista and
Windows 7 to find the active boot partition of MSWindows.  If you move
that partition then its disk offset changes and you start getting
errors like "winload.exe..... is missing or corrupt", when what has
actually happened is that the drive ID (partition signature) has
changed and BCD doesn't know about it.

2.  OEMs use additional partitions to save installation images for
recovery purposes and they often mark these as active boot partitions.
 The boomgr and BCD is consequently installed there as part of the
installation script - but it doesn't clearly tell you this in the BCD
file (that's the new boot.ini) unless you can decipher partition ID
signatures.  Remove that recovery partition to save space and your
MSWindows won't boot again.

3.  Windows 7 uses BitLocker on the IPL in the MBR and this may
introduce additional complications - you mess with the MBR and then
kiss goodbye to booting your MSWindows bloatware again.

My solution worked by editing the BCD file using the native editor
provided by MSWindows, the bcdedit command.  The winload.exe (which
partly replaces NTLDR) is thereafter used normally to launch an image
of the GRUB partition boot record and that of course knows where to
jump to launch your Gentoo.  There's no need for 3rd party boot
managers - there are two or three available like Neogrub which should
do the same job by offering you a GUI, but if you are capable enough
to install Gentoo then you can easily find your way around the BCD
file with bcdedit.exe.

The main steps to achieve this solution are:

1.  Install GRUB in your Linux /boot partition and capture an image of
the partition boot record (it must be unmouted at the time):

dd if=/dev/sda5 of=boot.lnx bs=512 count=1

2.  Copy the boot.lnx file to C:\boot.lnx

3.  Launch cmd.exe as administrator and call bcdedit /v which will
show you something like this:
====================================================
C:\Windows\system32>bcdedit /v

Windows Boot Manager
--------------------
identifier              {9dea862c-5cdd-4e70-acc1-f32b344d4795}
device                  partition=\Device\HarddiskVolume2
path                    \bootmgr
description             Windows Boot Manager
locale                  en-US
inherit                 {7ea2e1ac-2e61-4728-aaa3-896d9d0a9f0e}
default                 {fda5ebf3-119b-11df-969c-f924691e8117}
resumeobject            {5744906c-0bf4-11df-8e08-0026b920b49c}
displayorder            {fda5ebf3-119b-11df-969c-f924691e8117}
                        {fda5ebf6-119b-11df-969c-f924691e8117}
toolsdisplayorder       {b2721d73-1db4-4c62-bf78-c548a880142d}
timeout                 3

Windows Boot Loader
-------------------
identifier              {fda5ebf3-119b-11df-969c-f924691e8117}
device                  partition=C:
path                    \Windows\system32\winload.exe
description             Windows 7 Home Premium
locale                  en-US
recoverysequence        {5744906e-0bf4-11df-8e08-0026b920b49c}
recoveryenabled         Yes
osdevice                partition=C:
systemroot              \Windows
resumeobject            {5b312091-116a-11df-8b54-806e6f6e6963}
====================================================

The first entry is the bootmgr, the second is MSWindows OS partition.
First make a back up of the BCD file:

C:\Windows\system32>bcdedit /export C:\BCD_backup

Then create a new entry using bcdedit for the Linux boot image, by entering:
====================================================
bcdedit /create /d "Gentoo Linux2" /application BOOTSECTOR
The entry {fda5ebf7-119b-11df-969c-f924691e8117} was successfully created.
====================================================

Cut and paste the partition ID in all the subsequent commands:
====================================================
bcdedit /set {fda5ebf7-119b-11df-969c-f924691e8117} device boot

bcdedit /set {fda5ebf7-119b-11df-969c-f924691e8117} path /boot.lnx

bcdedit /set {fda5ebf7-119b-11df-969c-f924691e8117} locale en-US
====================================================
If you don't get "The operation completed successfully." you know
you've done something wrong.

Then set it as last in the menu:
====================================================
bcdedit /displayorder {fda5ebf7-119b-11df-969c-f924691e8117} /addlast
The operation completed successfully.
====================================================

and increase the delay before the menu automatically boots the default
(leave the default as MSWindows until you prove that your Linux system
can boot):
====================================================
 bcdedit /timeout 10
====================================================

Then run C:\Windows\system32>bcdedit /v to see what you have just
made, at the bottom of the menu:
====================================================
Real-mode Boot Sector
---------------------
identifier              {fda5ebf6-119b-11df-969c-f924691e8117}
device                  boot
path                    \boot.lnx
description             Gentoo Linux
locale                  en-US
====================================================

Now, this may not boot if your MSWindows boot drive is different to
the MSWindows OS partition (as was in my case).  So, we need to point
the bootmgr at the partition where the linux boot image resides, in my
case C:
====================================================
bcdedit /set {fda5ebf7-119b-11df-969c-f924691e8117} device partition=C:
====================================================

Use the /v option to check all is good and reboot the machine.
Hopefully, you will be greeted with a GRUB splash.  :-)

HTH.
-- 
Regards,
Mick

Reply via email to