diff --git a/trans.sh b/trans.sh index 72a0a0c..b8e1499 100644 --- a/trans.sh +++ b/trans.sh @@ -1973,9 +1973,9 @@ install_windows() { # https://github.com/virtio-win/virtio-win-pkg-scripts/issues/40 # https://github.com/virtio-win/virtio-win-pkg-scripts/issues/61 - case "$sys" in - vista | w7 | 2k8 | 2k8R2) dir=archive-virtio/virtio-win-0.1.173-9 ;; - w8 | w8.1 | 2k12 | 2k12R2) dir=archive-virtio/virtio-win-0.1.215-1 ;; + case "$nt_ver" in + 6.0 | 6.1) dir=archive-virtio/virtio-win-0.1.173-9 ;; # vista | w7 | 2k8 | 2k8R2 + 6.2 | 6.3) dir=archive-virtio/virtio-win-0.1.215-1 ;; # win8 | w8.1 | 2k12 | 2k12R2 *) dir=stable-virtio ;; esac @@ -2013,12 +2013,18 @@ install_windows() { sed -i "s|%installto_partitionid%|1|" /tmp/autounattend.xml fi - # 评估版 iso 需要删除 autounattend.xml 里面的 - # 否则会出现 Windows Cannot find Microsoft software license terms # shellcheck disable=SC2010 if ei_cfg="$(ls -d /os/installer/sources/* | grep -i ei.cfg)"; then + # 评估版 iso 需要删除 autounattend.xml 里面的 + # 否则会出现 Windows Cannot find Microsoft software license terms if grep -i EVAL "$ei_cfg"; then - sed -i '//d' /tmp/autounattend.xml + sed -i "s|||" /tmp/autounattend.xml + fi + else + # vista 需密钥,密钥与 edition 可以不一致 + if [[ "$image_name" = 'Windows Vista'* ]]; then + vista_gvlk=VKK3X-68KWM-X2YGT-QR4M6-4BWMV + sed -i "s||$vista_gvlk|" /tmp/autounattend.xml fi fi @@ -2028,28 +2034,32 @@ install_windows() { cp_drivers() { src=$1 - path=$2 + shift - [ -n "$path" ] && filter="-ipath $path" || filter="" find $src \ - $filter \ -type f \ -not -iname "*.pdb" \ -not -iname "dpinst.exe" \ + "$@" \ -exec cp -rfv {} /wim/drivers \; } # 添加驱动 mkdir -p /wim/drivers - - [ -d $drv/virtio ] && cp_drivers $drv/virtio "*/$sys/$arch/*" + [ -d $drv/virtio ] && { + if [ "$nt_ver" = 6.0 ]; then + # 气球驱动有问题 + cp_drivers $drv/virtio -ipath "*/$sys/$arch/*" -not -ipath "*/balloon/*" + else + cp_drivers $drv/virtio -ipath "*/$sys/$arch/*" + fi + } [ -d $drv/aws ] && cp_drivers $drv/aws - [ -d $drv/xen ] && cp_drivers $drv/xen "*/$arch_xen/*" + [ -d $drv/xen ] && cp_drivers $drv/xen -ipath "*/$arch_xen/*" [ -d $drv/gce ] && { [ "$arch_wim" = x86 ] && gvnic_suffix=-32 || gvnic_suffix= - cp_drivers $drv/gce/gvnic "*/$sys_gce$gvnic_suffix/*" - # gga 驱动不分32/64位 - cp_drivers $drv/gce/gga "*/$sys_gce/*" + cp_drivers $drv/gce/gvnic -ipath "*/$sys_gce$gvnic_suffix/*" + cp_drivers $drv/gce/gga -ipath "*/$sys_gce/*" } # win7 要添加 bootx64.efi 到 efi 目录 diff --git a/windows-setup.bat b/windows-setup.bat index 165e936..1f58210 100644 --- a/windows-setup.bat +++ b/windows-setup.bat @@ -20,12 +20,6 @@ for %%F in ("X:\drivers\*.inf") do ( echo wscript.sleep(5000) > sleep.vbs cscript //nologo sleep.vbs -:: 获取主硬盘 id -:: 注意 vista pe 没有 wmic -for /F "tokens=2 delims==" %%A in ('wmic logicaldisk where "VolumeName='installer'" assoc:value /resultclass:Win32_DiskPartition ^| find "DiskIndex"') do ( - set "DiskIndex=%%A" -) - :: 判断 efi 还是 bios echo list vol | diskpart | find "efi" && ( set boot_type=efi @@ -33,6 +27,25 @@ echo list vol | diskpart | find "efi" && ( set boot_type=bios ) +:: 获取 installer 卷 id +for /f "tokens=2" %%a in ('echo list vol ^| diskpart ^| find "installer"') do ( + set "VolIndex=%%a" +) + +:: 将 installer 分区设为 Y 盘 +(echo select vol %VolIndex% & echo assign letter=Y) | diskpart + +:: 设置虚拟内存,好像没必要,安装时会自动在 C 盘设置虚拟内存 +rem wpeutil CreatePageFile /path=Y:\pagefile.sys + +:: 获取主硬盘 id +:: vista pe 没有 wmic,因此用 diskpart +(echo select vol %VolIndex% & echo list disk) | diskpart | find "* " > X:\disk.txt +for /f "tokens=3" %%a in (X:\disk.txt) do ( + set "DiskIndex=%%a" +) +del X:\disk.txt + :: 重新分区/格式化 (if "%boot_type%"=="efi" ( echo select disk %DiskIndex% @@ -58,9 +71,13 @@ echo list vol | diskpart | find "efi" && ( echo format fs=ntfs quick )) > X:\diskpart.txt - :: 使用 diskpart /s ,出错不会执行剩下的 diskpart 命令 diskpart /s X:\diskpart.txt +del X:\diskpart.txt + +:: 盘符 +rem X boot.wim (ram) +rem Y installer :: 设置 autounattend.xml 的主硬盘 id set "file=X:\autounattend.xml" @@ -79,6 +96,9 @@ set "replace=%DiskIndex%" )) > %tempFile% move /y %tempFile% %file% -:: 执行 setup.exe rename X:\setup.exe.disabled setup.exe -X:\setup.exe /emsport:COM1 /emsbaudrate:115200 + +:: 运行 X:\setup.exe 的话 +:: vista 会找不到安装源 +:: server 23h2 会无法运行 +Y:\setup.exe /emsport:COM1 /emsbaudrate:115200 diff --git a/windows.xml b/windows.xml index 39764d4..e94fa5a 100644 --- a/windows.xml +++ b/windows.xml @@ -6,7 +6,7 @@ true OnError - +