Compare commits

...

5 Commits

Author SHA1 Message Date
bin456789
103ef84f92
windows: 支持 4Kn 硬盘 2025-05-05 21:37:44 +08:00
bin456789
f4f2481009
windows: 降级 aws xen win2012r2 驱动
关联 #329
2025-05-05 21:27:09 +08:00
bin456789
2fb31ed7c3
windows: 修复 vista 没有 InstallationType 导致报错 2025-05-05 21:27:08 +08:00
bin456789
318f0e589a
core: 修复国内机从 github 下载 wmic.ps1 2025-05-05 21:27:07 +08:00
bin456789
36ee398eb6
core: 改进 reinstall.bat 2025-05-05 21:27:07 +08:00
4 changed files with 138 additions and 42 deletions

View File

@ -30,15 +30,25 @@ if errorlevel 1 (
rem 有时 %tmp% 带会话 id且文件夹不存在
rem https://learn.microsoft.com/troubleshoot/windows-server/shell-experience/temp-folder-with-logon-session-id-deleted
if not exist %tmp% (
md %tmp%
)
rem if not exist %tmp% (
rem md %tmp%
rem )
rem 检查是否国内
rem 下载 geoip
if not exist geoip (
rem www.cloudflare.com/dash.cloudflare.com 国内访问的是美国服务器,而且部分地区被墙
call :download http://www.qualcomm.cn/cdn-cgi/trace %~dp0geoip || goto :download_failed
)
rem 判断是否有 loc=
findstr /c:"loc=" geoip >nul
if errorlevel 1 (
echo Invalid geoip file
del geoip
exit /b 1
)
rem 检查是否国内
findstr /c:"loc=CN" geoip >nul
if not errorlevel 1 (
rem mirrors.tuna.tsinghua.edu.cn 会强制跳转 https
@ -60,23 +70,35 @@ if not errorlevel 1 (
call :check_cygwin_installed || (
rem win10 arm 支持运行 x86 软件
rem win11 arm 支持运行 x86 和 x86_64 软件
rem wmic os get osarchitecture 显示中文
rem wmic ComputerSystem get SystemType 显示英文
rem SystemType
rem windows 11 24h2 没有 wmic
rem wmic os get osarchitecture 显示中文,即使设置了 mode con cp select=437
rem wmic ComputerSystem get SystemType 显示英文
rem for /f "tokens=*" %%a in ('wmic ComputerSystem get SystemType ^| find /i "based"') do (
rem set "SystemType=%%a"
rem )
rem 有的系统精简了 powershell
where wmic >nul 2>&1
if not errorlevel 1 (
for /f "tokens=*" %%a in ('wmic ComputerSystem get SystemType ^| find /i "based"') do (
set "SystemType=%%a"
)
) else (
for /f "delims=" %%a in ('powershell -NoLogo -NoProfile -NonInteractive -Command "(Get-WmiObject win32_computersystem).SystemType"') do (
set "SystemType=%%a"
)
rem for /f "delims=" %%a in ('powershell -NoLogo -NoProfile -NonInteractive -Command "(Get-WmiObject win32_computersystem).SystemType"') do (
rem set "SystemType=%%a"
rem )
rem SystemArch
for /f "tokens=3" %%a in ('reg query "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v PROCESSOR_ARCHITECTURE') do (
set SystemArch=%%a
)
rem 也可以用 PROCESSOR_ARCHITEW6432 和 PROCESSOR_ARCHITECTURE 判断
rem ARM64 win11 PROCESSOR_ARCHITEW6432 PROCESSOR_ARCHITECTURE
rem 原生cmd 未定义 ARM64
rem 32位cmd ARM64 x86
rem if defined PROCESSOR_ARCHITEW6432 (
rem set "SystemArch=%PROCESSOR_ARCHITEW6432%"
rem ) else (
rem set "SystemArch=%PROCESSOR_ARCHITECTURE%"
rem )
rem BuildNumber
for /f "tokens=3" %%a in ('reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v CurrentBuildNumber') do (
set /a BuildNumber=%%a
@ -84,13 +106,13 @@ call :check_cygwin_installed || (
set CygwinEOL=1
echo !SystemType! | find "ARM" > nul
echo !SystemArch! | find "ARM" > nul
if not errorlevel 1 (
if !BuildNumber! GEQ 22000 (
set CygwinEOL=0
)
) else (
echo !SystemType! | find "x64" > nul
echo !SystemArch! | find "AMD64" > nul
if not errorlevel 1 (
if !BuildNumber! GEQ 9600 (
set CygwinEOL=0
@ -114,6 +136,14 @@ call :check_cygwin_installed || (
call :download http://www.cygwin.com/setup-!CygwinArch!.exe %~dp0setup-!CygwinArch!.exe || goto :download_failed
)
rem 少于 1M 视为无效
rem 有的 IP 被官网拉黑,无法下载 exe下载得到 html
for %%A in (setup-!CygwinArch!.exe) do if %%~zA LSS 1048576 (
echo Invalid Cgywin installer
del setup-!CygwinArch!.exe
exit /b 1
)
rem 安装 Cygwin
set site=!mirror!!dir!
start /wait setup-!CygwinArch!.exe ^

View File

@ -4002,16 +4002,24 @@ redhat | centos | almalinux | rocky | fedora | ubuntu)
;;
esac
# 检查内存
check_ram
# 检查硬件架构
if is_in_windows; then
# x86-based PC
# x64-based PC
# ARM-based PC
# ARM64-based PC
if false; then
# 如果机器没有 wmic 则需要下载 wmic.ps1但此时未判断国内外还是用国外源
basearch=$(wmic ComputerSystem get SystemType | grep '=' | cut -d= -f2 | cut -d- -f1)
elif true; then
# 可以用
basearch=$(reg query "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v PROCESSOR_ARCHITECTURE |
grep . | tail -1 | awk '{print $NF}')
else
# 也可以用
basearch=$(cmd /c "if defined PROCESSOR_ARCHITEW6432 (echo %PROCESSOR_ARCHITEW6432%) else (echo %PROCESSOR_ARCHITECTURE%)")
fi
else
# archlinux 云镜像没有 arch 命令
# https://en.wikipedia.org/wiki/Uname
@ -4045,6 +4053,7 @@ if false && [[ "$confhome" = http*://raw.githubusercontent.com/* ]]; then
fi
# 设置国内代理
# 要在使用 wmic 前设置,否则国内机器会从国外源下载 wmic.ps1
# gitee 不支持ipv6
# jsdelivr 有12小时缓存
# https://github.com/XIU2/UserScript/blob/master/GithubEnhanced-High-Speed-Download.user.js#L31
@ -4057,6 +4066,10 @@ if is_in_china; then
fi
fi
# 检查内存
# 会用到 wmic因此要在设置国内 confhome 后使用
check_ram
# 以下目标系统不需要两步安装
# alpine
# debian

View File

@ -2328,6 +2328,10 @@ get_disk_logic_sector_size() {
blockdev --getss "$1"
}
is_4kn() {
[ "$(blockdev --getss "$1")" = 4096 ]
}
is_xda_gt_2t() {
disk_size=$(get_disk_size /dev/$xda)
disk_2t=$((2 * 1024 * 1024 * 1024 * 1024))
@ -5351,13 +5355,29 @@ hivexget() {
ash "$(which hivexget)" "$@"
}
get_installation_type_from_windows_drive() {
get_windows_type_from_windows_drive() {
local os_dir=$1
apk add hivex
hive=$(find_file_ignore_case $os_dir/Windows/System32/config/SOFTWARE)
hivexget $hive '\Microsoft\Windows NT\CurrentVersion' InstallationType
software_hive=$(find_file_ignore_case $os_dir/Windows/System32/config/SOFTWARE)
system_hive=$(find_file_ignore_case $os_dir/Windows/System32/config/SYSTEM)
installation_type=$(hivexget $software_hive '\Microsoft\Windows NT\CurrentVersion' InstallationType || true)
product_type=$(hivexget $system_hive '\ControlSet001\Control\ProductOptions' ProductType || true)
apk del hivex
# 根据 win11 multi-session 的情况
# InstallationType 比 ProductType 准确
# Vista wim 和注册表都没有 InstallationType
case "$installation_type" in
Client | Embedded) echo client ;;
Server | 'Server Core') echo server ;;
*) case "$product_type" in
WinNT) echo client ;;
ServerNT) echo server ;;
*) error_and_exit "Unknown Windows Type" ;;
esac ;;
esac
}
get_windows_arch_from_windows_drive() {
@ -5506,7 +5526,7 @@ install_windows() {
# 用内核版本号筛选驱动
# 使得可以安装 Hyper-V Server / Azure Stack HCI 等 Windows Server 变种
# 7601.24214.180801-1700.win7sp1_ldr_escrow_CLIENT_ULTIMATE_x64FRE_en-us.iso wim 没有 Installation Type
# 因此改成从注册表获取
# Vista wim 和 注册表 都没有 InstallationType
if false; then
nt_ver=$(get_selected_image_prop "Major Version").$(get_selected_image_prop "Minor Version")
build_ver=$(get_selected_image_prop "Build")
@ -5521,7 +5541,7 @@ install_windows() {
wimmount "$iso_install_wim" "$image_index" /wim/
ntoskrnl_exe=$(find_file_ignore_case /wim/Windows/System32/ntoskrnl.exe)
get_windows_version_from_dll "$ntoskrnl_exe"
installation_type=$(get_installation_type_from_windows_drive /wim)
windows_type=$(get_windows_type_from_windows_drive /wim)
{
find_file_ignore_case /wim/Windows/System32/sacsess.exe && has_sac=true || has_sac=false
find_file_ignore_case /wim/Windows/INF/stornvme.inf && has_stornvme=true || has_stornvme=false
@ -5540,17 +5560,12 @@ install_windows() {
support_sha256=true
fi
case "$installation_type" in
Client | Embedded)
windows_type=client
product_ver=$(get_client_name_by_build_ver "$build_ver")
;;
Server | 'Server Core')
windows_type=server
product_ver=$(get_server_name_by_build_ver "$build_ver")
;;
*) error_and_exit "Unknown Installation Type: $installation_type" ;;
product_ver=$(
case "$windows_type" in
client) get_client_name_by_build_ver "$build_ver" ;;
server) get_server_name_by_build_ver "$build_ver" ;;
esac
)
info "Selected image info"
echo "Image Name: $image_name"
@ -5921,15 +5936,39 @@ EOF
apk add msitools
# 8.4.3 的 xenbus 挑创建实例时的初始系统
# 初始系统为 windows 的实例支持 8.4.3
# 初始系统为 linux 的实例不支持 8.4.3
# 初始系统为 linux + 安装 8.4.3
# 如果用 msi 安装,则不会启用 xenbus结果是能启动但无法上网
# 如果通过 inf 安装,则会启用 xenbus结果是无法启动
apk add lscpu
hypervisor_vendor=$(lscpu | grep 'Hypervisor vendor:' | awk '{print $3}')
apk del lscpu
aws_pv_ver=$(
case "$nt_ver" in
6.1) $support_sha256 && echo 8.3.5 || echo 8.3.2 ;;
6.2 | 6.3) echo 8.4.3 ;;
6.2 | 6.3)
case "$hypervisor_vendor" in
Microsoft) echo 8.4.3 ;; # 实例初始系统为 Windows能使用 8.4.3
Xen) echo 8.3.5 ;; # 实例初始系统为 Linux不能使用 8.4.3
esac
;;
*) echo Latest ;;
esac
)
download "$(get_aws_repo)/AWSPV/$aws_pv_ver/AWSPVDriver.zip" $drv/AWSPVDriver.zip
url=$(
case "$aws_pv_ver" in
8.3.2) echo https://web.archive.org/web/20221016194548/https://s3.amazonaws.com/ec2-windows-drivers-downloads/AWSPV/$aws_pv_ver/AWSPVDriver.zip ;; # win7 sha1
*) echo "$(get_aws_repo)/AWSPV/$aws_pv_ver/AWSPVDriver.zip" ;;
esac
)
download "$url" $drv/AWSPVDriver.zip
unzip -o -d $drv $drv/AWSPVDriver.zip
mkdir -p $drv/xen/
@ -6492,6 +6531,12 @@ EOF
sed -i 's/EnableEMS=0/EnableEMS=1/i' $startnet_cmd
fi
# 4kn EFI 分区最少要 260M
# https://learn.microsoft.com/windows-hardware/manufacture/desktop/hard-drives-and-partitions
if is_4kn /dev/$xda; then
sed -i 's/is4kn=0/is4kn=1/i' $startnet_cmd
fi
# Windows Thin PC 有 Windows\System32\winpeshl.ini
# [LaunchApps]
# %SYSTEMDRIVE%\windows\system32\drvload.exe, %SYSTEMDRIVE%\windows\inf\sdbus.inf

View File

@ -93,6 +93,14 @@ for /f "tokens=3" %%a in (X:\disk.txt) do (
)
del X:\disk.txt
rem 这个变量会被 trans.sh 修改
set is4kn=0
if "%is4kn%"=="1" (
set EFISize=260
) else (
set EFISize=100
)
rem 重新分区/格式化
(if "%BootType%"=="efi" (
echo select disk %DiskIndex%
@ -104,7 +112,7 @@ rem 重新分区/格式化
echo select part 3
echo delete part override
echo create part efi size=100
echo create part efi size=%EFISize%
echo format fs=fat32 quick
echo create part msr size=16