Jump to content











Photo
- - - - -

Boot sequence when booting to a W7 VHD from bootmgr on HDD


  • Please log in to reply
15 replies to this topic

#1 gbrao

gbrao

    Frequent Member

  • Advanced user
  • 373 posts
  •  
    India

Posted 06 March 2012 - 04:18 AM

I can boot to a VHD that has W7 U installed. I normally do this by booting to W7 installed to drive C: on a hard disk and then select the right entry from the boot menu presented by boot mgr ( EasyBCD has been used to create the boot entry for boot to VHD ).

What I want to know is where does the bootmgr+bcd on the hard disk transfer control to when I choose "boot to vhd" from the boot menu. Since the VHD is a "hard disk" it has a MBR, one or more PBRs, and may have one or more bootmgr or ntldr on the various partitions in the VHD, and a partition could have a winload too.

What I'm looking for is for control to be transfered to one (say the active partition on the VHD) PBR. Or to the MBR of the VHD since it should boot the active partition (right ?).

#2 karyonix

karyonix

    Frequent Member

  • Advanced user
  • 472 posts
  •  
    Thailand

Posted 06 March 2012 - 06:19 AM

bootmgr and BCD are in active partition outside of VHD. There is no need for bootmgr and BCD in VHD.
BCD entry tells bootmgr to load Windowssystem32winload.exe from a partition inside VHD and transfer control to winload.exe.
MBR code and PBR code inside VHD are not used.

#3 sambul61

sambul61

    Gold Member

  • Advanced user
  • 1568 posts
  •  
    American Samoa

Posted 06 March 2012 - 06:36 AM

gbrao

I see you left wimb alone for now and moved to the next target. :smiling9: You can also boot a native boot VHD from a drive without Windows installed on it. In both cases Win7 BCD boot record (store) for the VHD contains active partition offset and winload.exe path, and once the VHD is mounted (presumably by Bootmgr in real mode), Bootmgr transfers control to winload.exe on that VHD partition, and from their to kernel and protected mode drivers.

Why your style reminds me someone else though? What do you actually want to accomplish? :dubbio:

Would be interesting to find out, how exactly Bootmgr mounts the VHD and what code is used instead of Windows native Virtual Disk Driver and at what stage of the process. The VHD should be mounted, since winload.exe address in BCD is given as a file path, not as offset.

Once you are all set, try solving this challenge.

#4 gbrao

gbrao

    Frequent Member

  • Advanced user
  • 373 posts
  •  
    India

Posted 06 March 2012 - 12:13 PM

gbrao
I see you left wimb alone for now and moved to the next target. :smiling9:

just giving him a break ;-) . and Olof Lagerkvist too ;-) ;-) .

In both cases Win7 BCD boot record for the VHD contains active partition offset and winload.exe address, and once the VHD is mounted by a Virtual Disk Driver, Bootmgr transfers control to winload.exe on that VHD partition.

i more or less understood that. now. so if a vhd has multiple partitions, all but the first cannot be booted to ?

Why your style reminds me someone else though?


that i did not understand.

What do you actually want to accomplish?

i created a w7 vhd using wimbs tools. i moved it to another partition, used easybcd to make a new boor menu entry, when i booted the vhd i got a message saying windows not activated. even though it said activated before. that's when i realised even though i had used vhd boot before i never really understood the 'mechanics' involved.

thanks everyone, i'll try to hold back the Qs for a while.

#5 wimb

wimb

    Platinum Member

  • Developer
  • 2629 posts
  • Interests:Boot and Install from USB
  •  
    Netherlands

Posted 06 March 2012 - 12:30 PM

You can use USB_W7_Fix.exe or BOOT_USB.exe to create the new boot entry for the Win7 VHD

:cheers:

#6 sambul61

sambul61

    Gold Member

  • Advanced user
  • 1568 posts
  •  
    American Samoa

Posted 06 March 2012 - 03:47 PM

that's when i realised even though i had used vhd boot before i never really understood the 'mechanics' involved.

MS didn't disclose details about BCD, Bootmgr and Virtual Disk Driver interaction during native OS boot from VHD. Presumable EasyBCD should write offset of an active partition to BCD, but this tool is more suited for beginners, and may not handle well multi-partition VHDs, as well as some other complex tasks despite having them in GUI due to diversity of OSs and approaches to boot various images. So you can use Visual BCD Editor or native BCD tools to edit Win BCD. The bootable partition still needs to be marked active.

