0

I cannot make my VHD bootable.

I'm following this guild word for word, trying to create a Bootable VHD.

The BCDboot is supposed to create boot configuration entry so that windows bootloader can boot from the VHD, and I've seen it went successful, however, it just doesn't work:

D:>P:\windows\system32\bcdboot P:\windows /s P:
Boot files successfully created.

D:>BCDEdit

Windows Boot Manager
--------------------
identifier              {bootmgr}
device                  partition=\Device\HarddiskVolume1
path                    \EFI\MICROSOFT\BOOT\BOOTMGFW.EFI
description             Windows Boot Manager
locale                  en-US
inherit                 {globalsettings}
default                 {current}
resumeobject            {c605aeaf-...8}
displayorder            {current}
toolsdisplayorder       {memdiag}
timeout                 30

Windows Boot Loader
-------------------
identifier              {current}
device                  partition=C:
path                    \Windows\system32\winload.efi
description             Windows 10
locale                  en-US
inherit                 {bootloadersettings}
recoverysequence        {c605aeb1-...8}
displaymessageoverride  Recovery
recoveryenabled         Yes
isolatedcontext         Yes
allowedinmemorysettings 0x15000075
osdevice                partition=C:
systemroot              \Windows
resumeobject            {c605aeaf-...8}
nx                      OptIn
bootmenupolicy          Standard
hypervisorlaunchtype    Auto

I.e., the device partition=P: entry is not there. When I tried to boot it from Hyper-V, Hyper-V tells me that there is no boot-loader.

What could possibly wrong and how can I fix it? (again, I'm followed this guild word for word successfully until I came to the bcdboot & BCDEdit step. I.e., all my steps are exactly as shown there.)

UPDATE:

I'm not sure if I'm using UEFI though, because these are all it takes for me to create my disk:

select vdisk file=e:\vhd\winboot.vhd
attach vdisk
create partition primary
assign letter=v
active
format quick FS=NTFS Label=VHD

Most importanly, when select the Generation type for hyper-v, I chose Generation 1, which I think don't support UEFI.

xpt
  • 8,261
  • 38
  • 102
  • 156
  • I now think there should also be one very important step missing from the tutorial -- it only creates a primary partition but didn't initialize the MBR to make it boot the active partition, apart from bcdboot not working as expected. – xpt Jun 18 '20 at 05:22
  • If that's the `BCD` store for the VHD, it's UEFI, whereas the `DiskPart` commands you issued are for BIOS _(`bcdedit` shows the BCD store for the booted OS if `BCD` store isn't specified)_. @wasif-hasan's answer is the semi-correct way to configure the VHD - I'd recommend modifying it slightly to create the WinRE partition in front of the EFI _(order: **1:** 665MB WinRE; **2:** 100MB EFI; **3:** 16MB MSR; **4:** OS partition)_, such as in [this](https://github.com/JW0914/Wikis/blob/master/Scripts%2BConfigs/WinRE/CreatePartitions.txt) `DiskPart` script _(`diskpart /s CreatePartitions.txt`)_. – JW0914 Jun 18 '20 at 11:06
  • _Cont'd..._ Gen1 is BIOS-based, with the tutorial leaving out the step for creating the boot partition, not to mention WinRE _(I'm creating an answer to fix, as it's not simple enough to contain within a comment)_ – JW0914 Jun 18 '20 at 12:18

2 Answers2

1

If you are using UEFI, you need to convert the attached VHD's partition table to GPT:

  1. Access WinPE Open Command Prompt
  2. Prepare the UEFI disk by creating three partitions via diskpart:
    diskpart
     select disk 0
     clean
     convert gpt
    
     rem == 1. System partition =========================
     create partition efi size=100
     format quick fs=fat32 label="System"
     assign letter="S"
    
     rem == 2. Microsoft Reserved (MSR) partition =======
     create partition msr size=128
    
     rem == 3. Main partition ===========================
     create partition primary
     format quick fs=ntfs label="Main"
     assign letter="M"
    
     exit
    
  3. Add the entry in the boot menu with /f UEFI
JW0914
  • 7,052
  • 7
  • 27
  • 48
Wasif
  • 7,984
  • 2
  • 19
  • 32
  • Thanks Wasif, but I'm not sure if I'm using UEFI though. See my updated OP. I'm sure your answer would help for the UEFI cases, but I just don't want to complicate things as it is already not working. thx again. – xpt Jun 18 '20 at 05:18
  • The example `DiskPart` script from Microsoft Docs isn't recommended for users, as it results in a non-optimal configuration since WinRE should be the first partition on the disk _(it's intended as an example script for OEMs, which usually place WinRE as the last partition - also not recommended)_; EFI partition shouldn't be named `System`, as that's the naming scheme for the OS partition most use _(`EFI` or `Boot` would be best)_, and the partition doesn't need to be mounted (`assign letter=S`) since it's not going to be manually configured; last partition should be `System` and not mounted. – JW0914 Jun 18 '20 at 10:33
  • Thanks @JW0914 for nice thoughts. I have made a look at the UEFI partitions in my hard disk and ssd. There is partition labelled "System" then why it is not recommended. – Wasif Jun 18 '20 at 14:23
  • You're correlating two different things, partition types and partition label names: majority of Windows users have `C:` _(the OS' system partition)_ labeled with the _name_ `System`, whereas what I believe you're asking about is the partition _type_ of the ESP/EFI partition, which is listed as `Type: system` in `DiskPart`. While Microsoft has decided on their own label names in Microsoft Docs, the reality is this is not the naming scheme followed by OEMs or the vast majority of Windows users, as the OS partition [`C:`] has been [label] named `System` for >15yrs and has never been named `Main` – JW0914 Jun 18 '20 at 14:38
  • _Cont'd..._ None of my comments are intended as criticism, as the fault lies with Microsoft failing to present logical naming in Microsoft Docs that's been used since at least the early 2000s. The Microsoft Docs article linked to, and most Microsoft Docs regarding configuring Windows for installation, is for OEMs and is why it's under Desktop Manufacturing; when such information is disseminated in an answer, I personally prefer to modify it to match the normal schemes all are familiar with, else it risks creating confusion, especially for users who are new to Windows or non-technical users – JW0914 Jun 18 '20 at 15:02
