I'm attempting to reboot a computer into a flash drive media containing Windows PE, but every time it only launches Preparing Automatic Repair. Here is my powershell that generates the new bcd entry:
$drive = (get-location).Drive.Name + ":"
$output = bcdedit /copy '{current}' /d "automaticabd"
$variable = "{" + $output.Split('{')[-1]
$variable = $variable.TrimEnd('.')
"Attaching $variable to device partition $drive"
bcdedit /set $variable device partition=$drive
""
"Attaching $variable to osdevice partition $drive"
bcdedit /set $variable osdevice partition=$drive
""
"Setting $variable path to EFI: \EFI\Boot\bootx64.efi"
bcdedit /set $variable path \EFI\Boot\bootx64.efi
""
"Other settings..."
bcdedit /set $variable systemroot \windows
bcdedit /set $variable winpe yes
bcdedit /set $variable recoveryenabled No
bcdedit /bootsequence $variable
All operations are completed successfully, and it appears as though the entry is correct to my knowledge:
But, when I restart the computer I used to get the message "Repairing Automatic Recovery" which would then eventually go into Windows Recovery environment. I have since added bcdedit /set $variable recoveryenabled No
, which makes it so it cannot possibly go into the recovery environment, but I get a different error now:
The application or operating system couldn't be loaded because a required file is missing or contains errors.
File: \EFI\Boot\bootx64.efi Error code: 0xc000007b
But, if I go into boot options and select this file manually, it boots into winpe just fine.
I'm not really sure what's going wrong, any help would be greatly appreciated.
How can I fix my code to allow me to successfully boot into Windows PE on my flash drive?
This problem can be depending from a different perspective of what is named as c: between the moment you run the powershell and the moment the system is going to boot.
Can you try this ?
Boot by using the USB drive open a console and type:
bcdedit / export C: \ SAVEDBCD
I expect that C: in this case should correspond to your pendrive, isn't it ?
Then reboot normally, execute your powershell script.
You should notice that the pendrive letter you get in $drive is not c:\ since when the system started the C:\ is already occupied from the hard disk primary windows partition.
Now compare the previously saved SAVEBCD file with the one present in c:\boot\bcd, you should make them equal in order to have the boot working , so likely you just need to start your code with: