From 89800f18edd52af3740837520578f20764b30f5e Mon Sep 17 00:00:00 2001 From: bin456789 Date: Mon, 14 Oct 2024 22:41:01 +0800 Subject: [PATCH] =?UTF-8?q?windows:=20=E6=B7=BB=E5=8A=A0=20vmd=20=E9=A9=B1?= =?UTF-8?q?=E5=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.en.md | 23 ++++++++++++++++------- README.md | 21 +++++++++++++++------ reinstall.sh | 4 ++-- trans.sh | 52 +++++++++++++++++++++++++++++++++++++++++++++------- 4 files changed, 78 insertions(+), 22 deletions(-) diff --git a/README.en.md b/README.en.md index cae9019..2c6c65f 100644 --- a/README.en.md +++ b/README.en.md @@ -129,7 +129,8 @@ certutil -urlcache -f -split https://jihulab.com/bin456789/reinstall/-/raw/main/ - After reinstalling, if you need to change SSH port or switch to key-based login, be sure to modify the files inside `/etc/ssh/sshd_config.d/`. - Optional parameters: - `--password PASSWORD` Set password - - `--ssh-port PORT` Change SSH port + - `--ssh-port PORT` Change SSH port (for both the target system and log observation during installation) + - `--web-port PORT` Change Web port (for log observation during installation) - `--hold 2` Prevent entering the system after installation. You can connect via SSH to modify system content, with the system mounted at `/os` (this feature is not supported on Debian/Kali). ```bash @@ -196,8 +197,10 @@ bash reinstall.sh ubuntu --installer - When deploy a Windows image, the system disk will be expanded, and machines with static IPs will have their IPs configured. However, it may take a few minutes after the first boot for the configuration to take effect. - When deploy a Linux image, the script will not modify any contents of the image. - Optional parameters: - - `--rdp-port PORT` Change RDP port (Windows only). - - `--allow-ping` Allow ping responses (Windows only). + - `--allow-ping` Allow ping responses (Windows only) + - `--rdp-port PORT` Change RDP port (DD Windows only) + - `--ssh-port PORT` Change SSH port (for log observation during installation) + - `--web-port PORT` Change Web port (for log observation during installation) - `--hold 2` Prevent entering the system after DD completion. You can connect via SSH to modify system content, with the system mounted at `/os`. ```bash @@ -215,6 +218,7 @@ bash reinstall.sh dd --img https://example.com/xxx.xz - If the disk content is not modified, rebooting again will return to the original system. - Optional parameters: - `--password PASSWORD` Set password + - `--ssh-port PORT` Change SSH port ```bash bash reinstall.sh alpine --hold=1 @@ -238,8 +242,10 @@ bash reinstall.sh netboot.xyz - The machine with a static IP will automatically configure the IP. It may take a few minutes to take effect on the first boot. - Optional parameters: - `--password PASSWORD` Set Password - - `--rdp-port PORT` Change RDP port - `--allow-ping` Allow ping responses + - `--rdp-port PORT` Change RDP port + - `--ssh-port PORT` Change SSH port (for log observation during installation) + - `--web-port PORT` Change Web port (for log observation during installation) - `--hold 2` Allow SSH connections for modifying the hard disk content before rebooting into the official Windows installation program, with the hard disk mounted at `/os`. ![Windows Installation](https://github.com/bin456789/reinstall/assets/7548515/07c1aea2-1ce3-4967-904f-aaf9d6eec3f7) @@ -362,11 +368,12 @@ With * indicating that an ISO link is required. #### The script will install the following drivers as needed -- KVM ([Virtio](https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/), [Alibaba Cloud](https://www.alibabacloud.com/help/ecs/user-guide/update-red-hat-virtio-drivers-of-windows-instances)) +- Virtio ([Virtio](https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/), [Alibaba Cloud](https://www.alibabacloud.com/help/ecs/user-guide/update-red-hat-virtio-drivers-of-windows-instances)) - XEN ([XEN](https://xenproject.org/windows-pv-drivers/), [Citrix](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/Upgrading_PV_drivers.html#win2008-citrix-upgrade), [AWS](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/xen-drivers-overview.html)) - AWS ([ENA Network Adapter](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ena-driver-releases-windows.html), [NVMe Storage Controller](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/nvme-driver-version-history.html)) -- GCP ([gVNIC Network Adapter](https://cloud.google.com/compute/docs/networking/using-gvnic), [GGA Graphics](https://cloud.google.com/compute/docs/instances/enable-instance-virtual-display)) +- GCP ([gVNIC Network Adapter](https://cloud.google.com/compute/docs/networking/using-gvnic), [GGA Display Adapter](https://cloud.google.com/compute/docs/instances/enable-instance-virtual-display)) - Azure ([MANA Network Adapter](https://learn.microsoft.com/azure/virtual-network/accelerated-networking-mana-windows)) +- Intel ([VMD Storage Controller](https://www.intel.com/content/www/us/en/download/720755/intel-rapid-storage-technology-driver-installation-software-with-intel-optane-memory-11th-up-to-13th-gen-platforms.html)) > [!WARNING] > Vista (Server 2008) and 32-bit systems may lack drivers. @@ -383,7 +390,9 @@ With * indicating that an ISO link is required. #### ARM Considerations -Most ARM machines support ISO installation of Windows 11 24H2, but some machines may experience a black screen during installation, which does not affect the installation process. +Most ARM machines support installing Windows 11 24H2 via ISO. + +During the installation process, you might encounter a black screen, and the serial console may display `ConvertPages: failed to find range`, but neither issue affects the installation. - ✔️Azure: B2pts_v2 - ✔️Alibaba Cloud: g8y, c8y, r8y (may occasionally get stuck on the boot logo during restart; force restart to resolve) diff --git a/README.md b/README.md index 095703d..17d6c9e 100644 --- a/README.md +++ b/README.md @@ -129,7 +129,8 @@ certutil -urlcache -f -split https://jihulab.com/bin456789/reinstall/-/raw/main/ - 重装后如需修改 SSH 端口 / 改成密钥登录,还要注意修改 `/etc/ssh/sshd_config.d/` 里面的文件 - 可选参数 - `--password PASSWORD` 设置密码 - - `--ssh-port PORT` 修改 SSH 端口 + - `--ssh-port PORT` 修改 SSH 端口(目标系统 + 安装期间观察日志) + - `--web-port PORT` 修改 Web 端口(安装期间观察日志) - `--hold 2` 安装结束后不进入系统。可连接 SSH 修改系统内容,系统挂载在 `/os` (此功能不支持 Debian / Kali) ```bash @@ -196,8 +197,10 @@ bash reinstall.sh ubuntu --installer - DD Windows 镜像时,会扩展系统盘,静态 IP 的机器会配置好 IP,可能首次开机几分钟后才生效 - DD Linux 镜像时,脚本不会修改镜像的任何内容 - 可选参数 - - `--rdp-port PORT` 修改 RDP 端口 (仅限 Windows) - - `--allow-ping` 允许被 Ping (仅限 Windows) + - `--allow-ping` 允许被 Ping (仅限 DD Windows) + - `--rdp-port PORT` 修改 RDP 端口 (仅限 DD Windows) + - `--ssh-port PORT` 修改 SSH 端口(安装期间观察日志) + - `--web-port PORT` 修改 Web 端口(安装期间观察日志) - `--hold 2` DD 结束后不进入系统。可连接 SSH 修改系统内容,系统挂载在 `/os` ```bash @@ -215,6 +218,7 @@ bash reinstall.sh dd --img https://example.com/xxx.xz - 如果没有修改硬盘内容,再次重启将回到原系统 - 可选参数 - `--password PASSWORD` 设置密码 + - `--ssh-port PORT` 修改 SSH 端口 ```bash bash reinstall.sh alpine --hold=1 @@ -238,8 +242,10 @@ bash reinstall.sh netboot.xyz - 静态机器会自动配置好 IP,可能首次开机几分钟后才生效 - 可选参数 - `--password PASSWORD` 设置密码 - - `--rdp-port PORT` 更改 RDP 端口 - `--allow-ping` 允许被 Ping + - `--rdp-port PORT` 更改 RDP 端口 + - `--ssh-port PORT` 修改 SSH 端口(安装期间观察日志) + - `--web-port PORT` 修改 Web 端口(安装期间观察日志) - `--hold 2` 在重启进入 Windows 官方安装程序前,可连接 SSH 修改硬盘内容,硬盘挂载在 `/os` ![Windows 安装界面](https://github.com/bin456789/reinstall/assets/7548515/07c1aea2-1ce3-4967-904f-aaf9d6eec3f7) @@ -362,11 +368,12 @@ Windows Server 2025 SERVERDATACENTER #### 脚本会按需安装以下驱动 -- KVM ([Virtio](https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/)、[阿里云](https://www.alibabacloud.com/help/ecs/user-guide/update-red-hat-virtio-drivers-of-windows-instances)) +- Virtio ([Virtio](https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/)、[阿里云](https://www.alibabacloud.com/help/ecs/user-guide/update-red-hat-virtio-drivers-of-windows-instances)) - XEN ([XEN](https://xenproject.org/windows-pv-drivers/)、[Citrix](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/Upgrading_PV_drivers.html#win2008-citrix-upgrade)、[AWS](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/xen-drivers-overview.html)) - AWS ([ENA 网卡](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ena-driver-releases-windows.html)、[NVME 存储控制器](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/nvme-driver-version-history.html)) - GCP ([gVNIC 网卡](https://cloud.google.com/compute/docs/networking/using-gvnic)、[GGA 显卡](https://cloud.google.com/compute/docs/instances/enable-instance-virtual-display)) - Azure ([MANA 网卡](https://learn.microsoft.com/azure/virtual-network/accelerated-networking-mana-windows)) +- Intel ([VMD 存储控制器](https://www.intel.com/content/www/us/en/download/720755/intel-rapid-storage-technology-driver-installation-software-with-intel-optane-memory-11th-up-to-13th-gen-platforms.html)) > [!WARNING] > Vista (Server 2008) 和 32 位系统可能会缺少驱动 @@ -383,7 +390,9 @@ Windows Server 2025 SERVERDATACENTER #### ARM 注意事项 -大部分 ARM 机器支持 ISO 安装 Windows 11 24H2,部分机器安装过程会黑屏,不影响安装 +大部分 ARM 机器支持 ISO 安装 Windows 11 24H2 + +安装过程可能会黑屏,串行控制台可能会显示 `ConvertPages: failed to find range`,均不影响安装 - ✔️Azure B2pts_v2 - ✔️阿里云 g8y c8y r8y (有几率重启时卡开机 Logo,强制重启即可) diff --git a/reinstall.sh b/reinstall.sh index 1d6cfd8..0cd43cf 100644 --- a/reinstall.sh +++ b/reinstall.sh @@ -3186,7 +3186,7 @@ for o in ci installer debug minimal allow-ping \ passwd: password: \ ssh-port: \ rdp-port: \ - web-port: \ + web-port: http-port: \ allow-ping: \ commit: \ force: \ @@ -3259,7 +3259,7 @@ while true; do rdp_port=$2 shift 2 ;; - --web-port) + --web-port | --http-port) is_port_valid $2 || error_and_exit "Invalid $1 value: $2" web_port=$2 shift 2 diff --git a/trans.sh b/trans.sh index d356886..15331ec 100644 --- a/trans.sh +++ b/trans.sh @@ -387,22 +387,31 @@ clear_previous() { # mount /1/file2 /2 } +# virt-what 自动安装 dmidecode,因此同时缓存 cache_dmi_and_virt() { - if [ -z "$_dmi" ] || [ -z "$_virt" ]; then - # virt-what 自动安装 dmidecode + if ! [ "$_dmi_and_virt_cached" = 1 ]; then apk add virt-what # 区分 kvm 和 virtio,原因: # 1. 阿里云 c8y virt-what 不显示 kvm # 2. 不是所有 kvm 都需要 virtio 驱动,例如 aws nitro + # 3. virt-what 不会检测 virtio + _virt=$( + virt-what - # virt-what 不会检测 virtio - _virt=$(virt-what) - if [ -d /sys/bus/virtio ]; then - _virt=$({ echo "$_virt" && echo virtio; } | sort -u) - fi + # hyper-v 环境下 modprobe virtio_scsi 也会创建 /sys/bus/virtio/drivers + # 因此用 devices 判断更准确,有设备时才有 devices + # 或者加上 lspci 检测? + + # 不要用 [ -d /sys/bus/virtio/devices ] && echo virtio + # 因为非 virtio 时返回值不为 0 + if [ -d /sys/bus/virtio/devices ]; then + echo virtio + fi + ) _dmi=$(dmidecode | grep -E '(Manufacturer|Asset Tag|Vendor): ' | awk -F': ' '{print $2}') + _dmi_and_virt_cached=1 apk del virt-what fi } @@ -429,6 +438,19 @@ is_dmi_contains() { echo "$_dmi" | grep -Eiwq "$1" } +cache_lspci() { + if [ -z "$_lspci" ]; then + apk add pciutils + _lspci=$(lspci) + apk del pciutils + fi +} + +is_lspci_contains() { + cache_lspci + echo "$_lspci" | grep -Eiwq "$1" +} + get_config() { cat "/configs/$1" } @@ -3812,6 +3834,14 @@ install_windows() { fi fi + # vmd + # 改进: 像检测 virtio 那样直接从 /sys 检测设备 + # inf 有要求 19041 或以上 + if [ "$build_ver" -ge 19041 ] && [ "$arch_wim" = x86_64 ] && + is_lspci_contains 'Volume Management Device'; then + add_driver_vmd + fi + # 厂商驱动 case "$vendor" in aws) @@ -4158,6 +4188,14 @@ install_windows() { cp_drivers $drv/azure } + add_driver_vmd() { + apk add 7zip + download https://downloadmirror.intel.com/820815/SetupRST.exe $drv/SetupRST.exe + 7z x $drv/SetupRST.exe -o$drv/SetupRST -i!.text + 7z x $drv/SetupRST/.text -o$drv/vmd + cp_drivers $drv/vmd + } + # 修改应答文件 download $confhome/windows.xml /tmp/autounattend.xml locale=$(get_selected_image_prop 'Default Language')