From 56a8d9b42126c017ee7363ae4c9c0a50afe18ce1 Mon Sep 17 00:00:00 2001 From: bin456789 Date: Wed, 15 Nov 2023 20:51:44 +0800 Subject: [PATCH] =?UTF-8?q?windows:=20=E5=9C=A8=20pe=20=E4=B8=8B=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE=E4=B8=BB=E7=A1=AC=E7=9B=98=20id?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- trans.sh | 30 ++++++++++++++++++++---------- windows-setup.bat | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 10 deletions(-) create mode 100644 windows-setup.bat diff --git a/trans.sh b/trans.sh index 04575f1..6bf5a28 100644 --- a/trans.sh +++ b/trans.sh @@ -1793,15 +1793,18 @@ install_windows() { locale=$(wiminfo $install_wim | grep 'Default Language' | head -1 | awk '{print $NF}') sed -i "s|%arch%|$arch|; s|%image_name%|$image_name|; s|%locale%|$locale|" /tmp/Autounattend.xml - # sda 只读,放的是 cloud-init 配置,通常 win 有驱动,能识别 - # 而 vda/nvme/xen 加载驱动后才能识别,所以这时 disk_id 应该为 1 - if [ -e "/sys/class/block/sda/ro" ] && - [ "$(cat /sys/class/block/sda/ro)" = 1 ]; then - disk_id=1 - else - disk_id=0 + # 修改 disk_id + if false; then + # sda 只读,放的是 cloud-init 配置,通常 win 有驱动,能识别 + # 而 vda/nvme/xen 加载驱动后才能识别,所以这时 disk_id 应该为 1 + if [ -e "/sys/class/block/sda/ro" ] && + [ "$(cat /sys/class/block/sda/ro)" = 1 ]; then + disk_id=1 + else + disk_id=0 + fi + sed -i "s|%disk_id%|$disk_id|" /tmp/Autounattend.xml fi - sed -i "s|%disk_id%|$disk_id|" /tmp/Autounattend.xml # 修改应答文件,分区配置 if is_efi; then @@ -1832,7 +1835,6 @@ EOF EOF fi - unix2dos /tmp/Autounattend.xml # # ei.cfg # cat </os/installer/sources/ei.cfg @@ -1879,7 +1881,15 @@ EOF fi # 复制应答文件 - cp /tmp/Autounattend.xml /wim/ + # 移除注释,否则 windows-setup.bat 重新生成的 Autounattend.xml 有问题 + apk add xmlstarlet + xmlstarlet ed -d '//comment()' /tmp/Autounattend.xml >/wim/Autounattend.xml + unix2dos /wim/Autounattend.xml + + # 复制安装脚本 + # https://slightlyovercomplicated.com/2016/11/07/windows-pe-startup-sequence-explained/ + mv /wim/setup.exe /wim/setup.exe.disabled + download $confhome/windows-setup.bat /wim/Windows/System32/startnet.cmd # 提交修改 boot.wim wimunmount --commit /wim/ diff --git a/windows-setup.bat b/windows-setup.bat new file mode 100644 index 0000000..41835e2 --- /dev/null +++ b/windows-setup.bat @@ -0,0 +1,41 @@ +@echo off + +:: 安装 SCSI 驱动 +for %%F in ("X:\drivers\*.inf") do ( + find "Class=SCSIAdapter" "%%~F" >nul + if not errorlevel 1 ( + drvload "%%~F" + ) +) + +:: 等待加载分区 +:: 没有 timeout 命令 +:: 没有加载网卡驱动,无法用 ping 来等待 +echo wscript.sleep(5000) > sleep.vbs +cscript //nologo sleep.vbs + +:: 获取主硬盘 id +for /F "tokens=2 delims==" %%A in ('wmic logicaldisk where "VolumeName='installer'" assoc:value /resultclass:Win32_DiskPartition ^| find "DiskIndex"') do ( + set "DiskIndex=%%A" +) + +:: 设置 Autounattend.xml 的主硬盘 id +set "file=X:\Autounattend.xml" +set "tempFile=X:\tmp.xml" + +set "search=%%disk_id%%" +set "replace=%DiskIndex%" + +(for /f "delims=" %%i in (%file%) do ( + set "line=%%i" + + setlocal EnableDelayedExpansion + echo !line:%search%=%replace%! + endlocal + +)) > %tempFile% +move /y %tempFile% %file% + +:: 执行 setup.exe +ren X:\setup.exe.disabled setup.exe +X:\setup.exe