1

The tutorial followed left out the step for creating the boot partition, as well as WinRE:

  1. Create correct partition structure via DiskPart:
    1. It's simpler to clear the VHD's partition table and re-partition (VHD: disk 0):
      # Select disk and clear the partition table:
        Sel Dis 0
        Clean
      
      # Create WinRE partition:
        Cre Par Pri Offset=1024 Size=665 Id=27
        Format Quick Fs=ntfs Label=WinRE
      
      # Create Boot partition:
        Cre Par Pri Size=100
        Format Quick Fs=ntfs Label=Boot
        Active
      
      # Create System partition:
        Cre Par Pri
        Format Quick Fs=ntfs Label=System
      
      # Verify:
        Lis Par
        Lis Vol
      
        Exit
      
    2. If preserving existing data on the VHD's [OS] System partition:
      # Select disk and [OS] System partition:
        Sel Dis 0
        Sel Par 1
      
      # Shrink System partition by 765MB [RAW]:
        Shrink Desired=765 Minimum=750
          # WinRE: 665MB, min 650MB
            # WinRE partition must have 320MB free (WinRE.wim is ~300MB in size)
          # Boot: 100MB
      
      # Create WinRE partition:
        Cre Par Pri Offset=1024 Size=665 Id=27
          # If it fails, remove Offset=1024
        Format Quick Fs=ntfs Label=WinRE
      
      # Create Boot partition:
        Cre Par Pri Size=100
        Format Quick Fs=ntfs Label=Boot
        Active
      
      # Verify:
        Lis Par
        Lis Vol
      

  2. Configure boot partition:
    1. While booted to Windows in the VHD's VM:
      BCDboot C:\Windows /v
      
    2. From WinPE/WinRE:
      1. Boot the VHD's VM to WinPE via a Windows install ISO
      2. Open terminal via SHIFT+F10:
        BootRec /FixMBR && BootRec /FixBoot && BootRec /RebuildBCD
        
        /RebuildBCD may or may not find an OS, either is okay
      3. Reboot the VM

  3. Configure WinRE partition via this answer:
    • #2: If VHD doesn't have WinRE at C:\Recovery or %WinDir%\System32\Recovery\, copy the host's WinRE.wim to the VHD's %WinDir%\System32\Recovery\
    • #3: Skip (WinRE partition creation)
JW0914
  • 7,052
  • 7
  • 27
  • 48
  • _"Configure the WinRE partition via this answer:"_, I took a look at it and found it very long. Have all the relevant info been presented here, or there are still bits and pieces left out over there? – xpt Jun 18 '20 at 13:31
  • @xpt All steps on the linked answer, except #3, would need to be performed to configure WinRE on its own partition. Come on now... It's a total of 7 commands, 9 steps, and 9 sentences, taking ~5min to accomplish - perhaps we have a different perception of what "_long_" is, especially when I make it a point to make steps one-liners in the answers I write, unless more than one line is absolutely necessary. – JW0914 Jun 18 '20 at 13:43
  • OK, I've done step 1 and step 3 (Configure WinRE partition). However, for step 2, are the two scenarios the only options? I.e., I can't boot to Windows in the VHD's VM because I need to make it bootable in the first place. As to "Boot the VHD's VM to WinPE", I believe I need to make that bootable first too. Is there any other way that I can break the catch-22? Thx. – xpt Jun 18 '20 at 23:27
  • @xpt For #2, use #2.2 - [download](https://www.microsoft.com/en-us/software-download/windows10) a Windows install ISO if you don't have one, then set the VM to boot to the ISO: Set IDE Controller 1 (or add SCSI controller) to Image File [Windows install ISO] > Set BIOS to CD, then boot the VM – JW0914 Jun 19 '20 at 11:33