As to copying a VHD to a different HD volume, you didn't give enough details. If that volume is on a different HD placed into another PC, it may result in sufficient hardware differences to trigger re-activation prompt. One may still reactivate Win7 Ultimate without much problems, but some WES7 versions is harder to re-activate.

#7 sambul61

sambul61

    Gold Member

  • Advanced user
  • 1568 posts
  •  
    American Samoa

Posted 08 March 2012 - 08:57 PM

What I want to know is where does the bootmgr+bcd on the hard disk transfer control to when I choose "boot to vhd" from the boot menu.

The Windows NT 6 boot process and details of relevant BCD Store content and work are described in more particulars in that article. Of course, it doesn't address VHD boot, since their native boot was introduced in Win7, and wasn't supported in Vista. But the difference appears to be mostly in that Bootmgr now able to mount in real mode the VHD selected by a user from Windows Boot Menu (thus acting similar to G4D), and then transfer control to Winload.exe on its active partition, followed by loading NT kernel and protected mode Windows Virtual Disk Driver from that partition, which hot swaps the VHD mounted by the Bootmgr, thus allowing the boot process to proceed further.

Some more details are found in this thread When does Windows/bootmgr stop using BIOS INTterrupts, where the guy RulerOf inspired by karyonix and Sha0 wanted to make his own driver facing similar complexities and knowledge gaps hidden behind the familiar driver names. :)

#8 joakim

joakim

    Silver Member

  • Team Reboot
  • 912 posts
  • Location:Bergen
  •  
    Norway

Posted 08 March 2012 - 09:49 PM

i more or less understood that. now. so if a vhd has multiple partitions, all but the first cannot be booted to ?

I suppose you could do something similar to what I did with the wimpatched (bootmgr) I did some time ago. That involved patching the bootmgr to behave differently and boot any index number (image) in a wim. If this patch is as "easy" as the wim one, I don't know. So the answer is like karyonix said, the sequence is hardcoded in bootmgr.

#9 sambul61

sambul61

    Gold Member

  • Advanced user
  • 1568 posts
  •  
    American Samoa

Posted 09 March 2012 - 03:51 AM

It would be too complex solution for a seemingly simple task. :) Bcdboot command syntax allows to select a partition on a native boot VHD to boot from, assuming all its volumes are mounted with drive letters:

bcdboot v:windows /s c:

Then using Bcdedit command, one can add Boot Entries for each bootable volume on the same VHD to the common BCD Store and Windows Boot Menu - just follow Create Native Boot VHDs Tutorial linked below. The volume one wants to boot from next time must be marked Active for boot to succeed - one can do it from WinPE or running Diskpart before reboot, or possibly by other means. Any BCD Store Record can be edited later via Visual BCD Editor, or by running bcdboot & bcdedit commands again. Would be interesting to find out, if its possible to make a VHD volume active during boot process, but its hard to envision scenarios that mandate such requirement.

#10 joakim

joakim

    Silver Member

  • Team Reboot
  • 912 posts
  • Location:Bergen
  •  
    Norway

Posted 09 March 2012 - 07:13 AM

OK, I did not know.

#11 renee

renee

    Member

  • Members
  • 46 posts
  •  
    United States

Posted 28 March 2012 - 02:31 AM

Joakim,

I need your help very badly. Some mft code, written by StCroixskipper. Please help........

Renee

Edited by renee, 28 March 2012 - 02:31 AM.


#12 joakim

joakim

    Silver Member

  • Team Reboot
  • 912 posts
  • Location:Bergen
  •  
    Norway

Posted 28 March 2012 - 05:22 PM

Joakim,

I need your help very badly. Some mft code, written by StCroixskipper. Please help........

Renee

If I can be of any help, I'll answer what I can. Do you have a more specific question regarding any particular issue you're facing right now? What exactly are you creating?

Perhaps you would like to start a new thread.

#13 renee

renee

    Member

  • Members
  • 46 posts
  •  
    United States

Posted 28 March 2012 - 05:37 PM

I think I have it. This is in VB. StCroix Skipper did it in C#. I've converted it.

