首页 > 解决方案 > winpe 的 BCD 条目仅启动准备自动修复

问题描述

我正在尝试将计算机重新启动到包含 Windows PE 的闪存驱动器媒体中,但每次它只启动准备自动修复。这是生成新 bcd 条目的 powershell:

$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

所有操作均已成功完成,据我所知,该条目似乎是正确的:

在此处输入图像描述

但是,当我重新启动计算机时,我曾经收到“正在修复自动恢复”的消息,然后最终会进入 Windows 恢复环境。我已经添加了bcdedit /set $variable recoveryenabled No,这使得它不可能进入恢复环境,但我现在得到一个不同的错误:

无法加载应用程序或操作系统,因为所需文件丢失或包含错误。

文件:\EFI\Boot\bootx64.efi 错误代码:0xc000007b

但是,如果我进入启动选项并手动选择此文件,它会启动到 winpe 就好了。

我不太确定出了什么问题,任何帮助将不胜感激。

如何修复我的代码以允许我在闪存驱动器上成功启动到 Windows PE?

标签: powershellwinpebcdedit

解决方案


这个问题可能取决于从名为 c 的不同角度来看:在您运行 powershell 的那一刻和系统将要启动的那一刻之间。

你能试试这个吗?

使用 USB 驱动器启动打开控制台并键入:

bcdedit / 导出 C:\SAVEDBCD

我希望 C: 在这种情况下应该对应于你的 pendrive,不是吗?

然后正常重启,执行你的powershell脚本。

您应该注意到您在 $drive 中获得的 pendrive 盘符不是 c:\,因为当系统启动时,C:\ 已经被硬盘主 Windows 分区占用。

现在将之前保存的 SAVEBCD 文件与 c:\boot\bcd 中的文件进行比较,您应该使它们相等以使启动正常工作,因此您可能只需要使用以下命令启动代码:

$drive="c:"

推荐阅读