mirror of
https://github.com/bin456789/reinstall.git
synced 2026-05-21 05:27:41 +08:00
Compare commits
6 Commits
139c342b7e
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 87301108df | |||
| 8d099f167f | |||
| 37af3fcd5f | |||
| 9e71f131db | |||
| e03ac1cdb3 | |||
| 65c3085416 |
@ -58,7 +58,7 @@ The system requirements for the target system are as follows:
|
|||||||
| <img width="16" height="16" src="https://www.centos.org/assets/icons/favicon.svg" /> CentOS Stream | 9, 10 | 512 MB \* | 5 GB |
|
| <img width="16" height="16" src="https://www.centos.org/assets/icons/favicon.svg" /> CentOS Stream | 9, 10 | 512 MB \* | 5 GB |
|
||||||
| <img width="16" height="16" src="https://fedoraproject.org/favicon.ico" /> Fedora | 43, 44 | 512 MB \* | 5 GB |
|
| <img width="16" height="16" src="https://fedoraproject.org/favicon.ico" /> Fedora | 43, 44 | 512 MB \* | 5 GB |
|
||||||
| <img width="16" height="16" src="https://www.openeuler.org/favicon.ico" /> openEuler | 20.03 LTS - 24.03 LTS | 512 MB \* | 5 GB |
|
| <img width="16" height="16" src="https://www.openeuler.org/favicon.ico" /> openEuler | 20.03 LTS - 24.03 LTS | 512 MB \* | 5 GB |
|
||||||
| <img width="16" height="16" src="https://static.opensuse.org/favicon.ico" /> openSUSE | Leap 15.6, 16.0, Tumbleweed (Rolling) | 512 MB \* | 5 GB |
|
| <img width="16" height="16" src="https://static.opensuse.org/favicon.ico" /> openSUSE | Leap 16.0, Tumbleweed (Rolling) | 512 MB \* | 5 GB |
|
||||||
| <img width="16" height="16" src="https://nixos.org/favicon.svg" /> NixOS | 25.11 | 512 MB | 5 GB |
|
| <img width="16" height="16" src="https://nixos.org/favicon.svg" /> NixOS | 25.11 | 512 MB | 5 GB |
|
||||||
| <img width="16" height="16" src="https://archlinux.org/static/favicon.png" /> Arch | Rolling | 512 MB | 5 GB |
|
| <img width="16" height="16" src="https://archlinux.org/static/favicon.png" /> Arch | Rolling | 512 MB | 5 GB |
|
||||||
| <img width="16" height="16" src="https://www.gentoo.org/assets/img/logo/gentoo-g.png" /> Gentoo | Rolling | 512 MB | 5 GB |
|
| <img width="16" height="16" src="https://www.gentoo.org/assets/img/logo/gentoo-g.png" /> Gentoo | Rolling | 512 MB | 5 GB |
|
||||||
@ -165,9 +165,9 @@ bash reinstall.sh anolis 7|8|23
|
|||||||
nixos 25.11
|
nixos 25.11
|
||||||
fedora 43|44
|
fedora 43|44
|
||||||
debian 9|10|11|12|13
|
debian 9|10|11|12|13
|
||||||
|
opensuse 16.0|tumbleweed
|
||||||
openeuler 20.03|22.03|24.03
|
openeuler 20.03|22.03|24.03
|
||||||
alpine 3.20|3.21|3.22|3.23
|
alpine 3.20|3.21|3.22|3.23
|
||||||
opensuse 15.6|16.0|tumbleweed
|
|
||||||
ubuntu 18.04|20.04|22.04|24.04|26.04 [--minimal]
|
ubuntu 18.04|20.04|22.04|24.04|26.04 [--minimal]
|
||||||
kali
|
kali
|
||||||
arch
|
arch
|
||||||
|
|||||||
@ -58,7 +58,7 @@
|
|||||||
| <img width="16" height="16" src="https://www.centos.org/assets/icons/favicon.svg" /> CentOS Stream | 9, 10 | 512 MB \* | 5 GB |
|
| <img width="16" height="16" src="https://www.centos.org/assets/icons/favicon.svg" /> CentOS Stream | 9, 10 | 512 MB \* | 5 GB |
|
||||||
| <img width="16" height="16" src="https://fedoraproject.org/favicon.ico" /> Fedora | 43, 44 | 512 MB \* | 5 GB |
|
| <img width="16" height="16" src="https://fedoraproject.org/favicon.ico" /> Fedora | 43, 44 | 512 MB \* | 5 GB |
|
||||||
| <img width="16" height="16" src="https://www.openeuler.org/favicon.ico" /> openEuler | 20.03 LTS - 24.03 LTS | 512 MB \* | 5 GB |
|
| <img width="16" height="16" src="https://www.openeuler.org/favicon.ico" /> openEuler | 20.03 LTS - 24.03 LTS | 512 MB \* | 5 GB |
|
||||||
| <img width="16" height="16" src="https://static.opensuse.org/favicon.ico" /> openSUSE | Leap 15.6, 16.0, Tumbleweed (滚动) | 512 MB \* | 5 GB |
|
| <img width="16" height="16" src="https://static.opensuse.org/favicon.ico" /> openSUSE | Leap 16.0, Tumbleweed (滚动) | 512 MB \* | 5 GB |
|
||||||
| <img width="16" height="16" src="https://nixos.org/favicon.svg" /> NixOS | 25.11 | 512 MB | 5 GB |
|
| <img width="16" height="16" src="https://nixos.org/favicon.svg" /> NixOS | 25.11 | 512 MB | 5 GB |
|
||||||
| <img width="16" height="16" src="https://archlinux.org/static/favicon.png" /> Arch | 滚动 | 512 MB | 5 GB |
|
| <img width="16" height="16" src="https://archlinux.org/static/favicon.png" /> Arch | 滚动 | 512 MB | 5 GB |
|
||||||
| <img width="16" height="16" src="https://www.gentoo.org/assets/img/logo/gentoo-g.png" /> Gentoo | 滚动 | 512 MB | 5 GB |
|
| <img width="16" height="16" src="https://www.gentoo.org/assets/img/logo/gentoo-g.png" /> Gentoo | 滚动 | 512 MB | 5 GB |
|
||||||
@ -165,9 +165,9 @@ bash reinstall.sh anolis 7|8|23
|
|||||||
nixos 25.11
|
nixos 25.11
|
||||||
fedora 43|44
|
fedora 43|44
|
||||||
debian 9|10|11|12|13
|
debian 9|10|11|12|13
|
||||||
|
opensuse 16.0|tumbleweed
|
||||||
openeuler 20.03|22.03|24.03
|
openeuler 20.03|22.03|24.03
|
||||||
alpine 3.20|3.21|3.22|3.23
|
alpine 3.20|3.21|3.22|3.23
|
||||||
opensuse 15.6|16.0|tumbleweed
|
|
||||||
ubuntu 18.04|20.04|22.04|24.04|26.04 [--minimal]
|
ubuntu 18.04|20.04|22.04|24.04|26.04 [--minimal]
|
||||||
kali
|
kali
|
||||||
arch
|
arch
|
||||||
|
|||||||
@ -170,47 +170,6 @@ GatewayOnLink=yes
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
fix_wicked_conf() {
|
|
||||||
# https://github.com/openSUSE/wicked/wiki/FAQ#q-why-wicked-does-not-set-my-default-static-route
|
|
||||||
|
|
||||||
# 修改前
|
|
||||||
# default 1.1.1.1 - -
|
|
||||||
# default 2602::1 - -
|
|
||||||
|
|
||||||
# 修改后
|
|
||||||
# 1.1.1.1 - -
|
|
||||||
# 2602::1 - -
|
|
||||||
# default 1.1.1.1 - -
|
|
||||||
# default 2602::1 - -
|
|
||||||
|
|
||||||
if ! confs=$(ls "$os_dir/etc/sysconfig/network/ifroute-"* 2>/dev/null); then
|
|
||||||
return
|
|
||||||
fi
|
|
||||||
|
|
||||||
for conf in $confs; do
|
|
||||||
# 判断 bug 是否已经修复
|
|
||||||
if grep -v 'default' "$conf" | grep -q '-'; then
|
|
||||||
return
|
|
||||||
fi
|
|
||||||
|
|
||||||
# 获取网关
|
|
||||||
gateways=$(awk '$1=="default" {print $2}' "$conf")
|
|
||||||
if [ -z "$gateways" ]; then
|
|
||||||
return
|
|
||||||
fi
|
|
||||||
|
|
||||||
# 创建新条目
|
|
||||||
for gateway in $gateways; do
|
|
||||||
echo "$gateway - -"
|
|
||||||
done | insert_into_file "$conf" head
|
|
||||||
done
|
|
||||||
|
|
||||||
# 重新应用配置
|
|
||||||
if systemctl -q is-enabled wicked; then
|
|
||||||
systemctl restart wicked
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
# ubuntu 18.04 cloud-init 版本 23.1.2,因此不用处理
|
# ubuntu 18.04 cloud-init 版本 23.1.2,因此不用处理
|
||||||
|
|
||||||
# debian 10/11 云镜像原本用 ifupdown + resolvconf,脚本改成用 netplan + networkd/resolved
|
# debian 10/11 云镜像原本用 ifupdown + resolvconf,脚本改成用 netplan + networkd/resolved
|
||||||
@ -224,6 +183,3 @@ fix_netplan_conf
|
|||||||
# 只需对云镜像处理
|
# 只需对云镜像处理
|
||||||
# 因为普通安装用的是 alpine 的 cloud-init,版本够新,不用处理
|
# 因为普通安装用的是 alpine 的 cloud-init,版本够新,不用处理
|
||||||
fix_networkd_conf
|
fix_networkd_conf
|
||||||
|
|
||||||
# opensuse 15.5: ifcfg + netconfig (dns) + wicked
|
|
||||||
fix_wicked_conf
|
|
||||||
|
|||||||
@ -9,10 +9,6 @@ Before=network.service
|
|||||||
Before=networking.service
|
Before=networking.service
|
||||||
Before=systemd-networkd.service
|
Before=systemd-networkd.service
|
||||||
Before=NetworkManager.service
|
Before=NetworkManager.service
|
||||||
Before=wickedd-auto4.service
|
|
||||||
Before=wickedd-dhcp4.service
|
|
||||||
Before=wickedd-dhcp6.service
|
|
||||||
Before=wickedd.service
|
|
||||||
|
|
||||||
Before=network.target
|
Before=network.target
|
||||||
|
|
||||||
|
|||||||
@ -86,9 +86,9 @@ Usage: $reinstall_____ anolis 7|8|23
|
|||||||
nixos 25.11
|
nixos 25.11
|
||||||
fedora 43|44
|
fedora 43|44
|
||||||
debian 9|10|11|12|13
|
debian 9|10|11|12|13
|
||||||
|
opensuse 16.0|tumbleweed
|
||||||
openeuler 20.03|22.03|24.03
|
openeuler 20.03|22.03|24.03
|
||||||
alpine 3.20|3.21|3.22|3.23
|
alpine 3.20|3.21|3.22|3.23
|
||||||
opensuse 15.6|16.0|tumbleweed
|
|
||||||
ubuntu 18.04|20.04|22.04|24.04|26.04 [--minimal]
|
ubuntu 18.04|20.04|22.04|24.04|26.04 [--minimal]
|
||||||
kali
|
kali
|
||||||
arch
|
arch
|
||||||
@ -1479,13 +1479,11 @@ Continue?
|
|||||||
# leap
|
# leap
|
||||||
dir=distribution/leap/$releasever/appliances
|
dir=distribution/leap/$releasever/appliances
|
||||||
case "$releasever" in
|
case "$releasever" in
|
||||||
15.6) file=openSUSE-Leap-$releasever-Minimal-VM.$basearch-Cloud.qcow2 ;;
|
|
||||||
16.0) file=Leap-$releasever-Minimal-VM.$basearch-Cloud.qcow2 ;;
|
16.0) file=Leap-$releasever-Minimal-VM.$basearch-Cloud.qcow2 ;;
|
||||||
# 16.0) file=Leap-$releasever-Minimal-VM.$basearch-kvm$(if [ "$basearch" = x86_64 ]; then echo '-and-xen'; fi).qcow2 ;;
|
# 16.0) file=Leap-$releasever-Minimal-VM.$basearch-kvm$(if [ "$basearch" = x86_64 ]; then echo '-and-xen'; fi).qcow2 ;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
# https://src.opensuse.org/openSUSE/Leap-Images/src/branch/leap-16.0/kiwi-templates-Minimal/Minimal.kiwi
|
# https://src.opensuse.org/openSUSE/Leap-Images/src/branch/leap-16.0/kiwi-templates-Minimal/Minimal.kiwi
|
||||||
# https://build.opensuse.org/projects/Virtualization:Appliances:Images:openSUSE-Leap-15.6/packages/kiwi-templates-Minimal/files/Minimal.kiwi
|
|
||||||
# https://build.opensuse.org/projects/Virtualization:Appliances:Images:openSUSE-Tumbleweed/packages/kiwi-templates-Minimal/files/Minimal.kiwi
|
# https://build.opensuse.org/projects/Virtualization:Appliances:Images:openSUSE-Tumbleweed/packages/kiwi-templates-Minimal/files/Minimal.kiwi
|
||||||
# 有专门的kvm镜像,openSUSE-Leap-15.5-Minimal-VM.x86_64-kvm-and-xen.qcow2,里面没有cloud-init
|
# 有专门的kvm镜像,openSUSE-Leap-15.5-Minimal-VM.x86_64-kvm-and-xen.qcow2,里面没有cloud-init
|
||||||
# file=openSUSE-Leap-15.5-Minimal-VM.x86_64-kvm-and-xen.qcow2
|
# file=openSUSE-Leap-15.5-Minimal-VM.x86_64-kvm-and-xen.qcow2
|
||||||
@ -1913,7 +1911,7 @@ verify_os_name() {
|
|||||||
'fedora 43|44' \
|
'fedora 43|44' \
|
||||||
'nixos 25.11' \
|
'nixos 25.11' \
|
||||||
'debian 9|10|11|12|13' \
|
'debian 9|10|11|12|13' \
|
||||||
'opensuse 15.6|16.0|tumbleweed' \
|
'opensuse 16.0|tumbleweed' \
|
||||||
'alpine 3.20|3.21|3.22|3.23' \
|
'alpine 3.20|3.21|3.22|3.23' \
|
||||||
'openeuler 20.03|22.03|24.03' \
|
'openeuler 20.03|22.03|24.03' \
|
||||||
'ubuntu 18.04|20.04|22.04|24.04|26.04' \
|
'ubuntu 18.04|20.04|22.04|24.04|26.04' \
|
||||||
@ -4196,7 +4194,7 @@ recreate_grub_or_extlinux_cfg() {
|
|||||||
/nix/var/nix/profiles/system/bin/switch-to-configuration boot
|
/nix/var/nix/profiles/system/bin/switch-to-configuration boot
|
||||||
# 手动启用 41_custom
|
# 手动启用 41_custom
|
||||||
nixos_grub_home="$(dirname "$(readlink -f "$(get_cmd_path grub-mkconfig)")")/.."
|
nixos_grub_home="$(dirname "$(readlink -f "$(get_cmd_path grub-mkconfig)")")/.."
|
||||||
$nixos_grub_home/etc/grub.d/41_custom >>$target_cfg
|
$nixos_grub_home/etc/grub.d/41_custom >>"$(dirname "$target_cfg")/grub.cfg"
|
||||||
elif is_have_cmd update-grub; then
|
elif is_have_cmd update-grub; then
|
||||||
update-grub
|
update-grub
|
||||||
else
|
else
|
||||||
|
|||||||
391
trans.sh
391
trans.sh
@ -1682,6 +1682,21 @@ install_nixos() {
|
|||||||
export USER=root
|
export USER=root
|
||||||
export HOME=/root
|
export HOME=/root
|
||||||
|
|
||||||
|
configure_nix_substituters() {
|
||||||
|
if ! is_in_china; then
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
|
nix_conf=/etc/nix/nix.conf
|
||||||
|
mkdir -p "$(dirname "$nix_conf")"
|
||||||
|
|
||||||
|
if [ -f "$nix_conf" ]; then
|
||||||
|
sed -i '/^[[:space:]]*substituters[[:space:]]*=/d' "$nix_conf"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "substituters = $mirror/store" >>"$nix_conf"
|
||||||
|
}
|
||||||
|
|
||||||
case "$nix_from" in
|
case "$nix_from" in
|
||||||
alpine)
|
alpine)
|
||||||
apk add nix
|
apk add nix
|
||||||
@ -1690,9 +1705,7 @@ install_nixos() {
|
|||||||
# https://gitlab.alpinelinux.org/alpine/aports/-/blob/master/community/nix/APKBUILD#L125
|
# https://gitlab.alpinelinux.org/alpine/aports/-/blob/master/community/nix/APKBUILD#L125
|
||||||
sed -i '/max-jobs/d' /etc/nix/nix.conf
|
sed -i '/max-jobs/d' /etc/nix/nix.conf
|
||||||
echo "max-jobs = $threads" >>/etc/nix/nix.conf
|
echo "max-jobs = $threads" >>/etc/nix/nix.conf
|
||||||
if is_in_china; then
|
configure_nix_substituters
|
||||||
echo "substituters = $mirror/store" >>/etc/nix/nix.conf
|
|
||||||
fi
|
|
||||||
rc-service -q nix-daemon restart
|
rc-service -q nix-daemon restart
|
||||||
# 添加 nix-env 安装的软件到 PATH
|
# 添加 nix-env 安装的软件到 PATH
|
||||||
PATH="/root/.nix-profile/bin:$PATH"
|
PATH="/root/.nix-profile/bin:$PATH"
|
||||||
@ -1743,6 +1756,7 @@ install_nixos() {
|
|||||||
apk del xz
|
apk del xz
|
||||||
# shellcheck source=/dev/null
|
# shellcheck source=/dev/null
|
||||||
. /root/.nix-profile/etc/profile.d/nix.sh
|
. /root/.nix-profile/etc/profile.d/nix.sh
|
||||||
|
configure_nix_substituters
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
@ -1783,6 +1797,7 @@ install_nixos() {
|
|||||||
|
|
||||||
if is_need_set_ssh_keys; then
|
if is_need_set_ssh_keys; then
|
||||||
nix_ssh_keys_or_PermitRootLogin="
|
nix_ssh_keys_or_PermitRootLogin="
|
||||||
|
services.openssh.settings.PasswordAuthentication = false;
|
||||||
users.users.root.openssh.authorizedKeys.keys = [
|
users.users.root.openssh.authorizedKeys.keys = [
|
||||||
$(del_comment_lines </configs/ssh_keys | del_empty_lines | quote_line | add_space 2)
|
$(del_comment_lines </configs/ssh_keys | del_empty_lines | quote_line | add_space 2)
|
||||||
];
|
];
|
||||||
@ -2029,10 +2044,10 @@ basic_init() {
|
|||||||
# 公钥/密码
|
# 公钥/密码
|
||||||
if is_need_set_ssh_keys; then
|
if is_need_set_ssh_keys; then
|
||||||
set_ssh_keys_and_del_password $os_dir
|
set_ssh_keys_and_del_password $os_dir
|
||||||
|
change_ssh_conf_for_root_key_login $os_dir
|
||||||
else
|
else
|
||||||
change_root_password $os_dir
|
change_root_password $os_dir
|
||||||
allow_root_password_login $os_dir
|
change_ssh_conf_for_root_password_login $os_dir
|
||||||
allow_password_login $os_dir
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# 下载 fix-eth-name.service
|
# 下载 fix-eth-name.service
|
||||||
@ -3752,61 +3767,11 @@ EOF
|
|||||||
# 禁用 selinux
|
# 禁用 selinux
|
||||||
disable_selinux $os_dir
|
disable_selinux $os_dir
|
||||||
|
|
||||||
# opensuse leap 15.6 用 wicked
|
|
||||||
# opensuse leap 16.0 / tumbleweed 用 NetworkManager
|
# opensuse leap 16.0 / tumbleweed 用 NetworkManager
|
||||||
if chroot $os_dir rpm -qi wicked; then
|
|
||||||
# sysconfig ifcfg
|
|
||||||
create_cloud_init_network_config $os_dir/net.cfg
|
|
||||||
chroot $os_dir cloud-init devel net-convert \
|
|
||||||
-p /net.cfg -k yaml -d out -D opensuse -O sysconfig
|
|
||||||
|
|
||||||
# 删除
|
|
||||||
# Created by cloud-init on instance boot automatically, do not edit.
|
|
||||||
#
|
|
||||||
sed -i '/^#/d' "$os_dir/out/etc/sysconfig/network/ifcfg-eth"*
|
|
||||||
|
|
||||||
for ethx in $(get_eths); do
|
|
||||||
# 1. 修复甲骨文云重启后 ipv6 丢失
|
|
||||||
# https://github.com/openSUSE/wicked/issues/1058
|
|
||||||
# 还要注意 wicked dhcpv6 获取到的 ipv6 是 /64,其他 DHCPv6 程序获取到的是 /128
|
|
||||||
echo DHCLIENT6_USE_LAST_LEASE=no >>$os_dir/out/etc/sysconfig/network/ifcfg-$ethx
|
|
||||||
|
|
||||||
# 2. 修复 onlink 网关
|
|
||||||
for prefix in '' 'default '; do
|
|
||||||
if is_staticv4; then
|
|
||||||
get_netconf_to ipv4_gateway
|
|
||||||
echo "${prefix}${ipv4_gateway} - -" >>$os_dir/out/etc/sysconfig/network/ifroute-$ethx
|
|
||||||
fi
|
|
||||||
if is_staticv6; then
|
|
||||||
get_netconf_to ipv6_gateway
|
|
||||||
echo "${prefix}${ipv6_gateway} - -" >>$os_dir/out/etc/sysconfig/network/ifroute-$ethx
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
done
|
|
||||||
|
|
||||||
# 复制配置
|
|
||||||
for file in \
|
|
||||||
"$os_dir/out/etc/sysconfig/network/ifcfg-eth"* \
|
|
||||||
"$os_dir/out/etc/sysconfig/network/ifroute-eth"*; do
|
|
||||||
# 动态 ip 没有 ifroute-eth*
|
|
||||||
if [ -f $file ]; then
|
|
||||||
cp $file $os_dir/etc/sysconfig/network/
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
# 清理
|
|
||||||
rm -rf $os_dir/net.cfg $os_dir/out
|
|
||||||
|
|
||||||
else
|
|
||||||
# 如果使用 cloud-init 则需要 touch NetworkManager.conf
|
|
||||||
# 更新到 cloud-init 24.1 后删除
|
|
||||||
# touch $os_dir/etc/NetworkManager/NetworkManager.conf
|
|
||||||
|
|
||||||
# 可以直接用 alpine 的 cloud-init 生成 Network Manager 配置
|
# 可以直接用 alpine 的 cloud-init 生成 Network Manager 配置
|
||||||
create_cloud_init_network_config /net.cfg
|
create_cloud_init_network_config /net.cfg
|
||||||
create_network_manager_config /net.cfg "$os_dir"
|
create_network_manager_config /net.cfg "$os_dir"
|
||||||
rm /net.cfg
|
rm /net.cfg
|
||||||
fi
|
|
||||||
|
|
||||||
# 选择新内核
|
# 选择新内核
|
||||||
# 只有 leap 有 kernel-azure
|
# 只有 leap 有 kernel-azure
|
||||||
@ -4082,30 +4047,50 @@ set_ssh_keys_and_del_password() {
|
|||||||
chroot $os_dir passwd -d root
|
chroot $os_dir passwd -d root
|
||||||
}
|
}
|
||||||
|
|
||||||
# 除了 alpine 都会用到
|
change_ssh_conf_if_different() {
|
||||||
change_ssh_conf() {
|
local os_dir=$1
|
||||||
os_dir=$1
|
local key=$2
|
||||||
key=$2
|
local value=$3
|
||||||
value=$3
|
local sub_conf=$4
|
||||||
sub_conf=$4
|
if [ -z "$sub_conf" ]; then
|
||||||
|
sub_conf=$(echo "01-$key.conf" | to_lower)
|
||||||
|
fi
|
||||||
|
|
||||||
if line="^$key .*" && grep -Exq "$line" $os_dir/etc/ssh/sshd_config 2>/dev/null; then
|
# 有些发行版自带了某些配置,例如
|
||||||
# 如果 sshd_config 存在此 key(非注释状态),则替换
|
# ubuntu:
|
||||||
|
# cat /etc/ssh/sshd_config.d/60-cloudimg-settings.conf | grep -i PasswordAuthentication
|
||||||
|
# PasswordAuthentication no
|
||||||
|
|
||||||
|
# gentoo:
|
||||||
|
# cat /etc/ssh/sshd_config.d/9999999gentoo-pam.conf | grep -i PasswordAuthentication
|
||||||
|
# PasswordAuthentication no
|
||||||
|
|
||||||
|
# 0. 如果已经有这个配置,则不修改,避免不必要的改动
|
||||||
|
if chroot "$os_dir" sshd -G | grep -Fxiq "$key $value"; then
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
|
if line="^$key .*" && grep -Exiq "$line" $os_dir/etc/ssh/sshd_config 2>/dev/null; then
|
||||||
|
# 1. 如果 sshd_config 存在此 key(非注释状态),则替换
|
||||||
sed -Ei "s/$line/$key $value/" $os_dir/etc/ssh/sshd_config
|
sed -Ei "s/$line/$key $value/" $os_dir/etc/ssh/sshd_config
|
||||||
elif include_line='^Include.*/etc/ssh/sshd_config.d' &&
|
elif include_line='^Include .*/etc/ssh/sshd_config.d' &&
|
||||||
|
# 2. 如果 sshd_config 设置了读取 sshd_config.d
|
||||||
|
# 则写入到 sshd_config.d/01-xxx.conf
|
||||||
|
|
||||||
# arch 没有 /etc/ssh/sshd_config.d/ 文件夹
|
# arch 没有 /etc/ssh/sshd_config.d/ 文件夹
|
||||||
# opensuse tumbleweed 没有 /etc/ssh/sshd_config
|
# opensuse tumbleweed 没有 /etc/ssh/sshd_config
|
||||||
# 有 /etc/ssh/sshd_config.d/ 文件夹
|
# 有 /etc/ssh/sshd_config.d/ 文件夹
|
||||||
# 有 /usr/etc/ssh/sshd_config
|
# 有 /usr/etc/ssh/sshd_config
|
||||||
{ grep -q "$include_line" $os_dir/etc/ssh/sshd_config ||
|
{ grep -iq "$include_line" $os_dir/etc/ssh/sshd_config ||
|
||||||
grep -q "$include_line" $os_dir/usr/etc/ssh/sshd_config; } 2>/dev/null; then
|
grep -iq "$include_line" $os_dir/usr/etc/ssh/sshd_config; } 2>/dev/null; then
|
||||||
mkdir -p $os_dir/etc/ssh/sshd_config.d/
|
mkdir -p $os_dir/etc/ssh/sshd_config.d/
|
||||||
echo "$key $value" >"$os_dir/etc/ssh/sshd_config.d/$sub_conf"
|
echo "$key $value" >"$os_dir/etc/ssh/sshd_config.d/$sub_conf"
|
||||||
else
|
else
|
||||||
|
# 3. 写入 sshd_config
|
||||||
# 如果 sshd_config 存在此 key (无论是否已注释),则替换,包括删除注释
|
# 如果 sshd_config 存在此 key (无论是否已注释),则替换,包括删除注释
|
||||||
# 否则追加
|
# 否则追加
|
||||||
line="^[# ]*$key .*"
|
line="^[# ]*$key .*"
|
||||||
if grep -Exq "$line" $os_dir/etc/ssh/sshd_config; then
|
if grep -Exiq "$line" $os_dir/etc/ssh/sshd_config; then
|
||||||
sed -Ei "s/$line/$key $value/" $os_dir/etc/ssh/sshd_config
|
sed -Ei "s/$line/$key $value/" $os_dir/etc/ssh/sshd_config
|
||||||
else
|
else
|
||||||
echo "$key $value" >>$os_dir/etc/ssh/sshd_config
|
echo "$key $value" >>$os_dir/etc/ssh/sshd_config
|
||||||
@ -4113,32 +4098,40 @@ change_ssh_conf() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
allow_password_login() {
|
change_ssh_conf_for_root_key_login() {
|
||||||
os_dir=$1
|
local os_dir=$1
|
||||||
change_ssh_conf "$os_dir" PasswordAuthentication yes 01-PasswordAuthentication.conf
|
|
||||||
|
# 目前脚本只用 root ,不需要设置这个
|
||||||
|
# change_ssh_conf_if_different "$os_dir" PasswordAuthentication no
|
||||||
|
|
||||||
|
# 这个也不需要设置,默认就是 prohibit-password
|
||||||
|
# change_ssh_conf_if_different "$os_dir" PermitRootLogin prohibit-password
|
||||||
}
|
}
|
||||||
|
|
||||||
allow_root_password_login() {
|
change_ssh_conf_for_root_password_login() {
|
||||||
os_dir=$1
|
local os_dir=$1
|
||||||
|
|
||||||
# opensuse 16/tumbleweed 安装 openssh-server-config-rootlogin
|
# opensuse 16/tumbleweed 安装 openssh-server-config-rootlogin
|
||||||
# 会生成 /usr/etc/ssh/sshd_config.d/50-permit-root-login.conf
|
# 会生成 /usr/etc/ssh/sshd_config.d/50-permit-root-login.conf
|
||||||
# 但是如果用户删除了此文件,包有更新的话,可能会重新创建这个文件?
|
# 但是如果用户删除了此文件,包有更新的话,可能会重新创建这个文件?
|
||||||
# 因此先不用这个方法
|
# 因此先不用这个方法
|
||||||
if false && [ -f $os_dir/etc/os-release ] &&
|
if false &&
|
||||||
grep -iq opensuse $os_dir/etc/os-release &&
|
[ -f $os_dir/etc/os-release ] &&
|
||||||
! grep -iq 15.6 $os_dir/etc/os-release; then
|
grep -iq opensuse $os_dir/etc/os-release; then
|
||||||
chroot $os_dir zypper install -y openssh-server-config-rootlogin
|
chroot $os_dir zypper install -y openssh-server-config-rootlogin
|
||||||
else
|
|
||||||
change_ssh_conf "$os_dir" PermitRootLogin yes 01-permitrootlogin.conf
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# PasswordAuthentication 默认是 yes
|
||||||
|
# 但某些发行版会在 sshd_config.d 里设置 PasswordAuthentication no
|
||||||
|
change_ssh_conf_if_different "$os_dir" PasswordAuthentication yes
|
||||||
|
change_ssh_conf_if_different "$os_dir" PermitRootLogin yes
|
||||||
}
|
}
|
||||||
|
|
||||||
change_ssh_port() {
|
change_ssh_port() {
|
||||||
os_dir=$1
|
local os_dir=$1
|
||||||
ssh_port=$2
|
local ssh_port=$2
|
||||||
|
|
||||||
change_ssh_conf "$os_dir" Port "$ssh_port" 01-change-ssh-port.conf
|
change_ssh_conf_if_different "$os_dir" Port "$ssh_port"
|
||||||
}
|
}
|
||||||
|
|
||||||
change_root_password() {
|
change_root_password() {
|
||||||
@ -4595,7 +4588,11 @@ install_fnos() {
|
|||||||
|
|
||||||
# ssh root 登录,测试用
|
# ssh root 登录,测试用
|
||||||
if false; then
|
if false; then
|
||||||
allow_root_password_login $os_dir
|
if is_need_set_ssh_keys; then
|
||||||
|
change_ssh_conf_for_root_key_login $os_dir
|
||||||
|
else
|
||||||
|
change_ssh_conf_for_root_password_login $os_dir
|
||||||
|
fi
|
||||||
chroot $os_dir systemctl enable ssh
|
chroot $os_dir systemctl enable ssh
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -5035,6 +5032,9 @@ EOF
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# 自带的 60-cloudimg-settings.conf 禁止了 PasswordAuthentication
|
# 自带的 60-cloudimg-settings.conf 禁止了 PasswordAuthentication
|
||||||
|
# 可删除可不删除,因为现在会先读取有效 sshd 配置再修改 sshd 配置
|
||||||
|
# 如果要删除 60-cloudimg-settings.conf 则要在 change_ssh_conf_if_different 之前删除
|
||||||
|
if false; then
|
||||||
file=$os_dir/etc/ssh/sshd_config.d/60-cloudimg-settings.conf
|
file=$os_dir/etc/ssh/sshd_config.d/60-cloudimg-settings.conf
|
||||||
if [ -f $file ]; then
|
if [ -f $file ]; then
|
||||||
sed -i '/^PasswordAuthentication/d' $file
|
sed -i '/^PasswordAuthentication/d' $file
|
||||||
@ -5042,6 +5042,7 @@ EOF
|
|||||||
rm -f $file
|
rm -f $file
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
# 更改 efi 目录的 grub.cfg 写死的 fsuuid
|
# 更改 efi 目录的 grub.cfg 写死的 fsuuid
|
||||||
# 因为 24.04 fsuuid 对应 boot 分区
|
# 因为 24.04 fsuuid 对应 boot 分区
|
||||||
@ -5680,49 +5681,58 @@ get_aws_repo() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
get_client_name_by_build_ver() {
|
|
||||||
build_ver=$1
|
|
||||||
|
|
||||||
if [ "$build_ver" -ge 22000 ]; then
|
|
||||||
echo 11
|
|
||||||
elif [ "$build_ver" -ge 10240 ]; then
|
|
||||||
echo 10
|
|
||||||
elif [ "$build_ver" -ge 9600 ]; then
|
|
||||||
echo 8.1
|
|
||||||
elif [ "$build_ver" -ge 9200 ]; then
|
|
||||||
echo 8
|
|
||||||
elif [ "$build_ver" -ge 7600 ]; then
|
|
||||||
echo 7
|
|
||||||
elif [ "$build_ver" -ge 6000 ]; then
|
|
||||||
echo vista
|
|
||||||
else
|
|
||||||
error_and_exit "Unknown Build Version: $build_ver"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
# 将 AC/SAC 版本号 转换为 LTSC 版本号
|
# 将 AC/SAC 版本号 转换为 LTSC 版本号
|
||||||
# 用于查找驱动
|
# 用于查找驱动
|
||||||
get_server_name_by_build_ver() {
|
get_windows_name_by_version() {
|
||||||
build_ver=$1
|
local nt_ver=$1
|
||||||
|
local build_ver=$2
|
||||||
|
local windows_type=$3
|
||||||
|
|
||||||
|
local windows_name
|
||||||
|
windows_name=$(
|
||||||
|
case "$windows_type" in
|
||||||
|
client)
|
||||||
|
case "$nt_ver" in
|
||||||
|
10.0)
|
||||||
|
if [ "$build_ver" -ge 22000 ]; then
|
||||||
|
echo 11
|
||||||
|
else
|
||||||
|
echo 10
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
6.3) echo 8.1 ;;
|
||||||
|
6.2) echo 8 ;;
|
||||||
|
6.1) echo 7 ;;
|
||||||
|
6.0) echo vista ;;
|
||||||
|
esac
|
||||||
|
;;
|
||||||
|
|
||||||
|
server)
|
||||||
|
case "$nt_ver" in
|
||||||
|
10.0)
|
||||||
if [ "$build_ver" -ge 26100 ]; then
|
if [ "$build_ver" -ge 26100 ]; then
|
||||||
echo 2025
|
echo 2025
|
||||||
elif [ "$build_ver" -ge 20348 ]; then
|
elif [ "$build_ver" -ge 20348 ]; then
|
||||||
echo 2022
|
echo 2022
|
||||||
elif [ "$build_ver" -ge 17763 ]; then
|
elif [ "$build_ver" -ge 17763 ]; then
|
||||||
echo 2019
|
echo 2019
|
||||||
elif [ "$build_ver" -ge 14393 ]; then
|
|
||||||
echo 2016
|
|
||||||
elif [ "$build_ver" -ge 9600 ]; then
|
|
||||||
echo 2012 r2
|
|
||||||
elif [ "$build_ver" -ge 9200 ]; then
|
|
||||||
echo 2012
|
|
||||||
elif [ "$build_ver" -ge 7600 ]; then
|
|
||||||
echo 2008 r2
|
|
||||||
elif [ "$build_ver" -ge 6001 ]; then
|
|
||||||
echo 2008
|
|
||||||
else
|
else
|
||||||
error_and_exit "Unknown Build Version: $build_ver"
|
echo 2016
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
6.3) echo '2012 r2' ;;
|
||||||
|
6.2) echo '2012' ;;
|
||||||
|
6.1) echo '2008 r2' ;;
|
||||||
|
6.0) echo '2008' ;;
|
||||||
|
esac
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
)
|
||||||
|
|
||||||
|
if [ -n "$windows_name" ]; then
|
||||||
|
echo "$windows_name"
|
||||||
|
else
|
||||||
|
error_and_exit "Unknown Windows Version: $nt_ver $build_ver $windows_type"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -5810,24 +5820,25 @@ get_windows_type_from_windows_drive() {
|
|||||||
local os_dir=$1
|
local os_dir=$1
|
||||||
|
|
||||||
apk add hivex
|
apk add hivex
|
||||||
software_hive=$(find_file_ignore_case $os_dir/Windows/System32/config/SOFTWARE)
|
|
||||||
system_hive=$(find_file_ignore_case $os_dir/Windows/System32/config/SYSTEM)
|
system_hive=$(find_file_ignore_case $os_dir/Windows/System32/config/SYSTEM)
|
||||||
installation_type=$(hivexget $software_hive '\Microsoft\Windows NT\CurrentVersion' InstallationType 2>/dev/null || true)
|
product_type=$(hivexget $system_hive '\ControlSet001\Control\ProductOptions' ProductType)
|
||||||
product_type=$(hivexget $system_hive '\ControlSet001\Control\ProductOptions' ProductType 2>/dev/null || true)
|
|
||||||
apk del hivex
|
apk del hivex
|
||||||
|
|
||||||
# 根据 win11 multi-session 的情况
|
# ProductType InstallationType 都是用来区分客户端和服务器系统
|
||||||
# InstallationType 比 ProductType 准确
|
# 就驱动而言,用的是 ProductType
|
||||||
|
# https://learn.microsoft.com/windows-hardware/drivers/install/inf-manufacturer-section
|
||||||
|
# NTamd64.10.0 # 不限制 ProductType
|
||||||
|
# NTamd64.10.0.1 # 只接受 ProductType 为 1 的系统
|
||||||
|
|
||||||
# Vista wim 和注册表都没有 InstallationType
|
# 实测也是用 ProductType
|
||||||
case "$installation_type" in
|
# 在 win11 右键 e1d.inf 安装驱动后,在任务管理器强制为任意网卡选择驱动,列表里面:
|
||||||
Client | Embedded) echo client ;;
|
# win11 enterprise 有 i218-V/i-219V,有 i218-LM/i219-LM
|
||||||
Server | 'Server Core') echo server ;;
|
# win11 multi-session 没有 i218-V/i-219V,有 i218-LM/i219-LM
|
||||||
*) case "$product_type" in
|
|
||||||
|
case "$product_type" in
|
||||||
WinNT) echo client ;;
|
WinNT) echo client ;;
|
||||||
ServerNT) echo server ;;
|
LanmanNT | ServerNT) echo server ;;
|
||||||
*) error_and_exit "Unknown Windows Type" ;;
|
*) error_and_exit "Unexpected Product Type: $product_type" ;;
|
||||||
esac ;;
|
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -5857,6 +5868,21 @@ get_intel_download_url() {
|
|||||||
grep -Eio -m1 "https://.+/$file_regex" | grep .
|
grep -Eio -m1 "https://.+/$file_regex" | grep .
|
||||||
}
|
}
|
||||||
|
|
||||||
|
apk_add_hivex_perl() {
|
||||||
|
# TODO: alpine 3.24 发布后删除
|
||||||
|
# hivex-perl 要从 edge/community 仓库下载
|
||||||
|
local alpine_mirror
|
||||||
|
alpine_mirror=$(grep '^http.*/main$' /etc/apk/repositories | sed 's,/[^/]*/main$,,' | head -1)
|
||||||
|
apk add --repository "$alpine_mirror/edge/community" \
|
||||||
|
--force-non-repository \
|
||||||
|
--virtual edge \
|
||||||
|
hivex-perl
|
||||||
|
}
|
||||||
|
|
||||||
|
apk_del_hivex_perl() {
|
||||||
|
apk del edge
|
||||||
|
}
|
||||||
|
|
||||||
install_windows() {
|
install_windows() {
|
||||||
get_wim_prop() {
|
get_wim_prop() {
|
||||||
wim=$1
|
wim=$1
|
||||||
@ -5942,14 +5968,14 @@ install_windows() {
|
|||||||
if [ "$image_count" = 1 ]; then
|
if [ "$image_count" = 1 ]; then
|
||||||
# 只有一个版本就用那个版本
|
# 只有一个版本就用那个版本
|
||||||
image_name=$all_image_names
|
image_name=$all_image_names
|
||||||
image_index=1
|
iso_image_index=1
|
||||||
else
|
else
|
||||||
while true; do
|
while true; do
|
||||||
# 匹配成功
|
# 匹配成功
|
||||||
# 改成正确的大小写
|
# 改成正确的大小写
|
||||||
if matched_image_name=$(printf '%s\n' "$all_image_names" | grep -Fix "$image_name"); then
|
if matched_image_name=$(printf '%s\n' "$all_image_names" | grep -Fix "$image_name"); then
|
||||||
image_name=$matched_image_name
|
image_name=$matched_image_name
|
||||||
image_index=$(wiminfo "$iso_install_wim" "$image_name" | grep 'Index:' | awk '{print $NF}')
|
iso_image_index=$(wiminfo "$iso_install_wim" "$image_name" | grep 'Index:' | awk '{print $NF}')
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -5970,54 +5996,35 @@ install_windows() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
get_selected_image_prop() {
|
get_selected_image_prop() {
|
||||||
get_image_prop "$iso_install_wim" "$image_index" "$1"
|
get_image_prop "$iso_install_wim" "$iso_image_index" "$1"
|
||||||
}
|
}
|
||||||
|
|
||||||
# 多会话的信息来自注册表,因为没有官方 iso
|
# Windows Server 作为域服务器时,ProductType 会变成 LanmanNT ?
|
||||||
|
|
||||||
# Installation Type:
|
|
||||||
# https://github.com/search?q=InstallationType+Client+Embedded+Server+Core&type=code
|
|
||||||
# - Client (普通 windows)
|
|
||||||
# - Server (windows server 带桌面体验)
|
|
||||||
# - Server Core (windows server 不带桌面体验)
|
|
||||||
# - Embedded (WES7 / Thin PC)
|
|
||||||
# - Client (windows 10/11 enterprise 多会话)
|
|
||||||
|
|
||||||
# Product Type:
|
|
||||||
# https://cloud.tencent.com/developer/article/2465206
|
# https://cloud.tencent.com/developer/article/2465206
|
||||||
# https://learn.microsoft.com/en-us/azure/virtual-desktop/windows-multisession-faq#why-does-my-application-report-windows-enterprise-multi-session-as-a-server-operating-system
|
# https://github.com/search?q=InstallationType+Client+Embedded+Server+Core&type=code
|
||||||
# - WinNT (普通 windows)
|
# https://learn.microsoft.com/azure/virtual-desktop/windows-multisession-faq#why-does-my-application-report-windows-enterprise-multi-session-as-a-server-operating-system
|
||||||
# - ServerNT (windows server 带桌面体验)
|
|
||||||
# - ServerNT (windows server 不带桌面体验)
|
|
||||||
# - WinNT (WES7 / Thin PC)
|
|
||||||
# - ServerNT (windows 10/11 enterprise 多会话)
|
|
||||||
|
|
||||||
# Product Suite:
|
# 信息是从注册表获取,因为某些 install.wim 可能缺少属性
|
||||||
# https://www.geoffchappell.com/studies/windows/km/ntoskrnl/api/ex/exinit/productsuite.htm
|
# Azure 上能使用 Windows 10/11 Enterprise 多会话
|
||||||
# - Terminal Server (普通 windows)
|
# HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\InstallationType
|
||||||
# - Enterprise (windows server 2025 带桌面体验)
|
# HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\ProductOptions\ProductType
|
||||||
# - Enterprise (windows server 2025 不带桌面体验)
|
# HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\ProductOptions\ProductSuite
|
||||||
# - Terminal Server (windows server 2012 R2 评估板 带桌面体验,注册表也是这个值)
|
|
||||||
# - Terminal Server (windows server 2022 R2 评估板 不带桌面体验,注册表也是这个值)
|
|
||||||
# - Terminal Server (WES7 / Thin PC)
|
|
||||||
# - ? (windows 10/11 enterprise 多会话)
|
|
||||||
|
|
||||||
# 用内核版本号筛选驱动
|
# 系统 InstallationType ProductType ProductSuite
|
||||||
# 使得可以安装 Hyper-V Server / Azure Stack HCI 等 Windows Server 变种
|
# Windows Client (普通 Windows) Client WinNT Terminal Server
|
||||||
# 7601.24214.180801-1700.win7sp1_ldr_escrow_CLIENT_ULTIMATE_x64FRE_en-us.iso wim 没有 Installation Type
|
# Windows 10/11 Enterprise 多会话 Client ServerNT Terminal Server
|
||||||
# Vista wim 和 注册表 都没有 InstallationType
|
# Windows Server 2012 R2 桌面体验 Server ServerNT Terminal Server 和 DataCenter (两行)
|
||||||
if false; then
|
# Windows Server 2012 R2 不带桌面体验 Server Core ServerNT Terminal Server 和 DataCenter (两行)
|
||||||
nt_ver=$(get_selected_image_prop "Major Version").$(get_selected_image_prop "Minor Version")
|
# Windows Server 2025 桌面体验 Server ServerNT Enterprise
|
||||||
build_ver=$(get_selected_image_prop "Build")
|
# Windows Server 2025 不带桌面体验 Server Core ServerNT Enterprise
|
||||||
installation_type=$(get_selected_image_prop "Installation Type")
|
# WES7 / Thin PC Embedded WinNT Terminal Server
|
||||||
fi
|
|
||||||
|
|
||||||
mount_iso_install_wim_to() {
|
mount_iso_install_wim_to() {
|
||||||
local dir=$1
|
local dir=$1
|
||||||
|
|
||||||
mkdir -p "$dir"
|
mkdir -p "$dir"
|
||||||
# shellcheck disable=SC2046
|
# shellcheck disable=SC2046
|
||||||
wimmount "$iso_install_wim" "$image_index" "$dir" \
|
wimmount "$iso_install_wim" "$iso_image_index" "$dir" \
|
||||||
$($is_swm && echo "--ref=$(dirname "$iso_install_wim")/$swm_ref")
|
$($is_swm && echo "--ref=$(dirname "$iso_install_wim")/$swm_ref")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -6032,13 +6039,9 @@ install_windows() {
|
|||||||
get_windows_version_from_windows_drive /wim
|
get_windows_version_from_windows_drive /wim
|
||||||
|
|
||||||
# 检测 client/server,并转换成标准版 windows 名称
|
# 检测 client/server,并转换成标准版 windows 名称
|
||||||
|
# 用于将 Hyper-V Server / Azure Stack HCI / Windows Server AC 的版本号转换成对应的 LTSC 版本号,用于查找驱动
|
||||||
windows_type=$(get_windows_type_from_windows_drive /wim)
|
windows_type=$(get_windows_type_from_windows_drive /wim)
|
||||||
product_ver=$(
|
product_ver=$(get_windows_name_by_version "$nt_ver" "$build_ver" "$windows_type")
|
||||||
case "$windows_type" in
|
|
||||||
client) get_client_name_by_build_ver "$build_ver" ;;
|
|
||||||
server) get_server_name_by_build_ver "$build_ver" ;;
|
|
||||||
esac
|
|
||||||
)
|
|
||||||
|
|
||||||
# 检测 sac 和 nvme
|
# 检测 sac 和 nvme
|
||||||
{
|
{
|
||||||
@ -6197,21 +6200,24 @@ install_windows() {
|
|||||||
)
|
)
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# $iso_image_index 是原 iso 里面的镜像 wim 编号
|
||||||
|
# $image_index 是复制到 installer 后的镜像 wim 编号
|
||||||
|
|
||||||
# 如果是 swm,要先合并成 wim 才能编辑
|
# 如果是 swm,要先合并成 wim 才能编辑
|
||||||
if $is_swm; then
|
if $is_swm; then
|
||||||
install_wim=$(echo "$install_wim" | sed 's/\.swm$/.wim/i')
|
install_wim=$(echo "$install_wim" | sed 's/\.swm$/.wim/i')
|
||||||
# 防止不格盘二次运行时报错:文件已存在
|
# 防止不格盘二次运行时报错:文件已存在
|
||||||
rm -f "$install_wim"
|
rm -f "$install_wim"
|
||||||
wimexport --ref="$(dirname "$iso_install_wim")/$swm_ref" "$iso_install_wim" "$image_index" "$install_wim"
|
wimexport --ref="$(dirname "$iso_install_wim")/$swm_ref" "$iso_install_wim" "$iso_image_index" "$install_wim"
|
||||||
# 只导出了要安装的镜像,因此 image_index 变为 1
|
# 只导出了要安装的镜像,因此 image_index 为 1
|
||||||
image_index=1
|
image_index=1
|
||||||
elif false; then
|
elif false; then
|
||||||
# 优化 install.wim
|
# 优化 install.wim
|
||||||
# 优点: 可以节省 200M~600M 空间,用来创建虚拟内存
|
# 优点: 可以节省 200M~600M 空间,用来创建虚拟内存
|
||||||
# (意义不大,因为已经删除了 boot.wim 用来创建虚拟内存,vista 除外)
|
# (意义不大,因为已经删除了 boot.wim 用来创建虚拟内存,vista 除外)
|
||||||
# 缺点: 如果 install.wim 只有一个镜像,则只能缩小 10M+
|
# 缺点: 如果 install.wim 只有一个镜像,则只能缩小 10M+
|
||||||
time wimexport --threads "$(get_build_threads 512)" "$iso_install_wim" "$image_index" "$install_wim"
|
time wimexport --threads "$(get_build_threads 512)" "$iso_install_wim" "$iso_image_index" "$install_wim"
|
||||||
# 只导出了要安装的镜像,因此 image_index 变为 1
|
# 只导出了要安装的镜像,因此 image_index 为 1
|
||||||
image_index=1
|
image_index=1
|
||||||
info "install.wim size"
|
info "install.wim size"
|
||||||
echo "Original: $(get_filesize_mb "$iso_install_wim")"
|
echo "Original: $(get_filesize_mb "$iso_install_wim")"
|
||||||
@ -6219,14 +6225,25 @@ install_windows() {
|
|||||||
echo
|
echo
|
||||||
else
|
else
|
||||||
cp "$iso_install_wim" "$install_wim"
|
cp "$iso_install_wim" "$install_wim"
|
||||||
|
image_index="$iso_image_index"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# win11 要求 1GHz 2核(1核超线程也行)
|
# win11 要求 1GHz 2核(1核超线程也行)
|
||||||
# 用注册表无法绕过
|
# 判断条件是 install.wim 元信息里的 Installation Type,而不是 install.wim 注册表里面的
|
||||||
|
# 7601.24214.180801-1700.win7sp1_ldr_escrow_CLIENT_ULTIMATE_x64FRE_en-us.iso wim 没有 Installation Type
|
||||||
|
# Vista wim 和 注册表 都没有 InstallationType
|
||||||
|
installation_type_from_install_wim_metadata=$(get_selected_image_prop "Installation Type" 2>/dev/null || true)
|
||||||
|
|
||||||
|
# 安装时无法用注册表绕过
|
||||||
# https://github.com/pbatard/rufus/issues/1990
|
# https://github.com/pbatard/rufus/issues/1990
|
||||||
# https://learn.microsoft.com/windows/iot/iot-enterprise/Hardware/System_Requirements
|
# https://learn.microsoft.com/windows/iot/iot-enterprise/Hardware/System_Requirements
|
||||||
# win11 旧版本安装程序(24h2之前)无法用 setup.exe /product server 跳过 cpu 核数限制,因此在xml里解除限制
|
# win11 旧版本安装程序(24h2之前)无法用 setup.exe /product server 跳过 cpu 核数限制,因此在xml里解除限制
|
||||||
if [ "$product_ver" = "11" ] && [ "$(nproc)" -le 1 ]; then
|
|
||||||
|
# windows 11 multi-session 用注册表的信息识别成 server 2022 用于匹配驱动,"$product_ver" 是 2022 而不是 11
|
||||||
|
# 因此这里判断的条件不是 [ "$product_ver" = "11" ]
|
||||||
|
if [ "$build_ver" -ge 22000 ] &&
|
||||||
|
[ "$(echo "$installation_type_from_install_wim_metadata" | to_lower)" = "client" ] &&
|
||||||
|
[ "$(nproc)" -le 1 ]; then
|
||||||
wiminfo "$install_wim" "$image_index" --image-property WINDOWS/INSTALLATIONTYPE=Server
|
wiminfo "$install_wim" "$image_index" --image-property WINDOWS/INSTALLATIONTYPE=Server
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -6790,10 +6807,10 @@ EOF
|
|||||||
download $baseurl/$dir/virtio-win-gt-$arch_xdd.msi $drv/virtio.msi $can_use_cn_mirror
|
download $baseurl/$dir/virtio-win-gt-$arch_xdd.msi $drv/virtio.msi $can_use_cn_mirror
|
||||||
match="FILE_*_${virtio_sys}_${arch}*"
|
match="FILE_*_${virtio_sys}_${arch}*"
|
||||||
7z x $drv/virtio.msi -o$drv/virtio -i!$match -y -bb1
|
7z x $drv/virtio.msi -o$drv/virtio -i!$match -y -bb1
|
||||||
|
|
||||||
# 为没有后缀名的文件添加后缀名
|
|
||||||
(
|
(
|
||||||
cd $drv/virtio
|
cd $drv/virtio
|
||||||
|
|
||||||
|
# 为没有后缀名的文件添加后缀名
|
||||||
echo "Recognizing file extension..."
|
echo "Recognizing file extension..."
|
||||||
for file in *"${virtio_sys}_${arch}"; do
|
for file in *"${virtio_sys}_${arch}"; do
|
||||||
recognized=false
|
recognized=false
|
||||||
@ -7052,13 +7069,7 @@ EOF
|
|||||||
to_system_hive="$(find_file_ignore_case /wim/Windows/System32/config/SYSTEM)"
|
to_system_hive="$(find_file_ignore_case /wim/Windows/System32/config/SYSTEM)"
|
||||||
to_software_hive="$(find_file_ignore_case /wim/Windows/System32/config/SOFTWARE)"
|
to_software_hive="$(find_file_ignore_case /wim/Windows/System32/config/SOFTWARE)"
|
||||||
|
|
||||||
# TODO: alpine 3.24 发布后删除
|
apk_add_hivex_perl
|
||||||
# hivex-perl 要从 edge/community 仓库下载
|
|
||||||
alpine_mirror=$(grep '^http.*/main$' /etc/apk/repositories | sed 's,/[^/]*/main$,,' | head -1)
|
|
||||||
apk add --repository "$alpine_mirror/edge/community" \
|
|
||||||
--force-non-repository \
|
|
||||||
--virtual edge \
|
|
||||||
hivex-perl
|
|
||||||
|
|
||||||
# 获取当前生效的 wvpci.inf 文件
|
# 获取当前生效的 wvpci.inf 文件
|
||||||
# 得到 wvpci.inf_amd64_86afbe8940682d27 这样的文件名
|
# 得到 wvpci.inf_amd64_86afbe8940682d27 这样的文件名
|
||||||
@ -7110,7 +7121,7 @@ EOF
|
|||||||
EOF
|
EOF
|
||||||
hivexregedit --merge "$to_system_hive" "$reg"
|
hivexregedit --merge "$to_system_hive" "$reg"
|
||||||
|
|
||||||
apk del edge
|
apk_del_hivex_perl
|
||||||
else
|
else
|
||||||
error_and_exit "vpci driver not found."
|
error_and_exit "vpci driver not found."
|
||||||
fi
|
fi
|
||||||
@ -7808,7 +7819,7 @@ mount / -o remount,size=100%
|
|||||||
sync_time || true
|
sync_time || true
|
||||||
|
|
||||||
# 安装 ssh 并更改端口
|
# 安装 ssh 并更改端口
|
||||||
apk add openssh
|
apk add openssh-server
|
||||||
if is_need_change_ssh_port; then
|
if is_need_change_ssh_port; then
|
||||||
change_ssh_port / $ssh_port
|
change_ssh_port / $ssh_port
|
||||||
fi
|
fi
|
||||||
@ -7816,6 +7827,8 @@ fi
|
|||||||
# 设置密码,添加开机启动 + 开启 ssh 服务
|
# 设置密码,添加开机启动 + 开启 ssh 服务
|
||||||
if is_need_set_ssh_keys; then
|
if is_need_set_ssh_keys; then
|
||||||
set_ssh_keys_and_del_password /
|
set_ssh_keys_and_del_password /
|
||||||
|
# 目前脚本只用 root,不需要设置这个
|
||||||
|
# change_ssh_conf_if_different / PasswordAuthentication no
|
||||||
printf '\n' | setup-sshd
|
printf '\n' | setup-sshd
|
||||||
else
|
else
|
||||||
change_root_password /
|
change_root_password /
|
||||||
|
|||||||
@ -115,6 +115,9 @@ for /f "delims=" %%a in (X:\disk.txt) do (
|
|||||||
goto :found_main_disk
|
goto :found_main_disk
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
rem 普通 for 是把“一段话”里的“每个词”排成队,让一个变量(%%b)轮流去当这些词
|
||||||
|
rem for /f 是把“一段话”拆成“几个零件”存在不同的变量里(%%i, %%j...)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user