|
本帖最后由 2010hook 于 2018-1-26 08:03 编辑
我再分享一个批处理,用于生成BCD启动项,减少人为出错,抛弃BOOTICE手工添加。
VHD路径和偏移量需要注意。
- @echo off
- SetLocal EnableDelayedExpansion
- :BCD
- set "_VD=C:"
- set "_Vfile=\ram.vhd"
- set "_Rname=RamVHD"
- set "_Rfile=[%_VD%]%_Vfile%"
- for /f "tokens=2" %%i in ('BCDedit /create /d "%_Rname%" /application osloader') do set "GUID=%%i"
- BCDedit /default %GUID% 2>nul
- BCDedit /displayorder %GUID% /addlast
- for /f "tokens=2" %%i in ('BCDedit /create /d "%_Rname%" /device') do set "GUIDa=%%i"
- BCDedit /set %GUIDa% ramdiskimageoffset 65536
- BCDedit /set %GUID% device ramdisk="%_Rfile%",%GUIDa%
- BCDedit /set %GUID% osdevice ramdisk="%_Rfile%",%GUIDa%
- BCDedit /set %GUID% path \Windows\system32\boot\winload.efi
- BCDedit /set %GUID% systemroot \Windows
- BCDedit /set %GUID% locale zh-CN
- BCDedit /set %GUID% NX OptIN
- BCDedit /set %GUID% DetectHAL yes
- BCDedit /set %GUID% BootMenuPolicy legacy
- BCDedit /set %GUID% BootStatusPolicy ignoreallfailures
- pause & exit
复制代码
自动对应GUID!!代码参考@y7y007,感谢。
仔细观察会发现,Win自带工具生成的GUID很整齐,只相差一个字符。
若需修复BCD,命令很简单:
- @echo off
- mountvol.exe S: /s
- bcdboot C:\Windows /s S: /f uefi
- pause & exit
复制代码
另外,生成VHD的代码改成这样(注意会先分离删除已存在的同名VHD):
- @echo off
- SetLocal EnableDelayedExpansion
- :RamVHD
- pause
- set "_VD=X:"
- set "_Vfile=\ram.vhd"
- set "_Dfile=%_VD%%_Vfile%"
- if exist "%_Dfile%" (
- echo select vdisk file="%_Dfile%"
- echo detach vdisk)|diskpart.exe
- del /f /q "%_Dfile%" 2>nul
- ( echo create vdisk file="%_Dfile%" maximum=128 type=fixed
- echo select vdisk file="%_Dfile%"
- echo attach vdisk
- echo convert gpt
- echo create partition primary
- echo assign letter=V
- echo format fs=NTFS override quick label="RamVHD"
- echo detail part)|diskpart.exe
- pause & exit
复制代码 |
|