bcdedit 挂载 boot.wim重装系统
一、给boot.wim打补丁
创建临时目录
New-Item -Path "C:\temp_pe" -ItemType Directory -Force
挂载 boot.wim
# 查看 boot.wim 有几个映像
Get-WindowsImage -ImagePath "D:\win2025\sources\boot.wim"# 一般有 2 个,Index 1 是普通 PE,Index 2 是setup
# 挂载 Index 2
Mount-WindowsImage -ImagePath "D:\win2025\sources\boot.wim" -Index 1 -Path "C:\mount_pe"创建自动启动命令行的脚本
# 创建 Winpeshl.ini,它会替代默认的 setup.exe 启动
@"
[LaunchApps]
%SYSTEMROOT%\System32\cmd.exe
"@ | Out-File -FilePath "C:\mount_pe\Windows\System32\winpeshl.ini" -Encoding ascii
4.打磁盘驱动dism /Image:"C:\mount_pe" /Add-Driver /Driver:"D:\virtio\viostor\2k25\amd64\viostor.inf"
保存修改后的 boot.wim
# 卸载并保存
Dismount-WindowsImage -Path "C:\mount_pe" -Save
二、将index2保存为单独的wim
dism /Export-Image /SourceImageFile:"D:\win2025\sources\boot.wim" /SourceIndex:2 /DestinationImageFile:"D:\win2025\sources\boot_setup.wim"
三、bcdedit 添加启动菜单
# 1. 设置 ramdisk 选项
$null = cmd /c bcdedit /create "{ramdiskoptions}" /d "Ramdisk 选项" 2>&1
cmd /c bcdedit /set "{ramdiskoptions}" ramdisksdidevice partition=D:
cmd /c bcdedit /set "{ramdiskoptions}" ramdisksdipath \win2025\boot\boot.sdi
# 2. 创建新启动项并捕获 GUID
$output = cmd /c bcdedit /copy "{current}" /d "Windows PE 恢复环境"
$guid = ($output | Select-String '{[^}]+}').Matches.Value
Write-Host "新启动项 GUID: $guid" -ForegroundColor Green
# 3. 配置启动项
cmd /c bcdedit /set $guid device "ramdisk=[D:]\win2025\sources\boot_setup.wim,{ramdiskoptions}"
cmd /c bcdedit /set $guid osdevice "ramdisk=[D:]\win2025\sources\boot_setup.wim,{ramdiskoptions}"
cmd /c bcdedit /set $guid winpe yes
cmd /c bcdedit /set $guid detecthal yes
cmd /c bcdedit /set $guid systemroot \Windows
# 4. 显示启动菜单
cmd /c bcdedit /set "{bootmgr}" displaybootmenu yes
cmd /c bcdedit /set "{bootmgr}" timeout 5
Write-Host "`n设置完成!重启后选择 'Windows PE 恢复环境' 即可进入。" -ForegroundColor Yellow