windows: 在 pe 下设置主硬盘 id
This commit is contained in:
parent
56f5c90a26
commit
56a8d9b421
30
trans.sh
30
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
|
||||
</ModifyPartition>
|
||||
EOF
|
||||
fi
|
||||
unix2dos /tmp/Autounattend.xml
|
||||
|
||||
# # ei.cfg
|
||||
# cat <<EOF >/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/
|
||||
|
41
windows-setup.bat
Normal file
41
windows-setup.bat
Normal file
@ -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
|
Loading…
Reference in New Issue
Block a user