I just set the constants and never have had issues making any partition-style bootable. Code: { [CmdletBinding()] param ( [Parameter(Mandatory = $true)][string][ValidateNotNullOrEmpty()]$BcdStoreFile, [Parameter()][string][ValidateNotNullOrEmpty()][ValidateScript({ ($_ -eq $PARTITION_STYLE_MBR) -or ($_ -eq $PARTITION_STYLE_GPT) })]$PartitionStyle = $PARTITION_STYLE_MBR, [Parameter()][UInt64][ValidateScript({ $_ -ge 0 })]$DiskSignature, [Parameter()][UInt64][ValidateScript({ $_ -ge 0 })]$PartitionOffset ) ######### Set Constants ######### $BOOTMGR_ID = "{9DEA862C-5CDD-4E70-ACC1-F32B344D4795}" $DEFAULT_TYPE = 0x23000003 $APPLICATION_DEVICE_TYPE = 0x11000001 $OS_DEVICE_TYPE = 0x21000001 ################################## Write-Verbose "Opening $($BcdStoreFile) for configuration..." Write-Output "Partition Style : $PartitionStyle" Write-Output "Disk Signature : $DiskSignature" Write-Output "Partition Offset: $PartitionOffset" $conn = New-Object Management.ConnectionOptions $scope = New-Object Management.ManagementScope -ArgumentList "\\.\ROOT\WMI", $conn $scope.Connect() $path = New-Object Management.ManagementPath ` -ArgumentList "\\.\ROOT\WMI:BCDObject.Id=`"$($BOOTMGR_ID)`",StoreFilePath=`"$($BcdStoreFile.Replace('\', '\\'))`"" $options = New-Object Management.ObjectGetOptions $bootMgr = New-Object Management.ManagementObject -ArgumentList $scope, $path, $options try { $bootMgr.Get() } catch { throw "Could not get the BootMgr object from the Virtual Disks BCDStore." } Write-Output "Setting Qualified Partition Device Element for Virtual Disk boot..." $ret = $bootMgr.SetQualifiedPartitionDeviceElement($APPLICATION_DEVICE_TYPE, $PartitionStyle, $DiskSignature, $PartitionOffset) if (!$ret.ReturnValue) { throw "Unable to set Qualified Partition Device Element in Virtual Disks BCDStore." } Write-Output "Getting the default boot entry..." $defaultBootEntryId = ($bootMgr.GetElement($DEFAULT_TYPE)).Element.Id Write-Output "Getting the OS Loader..." $Path = New-Object Management.ManagementPath ` -ArgumentList "\\.\ROOT\WMI:BCDObject.Id=`"$($defaultBootEntryId)`",StoreFilePath=`"$($BcdStoreFile.Replace('\', '\\'))`"" $OsLoader = New-Object Management.ManagementObject -ArgumentList $scope, $path, $options try { $OsLoader.Get() } catch { throw "Could not get the OS Loader..." } Write-Output "Setting Qualified Partition Device Element in the OS Loader Application..." $ret = $osLoader.SetQualifiedPartitionDeviceElement($APPLICATION_DEVICE_TYPE, $PartitionStyle, $DiskSignature, $PartitionOffset) if (!$ret.ReturnValue) { throw "Could not set Qualified Partition Device Element in the OS Loader Application." } Write-Output "Setting Qualified Partition Device Element in the OS Loader Device..." $ret = $osLoader.SetQualifiedPartitionDeviceElement($OS_DEVICE_TYPE, $PartitionStyle, $DiskSignature, $PartitionOffset) if (!$ret.ReturnValue) { throw "Could not set Qualified Partition Device Element in the OS Loader Device." } Write-Verbose "BCD configuration complete." }
the vhd is not the problem. it works. - it's about bcdedit and bcdboot. I clearly pointed this out and confirmed it by editing the working parameters into the non working, as the only change, and it boots. this is a more deep topic than just "i want to boot a vhd".
Sometime ago i tried to make vhd of vm bootable using my host tool didnt succeed U looking for same thing making bcd store that will work on any other pc?
Applying my BCD entries to an internal Drive works (byte: 06). Applying it to extern UFD or fixed SSD won't work and result in a failure. (byte: 08)
found the bug. as with "path". "systemroot" also needs to specified in the osloader itself. It's not enough to set "systemroot" in {bootloadersettings}. inherit {bootloadersettings} get's kind of useless.... 5 hours down the hole.
the described problem is solved, yes. - But the entries are still different (06 vs 08 byte) addig systemroot and path to the bcd entry is mandatory and can not be defined in {bootloadersettings} alone. [I put them in there as they are always the same]
Well to be fair, a lot of them require very little actual code to utilize, because you use them in a wrapper. Attaining data like BCD info is not an exhaustive process that requires *any* declarations. I'm just giving out the info on the way I manage these because I constantly apply images to VHDs or physical disks, as well as create them, etc. in a single go; and I've had issues in the past trying to manage this info either statically via variables in scripts, or would end up with absolutely ridiculous lines of code to trim, get substrings, convert, etc. just so I could *possibly* have it work. That said, I would never spend any substantial amount of time creating an advanced function for when my server will directly manipulate all of that automatically just by running MDT or SCOM on it to "test" the hardware. I have a few examples I can post that people can use at their desire.