mirror of
https://github.com/bin456789/reinstall.git
synced 2025-06-08 13:29:58 +00:00
Compare commits
5 Commits
770000ea9d
...
103ef84f92
Author | SHA1 | Date | |
---|---|---|---|
![]() |
103ef84f92 | ||
![]() |
f4f2481009 | ||
![]() |
2fb31ed7c3 | ||
![]() |
318f0e589a | ||
![]() |
36ee398eb6 |
@ -30,15 +30,25 @@ if errorlevel 1 (
|
|||||||
|
|
||||||
rem 有时 %tmp% 带会话 id,且文件夹不存在
|
rem 有时 %tmp% 带会话 id,且文件夹不存在
|
||||||
rem https://learn.microsoft.com/troubleshoot/windows-server/shell-experience/temp-folder-with-logon-session-id-deleted
|
rem https://learn.microsoft.com/troubleshoot/windows-server/shell-experience/temp-folder-with-logon-session-id-deleted
|
||||||
if not exist %tmp% (
|
rem if not exist %tmp% (
|
||||||
md %tmp%
|
rem md %tmp%
|
||||||
)
|
rem )
|
||||||
|
|
||||||
rem 检查是否国内
|
rem 下载 geoip
|
||||||
if not exist geoip (
|
if not exist geoip (
|
||||||
rem www.cloudflare.com/dash.cloudflare.com 国内访问的是美国服务器,而且部分地区被墙
|
rem www.cloudflare.com/dash.cloudflare.com 国内访问的是美国服务器,而且部分地区被墙
|
||||||
call :download http://www.qualcomm.cn/cdn-cgi/trace %~dp0geoip || goto :download_failed
|
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
|
findstr /c:"loc=CN" geoip >nul
|
||||||
if not errorlevel 1 (
|
if not errorlevel 1 (
|
||||||
rem mirrors.tuna.tsinghua.edu.cn 会强制跳转 https
|
rem mirrors.tuna.tsinghua.edu.cn 会强制跳转 https
|
||||||
@ -60,23 +70,35 @@ if not errorlevel 1 (
|
|||||||
call :check_cygwin_installed || (
|
call :check_cygwin_installed || (
|
||||||
rem win10 arm 支持运行 x86 软件
|
rem win10 arm 支持运行 x86 软件
|
||||||
rem win11 arm 支持运行 x86 和 x86_64 软件
|
rem win11 arm 支持运行 x86 和 x86_64 软件
|
||||||
rem wmic os get osarchitecture 显示中文
|
|
||||||
rem wmic ComputerSystem get SystemType 显示英文
|
|
||||||
|
|
||||||
rem SystemType
|
|
||||||
rem windows 11 24h2 没有 wmic
|
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
|
rem 有的系统精简了 powershell
|
||||||
where wmic >nul 2>&1
|
rem for /f "delims=" %%a in ('powershell -NoLogo -NoProfile -NonInteractive -Command "(Get-WmiObject win32_computersystem).SystemType"') do (
|
||||||
if not errorlevel 1 (
|
rem set "SystemType=%%a"
|
||||||
for /f "tokens=*" %%a in ('wmic ComputerSystem get SystemType ^| find /i "based"') do (
|
rem )
|
||||||
set "SystemType=%%a"
|
|
||||||
)
|
rem SystemArch
|
||||||
) else (
|
for /f "tokens=3" %%a in ('reg query "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v PROCESSOR_ARCHITECTURE') do (
|
||||||
for /f "delims=" %%a in ('powershell -NoLogo -NoProfile -NonInteractive -Command "(Get-WmiObject win32_computersystem).SystemType"') do (
|
set SystemArch=%%a
|
||||||
set "SystemType=%%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
|
rem BuildNumber
|
||||||
for /f "tokens=3" %%a in ('reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v CurrentBuildNumber') do (
|
for /f "tokens=3" %%a in ('reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v CurrentBuildNumber') do (
|
||||||
set /a BuildNumber=%%a
|
set /a BuildNumber=%%a
|
||||||
@ -84,13 +106,13 @@ call :check_cygwin_installed || (
|
|||||||
|
|
||||||
set CygwinEOL=1
|
set CygwinEOL=1
|
||||||
|
|
||||||
echo !SystemType! | find "ARM" > nul
|
echo !SystemArch! | find "ARM" > nul
|
||||||
if not errorlevel 1 (
|
if not errorlevel 1 (
|
||||||
if !BuildNumber! GEQ 22000 (
|
if !BuildNumber! GEQ 22000 (
|
||||||
set CygwinEOL=0
|
set CygwinEOL=0
|
||||||
)
|
)
|
||||||
) else (
|
) else (
|
||||||
echo !SystemType! | find "x64" > nul
|
echo !SystemArch! | find "AMD64" > nul
|
||||||
if not errorlevel 1 (
|
if not errorlevel 1 (
|
||||||
if !BuildNumber! GEQ 9600 (
|
if !BuildNumber! GEQ 9600 (
|
||||||
set CygwinEOL=0
|
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
|
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
|
rem 安装 Cygwin
|
||||||
set site=!mirror!!dir!
|
set site=!mirror!!dir!
|
||||||
start /wait setup-!CygwinArch!.exe ^
|
start /wait setup-!CygwinArch!.exe ^
|
||||||
|
19
reinstall.sh
19
reinstall.sh
@ -4002,16 +4002,24 @@ redhat | centos | almalinux | rocky | fedora | ubuntu)
|
|||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
# 检查内存
|
|
||||||
check_ram
|
|
||||||
|
|
||||||
# 检查硬件架构
|
# 检查硬件架构
|
||||||
if is_in_windows; then
|
if is_in_windows; then
|
||||||
# x86-based PC
|
# x86-based PC
|
||||||
# x64-based PC
|
# x64-based PC
|
||||||
# ARM-based PC
|
# ARM-based PC
|
||||||
# ARM64-based PC
|
# ARM64-based PC
|
||||||
|
|
||||||
|
if false; then
|
||||||
|
# 如果机器没有 wmic 则需要下载 wmic.ps1,但此时未判断国内外,还是用国外源
|
||||||
basearch=$(wmic ComputerSystem get SystemType | grep '=' | cut -d= -f2 | cut -d- -f1)
|
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
|
else
|
||||||
# archlinux 云镜像没有 arch 命令
|
# archlinux 云镜像没有 arch 命令
|
||||||
# https://en.wikipedia.org/wiki/Uname
|
# https://en.wikipedia.org/wiki/Uname
|
||||||
@ -4045,6 +4053,7 @@ if false && [[ "$confhome" = http*://raw.githubusercontent.com/* ]]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# 设置国内代理
|
# 设置国内代理
|
||||||
|
# 要在使用 wmic 前设置,否则国内机器会从国外源下载 wmic.ps1
|
||||||
# gitee 不支持ipv6
|
# gitee 不支持ipv6
|
||||||
# jsdelivr 有12小时缓存
|
# jsdelivr 有12小时缓存
|
||||||
# https://github.com/XIU2/UserScript/blob/master/GithubEnhanced-High-Speed-Download.user.js#L31
|
# 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
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# 检查内存
|
||||||
|
# 会用到 wmic,因此要在设置国内 confhome 后使用
|
||||||
|
check_ram
|
||||||
|
|
||||||
# 以下目标系统不需要两步安装
|
# 以下目标系统不需要两步安装
|
||||||
# alpine
|
# alpine
|
||||||
# debian
|
# debian
|
||||||
|
79
trans.sh
79
trans.sh
@ -2328,6 +2328,10 @@ get_disk_logic_sector_size() {
|
|||||||
blockdev --getss "$1"
|
blockdev --getss "$1"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
is_4kn() {
|
||||||
|
[ "$(blockdev --getss "$1")" = 4096 ]
|
||||||
|
}
|
||||||
|
|
||||||
is_xda_gt_2t() {
|
is_xda_gt_2t() {
|
||||||
disk_size=$(get_disk_size /dev/$xda)
|
disk_size=$(get_disk_size /dev/$xda)
|
||||||
disk_2t=$((2 * 1024 * 1024 * 1024 * 1024))
|
disk_2t=$((2 * 1024 * 1024 * 1024 * 1024))
|
||||||
@ -5351,13 +5355,29 @@ hivexget() {
|
|||||||
ash "$(which hivexget)" "$@"
|
ash "$(which hivexget)" "$@"
|
||||||
}
|
}
|
||||||
|
|
||||||
get_installation_type_from_windows_drive() {
|
get_windows_type_from_windows_drive() {
|
||||||
local os_dir=$1
|
local os_dir=$1
|
||||||
|
|
||||||
apk add hivex
|
apk add hivex
|
||||||
hive=$(find_file_ignore_case $os_dir/Windows/System32/config/SOFTWARE)
|
software_hive=$(find_file_ignore_case $os_dir/Windows/System32/config/SOFTWARE)
|
||||||
hivexget $hive '\Microsoft\Windows NT\CurrentVersion' InstallationType
|
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
|
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() {
|
get_windows_arch_from_windows_drive() {
|
||||||
@ -5506,7 +5526,7 @@ install_windows() {
|
|||||||
# 用内核版本号筛选驱动
|
# 用内核版本号筛选驱动
|
||||||
# 使得可以安装 Hyper-V Server / Azure Stack HCI 等 Windows Server 变种
|
# 使得可以安装 Hyper-V Server / Azure Stack HCI 等 Windows Server 变种
|
||||||
# 7601.24214.180801-1700.win7sp1_ldr_escrow_CLIENT_ULTIMATE_x64FRE_en-us.iso wim 没有 Installation Type
|
# 7601.24214.180801-1700.win7sp1_ldr_escrow_CLIENT_ULTIMATE_x64FRE_en-us.iso wim 没有 Installation Type
|
||||||
# 因此改成从注册表获取
|
# Vista wim 和 注册表 都没有 InstallationType
|
||||||
if false; then
|
if false; then
|
||||||
nt_ver=$(get_selected_image_prop "Major Version").$(get_selected_image_prop "Minor Version")
|
nt_ver=$(get_selected_image_prop "Major Version").$(get_selected_image_prop "Minor Version")
|
||||||
build_ver=$(get_selected_image_prop "Build")
|
build_ver=$(get_selected_image_prop "Build")
|
||||||
@ -5521,7 +5541,7 @@ install_windows() {
|
|||||||
wimmount "$iso_install_wim" "$image_index" /wim/
|
wimmount "$iso_install_wim" "$image_index" /wim/
|
||||||
ntoskrnl_exe=$(find_file_ignore_case /wim/Windows/System32/ntoskrnl.exe)
|
ntoskrnl_exe=$(find_file_ignore_case /wim/Windows/System32/ntoskrnl.exe)
|
||||||
get_windows_version_from_dll "$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/System32/sacsess.exe && has_sac=true || has_sac=false
|
||||||
find_file_ignore_case /wim/Windows/INF/stornvme.inf && has_stornvme=true || has_stornvme=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
|
support_sha256=true
|
||||||
fi
|
fi
|
||||||
|
|
||||||
case "$installation_type" in
|
product_ver=$(
|
||||||
Client | Embedded)
|
case "$windows_type" in
|
||||||
windows_type=client
|
client) get_client_name_by_build_ver "$build_ver" ;;
|
||||||
product_ver=$(get_client_name_by_build_ver "$build_ver")
|
server) get_server_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" ;;
|
|
||||||
esac
|
esac
|
||||||
|
)
|
||||||
|
|
||||||
info "Selected image info"
|
info "Selected image info"
|
||||||
echo "Image Name: $image_name"
|
echo "Image Name: $image_name"
|
||||||
@ -5921,15 +5936,39 @@ EOF
|
|||||||
|
|
||||||
apk add msitools
|
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=$(
|
aws_pv_ver=$(
|
||||||
case "$nt_ver" in
|
case "$nt_ver" in
|
||||||
6.1) $support_sha256 && echo 8.3.5 || echo 8.3.2 ;;
|
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 ;;
|
*) echo Latest ;;
|
||||||
esac
|
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
|
unzip -o -d $drv $drv/AWSPVDriver.zip
|
||||||
mkdir -p $drv/xen/
|
mkdir -p $drv/xen/
|
||||||
@ -6492,6 +6531,12 @@ EOF
|
|||||||
sed -i 's/EnableEMS=0/EnableEMS=1/i' $startnet_cmd
|
sed -i 's/EnableEMS=0/EnableEMS=1/i' $startnet_cmd
|
||||||
fi
|
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
|
# Windows Thin PC 有 Windows\System32\winpeshl.ini
|
||||||
# [LaunchApps]
|
# [LaunchApps]
|
||||||
# %SYSTEMDRIVE%\windows\system32\drvload.exe, %SYSTEMDRIVE%\windows\inf\sdbus.inf
|
# %SYSTEMDRIVE%\windows\system32\drvload.exe, %SYSTEMDRIVE%\windows\inf\sdbus.inf
|
||||||
|
@ -93,6 +93,14 @@ for /f "tokens=3" %%a in (X:\disk.txt) do (
|
|||||||
)
|
)
|
||||||
del X:\disk.txt
|
del X:\disk.txt
|
||||||
|
|
||||||
|
rem 这个变量会被 trans.sh 修改
|
||||||
|
set is4kn=0
|
||||||
|
if "%is4kn%"=="1" (
|
||||||
|
set EFISize=260
|
||||||
|
) else (
|
||||||
|
set EFISize=100
|
||||||
|
)
|
||||||
|
|
||||||
rem 重新分区/格式化
|
rem 重新分区/格式化
|
||||||
(if "%BootType%"=="efi" (
|
(if "%BootType%"=="efi" (
|
||||||
echo select disk %DiskIndex%
|
echo select disk %DiskIndex%
|
||||||
@ -104,7 +112,7 @@ rem 重新分区/格式化
|
|||||||
echo select part 3
|
echo select part 3
|
||||||
echo delete part override
|
echo delete part override
|
||||||
|
|
||||||
echo create part efi size=100
|
echo create part efi size=%EFISize%
|
||||||
echo format fs=fat32 quick
|
echo format fs=fat32 quick
|
||||||
|
|
||||||
echo create part msr size=16
|
echo create part msr size=16
|
||||||
|
Loading…
x
Reference in New Issue
Block a user