It will list files...but get's an Access Violation when it goes to list the directory. Identical code works on 32 bit xp and does not work on Win7. Once again it has a file listing but does not have a directory with it as it gets a protection violation. It must be run with aministrators privilege.

Do you care to take a look at it?

Renee

Edited by renee, 28 March 2012 - 05:45 PM.


#14 renee

renee

    Member

  • Members
  • 46 posts
  •  
    United States

Posted 28 March 2012 - 05:53 PM

This is the routine that get's the containing directory.

Private Function PathFromFrn(ByVal Id As Long) As String
Dim fOk As Integer
Dim FileName As String = String.Empty
Dim UnicodeString As UNICODE_STRING
Dim ObjAttributes As OBJECT_ATTRIBUTES
Dim IoStatusBlock As IO_STATUS_BLOCK
Dim hFile As IntPtr ' out handle
Dim Buffer As IntPtr = Marshal.AllocHGlobal(4096) ' Raw buffer
Dim Refptr As IntPtr = Marshal.AllocHGlobal(8) ' 8 byte FileID - allocate 8 bytes of unmanaged memory
Dim ObjAtt As IntPtr = Marshal.AllocHGlobal(Marshal.SizeOf(ObjAttributes)) 'pointer to the unicode string struct
Static i As UInt32 : i += 1 ' If i = 100 Then Debugger.Break()
' pointer>>fileid
Marshal.WriteInt64(Refptr, 0, Id)
' 8 byte file id
UnicodeString.Length = 8
UnicodeString.MaximumLength = 8
UnicodeString.Buffer = Refptr
' copy unicode structure to pointer
Marshal.StructureToPtr(UnicodeString, ObjAtt, True)
' InitializeObjectAttributes Macro
ObjAttributes.Length = Marshal.SizeOf(ObjAttributes)
ObjAttributes.ObjectName = ObjAtt ' Or OBJ_KERNEL_HANDLE
ObjAttributes.RootDirectory = m_hCJ
ObjAttributes.Attributes = OBJ_CASE_INSENSITIVE
fOk = NtCreateFile(hFile, 0, ObjAttributes, IoStatusBlock, 0, 0, _ '<---- This routine get's an Access vilation here and fails to get a directory listing on 64 bit Win7, C0000022(?) here. It works normally on 32 bit XP.
FILE_SHARE_READ Or FILE_SHARE_WRITE, _
FILE_OPEN, FILE_OPEN_BY_FILE_ID Or FILE_OPEN_FOR_BACKUP_INTENT, 0, 0)
' If Not fOk Then Debugger.Break()
If fOk <> INVALID_HANDLE_VALUE Then
fOk = NtQueryInformationFile(hFile, IoStatusBlock, Buffer, 4096, FileNameInformationClass)
If fOk = 0 Then
' The first 4 bytes is the length
Dim FileLength As Integer = Marshal.ReadInt32(Buffer, 0)
' The filename is just after the first 4 bytes.
FileName = Marshal.PtrToStringUni(New IntPtr(Buffer.ToInt32() + 4), FileLength / 2)
End If
End If
' free allocated memory and handles
CloseHandle(hFile)
Marshal.FreeHGlobal(Buffer)
Marshal.FreeHGlobal(ObjAtt)
Marshal.FreeHGlobal(Refptr)
 
Return FileName
End Function

Actually I think this has something to do with it lackin OBJ_KERNEL_HANDLE BUT I dont know how to add it to the attributes.

Renee

Edited by renee, 28 March 2012 - 06:15 PM.


#15 joakim

joakim

    Silver Member

  • Team Reboot
  • 912 posts
  • Location:Bergen
  •  
    Norway

Posted 28 March 2012 - 07:25 PM

Sorry, I'm no c# guru. But at msdn ther are some specific hints about that particular FileInformationClass you are using; http://msdn.microsof...2(v=vs.85).aspx Where does this code fit into any $MFT code btw?

#16 renee

renee

    Member

  • Members
  • 46 posts
  •  
    United States

Posted 28 March 2012 - 07:46 PM

The code finds the directory that continas the file bein described. This code provides those user with a directory spec to be a part of the complete filespec.This process simply lists files in the $MFT.

Renee




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users