From 8393297606ece292e649bf339381147adc24a193 Mon Sep 17 00:00:00 2001 From: bin456789 Date: Tue, 1 Oct 2024 20:05:24 +0800 Subject: [PATCH] =?UTF-8?q?windows:=20BIOS=20=E5=BC=95=E5=AF=BC=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=2024H2=20=E6=96=B0=E5=AE=89=E8=A3=85=E5=99=A8?= =?UTF-8?q?=E6=97=B6=EF=BC=8C=E9=9C=80=E6=89=8B=E5=8A=A8=E5=86=99=E5=85=A5?= =?UTF-8?q?=20Windows=20MBR?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- windows-setup.bat | 45 +++++++++++++++++++++++++++++---------------- 1 file changed, 29 insertions(+), 16 deletions(-) diff --git a/windows-setup.bat b/windows-setup.bat index 6498ab0..e601a93 100644 --- a/windows-setup.bat +++ b/windows-setup.bat @@ -43,6 +43,11 @@ echo list vol | diskpart | find "efi" && ( set BootType=bios ) +rem 获取 BuildNumber +for /f "tokens=3" %%a in ('reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v CurrentBuildNumber') do ( + set "BuildNumber=%%a" +) + rem 获取 installer 卷 id for /f "tokens=2" %%a in ('echo list vol ^| diskpart ^| find "installer"') do ( set "VolIndex=%%a" @@ -125,36 +130,44 @@ for %%a in (RAM TPM SecureBoot) do ( rem 设置 set EnableEMS=0 -set ForceOldSetup=1 +set ForceOldSetup=0 set EnableUnattended=1 -if %EnableEMS% EQU 1 ( +if "%EnableEMS%"=="1" ( set EMS=/EMSPort:COM1 /EMSBaudRate:115200 ) -if %EnableUnattended% EQU 1 ( +if "%EnableUnattended%"=="1" ( set Unattended=/unattend:X:\windows.xml ) +rem 新版安装程序默认开了 Compact OS + +rem 新版安装程序不会创建 BIOS MBR 引导 +rem 因此要回退到旧版,或者手动修复 MBR +rem server 2025 + bios 也是 +rem 但是 server 2025 官网写支持 bios +rem TODO: 使用 ms-sys 可以不修复? +if %BuildNumber% GEQ 26040 if "%BootType%"=="bios" ( + rem set ForceOldSetup=1 + bootrec /fixmbr +) + +rem 旧版安装程序不会创建 winre 分区 +rem 新版安装程序会创建 winre 分区 +rem winre 分区创建在 installer 分区前面 +rem 禁止 winre 分区后,winre 储存在 C 盘,依然有效 +if %BuildNumber% GEQ 26040 if "%ForceOldSetup%"=="0" ( + set ResizeRecoveryPartition=/ResizeRecoveryPartition Disable +) + rem 运行 ramdisk X:\setup.exe 的话 rem vista 会找不到安装源 rem server 23h2 会无法运行 - -rem 26040 开始有新版安装程序 -rem 新版安装程序不会创建 BIOS MBR 引导 -if %ForceOldSetup% EQU 1 ( +if "%ForceOldSetup%"=="1" ( set setup=Y:\sources\setup.exe ) else ( set setup=Y:\setup.exe - rem 旧版安装程序不会创建 winre 分区 - rem 新版安装程序会创建 winre 分区 - rem winre 分区创建在 installer 分区前面 - rem 禁止 winre 分区后,winre 储存在 C 盘,依然有效 - for /f "tokens=3" %%a in ('reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v CurrentBuildNumber') do ( - if %%a GEQ 26040 ( - set ResizeRecoveryPartition=/ResizeRecoveryPartition Disable - ) - ) ) %setup% %ResizeRecoveryPartition% %EMS% %Unattended%