Compare commits

...

11 Commits

Author SHA1 Message Date
f22cda1f10 opensuse: 添加 16.0 2025-10-18 23:41:24 +08:00
28e10128ff nixos: nix 版本号使用目标系统里面的,以修复 nixos-install 阶段报错
fixes #451
2025-10-17 20:57:27 +08:00
974d5712f0 debian: initrd 不精简 realtek 网卡驱动 2025-10-13 20:08:40 +08:00
845fa66e03 ubuntu: 添加 25.10 2025-10-11 00:01:19 +08:00
48823b4101 windows: 添加 GCP 兼容性说明 2025-10-11 00:01:18 +08:00
d212eb793c dd: 修复了用 wmic 获取网卡 id 时,!id! 变量保留了最后的 \r 导致语句不正确
fixes #444
fixes #445
fixes #446
2025-10-08 01:32:30 +08:00
aa1fc741fa Reapply "dd: 修复镜像没有 wmic 时无法配置静态 IP"
This reverts commit 74665b65cc.
2025-10-08 00:32:18 +08:00
74665b65cc Revert "dd: 修复镜像没有 wmic 时无法配置静态 IP"
This reverts commit 6708c77c63.
2025-10-07 02:58:20 +08:00
6708c77c63 dd: 修复镜像没有 wmic 时无法配置静态 IP 2025-10-05 23:35:36 +08:00
1afc1a0022 core: 通过文件判断分区作用 2025-10-02 00:10:24 +08:00
cdf09d017f openeuler: 修复 arm 机器进入了 grub rescue 模式
openeuler arm 25.09 云镜像里面的 grubaa64.efi 是用于 mbr 分区表,$root 是 hd0,msdos1
因此要重新下载 $root 是 hd0,gpt1 的 grubaa64.efi
2025-10-01 23:55:51 +08:00
5 changed files with 305 additions and 140 deletions

View File

@ -49,14 +49,14 @@ The system requirements for the target system are as follows:
| <img width="16" height="16" src="https://www.alpinelinux.org/alpine-logo.ico" /> Alpine | 3.19, 3.20, 3.21, 3.22 | 256 MB | 1 GB | | <img width="16" height="16" src="https://www.alpinelinux.org/alpine-logo.ico" /> Alpine | 3.19, 3.20, 3.21, 3.22 | 256 MB | 1 GB |
| <img width="16" height="16" src="https://www.debian.org/favicon.ico" /> Debian | 9, 10, 11, 12, 13 | 256 MB | 1 ~ 1.5 GB ^ | | <img width="16" height="16" src="https://www.debian.org/favicon.ico" /> Debian | 9, 10, 11, 12, 13 | 256 MB | 1 ~ 1.5 GB ^ |
| <img width="16" height="16" src="https://github.com/bin456789/reinstall/assets/7548515/f74b3d5b-085f-4df3-bcc9-8a9bd80bb16d" /> Kali | Rolling | 256 MB | 1 ~ 1.5 GB ^ | | <img width="16" height="16" src="https://github.com/bin456789/reinstall/assets/7548515/f74b3d5b-085f-4df3-bcc9-8a9bd80bb16d" /> Kali | Rolling | 256 MB | 1 ~ 1.5 GB ^ |
| <img width="16" height="16" src="https://documentation.ubuntu.com/server/_static/favicon.png" /> Ubuntu | 16.04 LTS - 24.04 LTS, 25.04 | 512 MB \* | 2 GB | | <img width="16" height="16" src="https://documentation.ubuntu.com/server/_static/favicon.png" /> Ubuntu | 16.04 LTS - 24.04 LTS, 25.10 | 512 MB \* | 2 GB |
| <img width="16" height="16" src="https://img.alicdn.com/imgextra/i1/O1CN01oJnJZg1yK4RzI4Rx2_!!6000000006559-2-tps-118-118.png" /> Anolis | 7, 8, 23 | 512 MB \* | 5 GB | | <img width="16" height="16" src="https://img.alicdn.com/imgextra/i1/O1CN01oJnJZg1yK4RzI4Rx2_!!6000000006559-2-tps-118-118.png" /> Anolis | 7, 8, 23 | 512 MB \* | 5 GB |
| <img width="16" height="16" src="https://www.redhat.com/favicon.ico" /> RHEL &nbsp;<img width="16" height="16" src="https://almalinux.org/fav/favicon.ico" /> AlmaLinux &nbsp;<img width="16" height="16" src="https://rockylinux.org/favicon.png" /> Rocky &nbsp;<img width="16" height="16" src="https://www.oracle.com/asset/web/favicons/favicon-32.png" /> Oracle | 8, 9, 10 | 512 MB \* | 5 GB | | <img width="16" height="16" src="https://www.redhat.com/favicon.ico" /> RHEL &nbsp;<img width="16" height="16" src="https://almalinux.org/fav/favicon.ico" /> AlmaLinux &nbsp;<img width="16" height="16" src="https://rockylinux.org/favicon.png" /> Rocky &nbsp;<img width="16" height="16" src="https://www.oracle.com/asset/web/favicons/favicon-32.png" /> Oracle | 8, 9, 10 | 512 MB \* | 5 GB |
| <img width="16" height="16" src="https://opencloudos.org/qq.ico" /> OpenCloudOS | 8, 9, Stream 23 | 512 MB \* | 5 GB | | <img width="16" height="16" src="https://opencloudos.org/qq.ico" /> OpenCloudOS | 8, 9, Stream 23 | 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://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 | 41, 42 | 512 MB \* | 5 GB | | <img width="16" height="16" src="https://fedoraproject.org/favicon.ico" /> Fedora | 41, 42 | 512 MB \* | 5 GB |
| <img width="16" height="16" src="https://www.openeuler.org/favicon.ico" /> openEuler | 20.03 LTS - 24.03 LTS, 25.03 | 512 MB \* | 5 GB | | <img width="16" height="16" src="https://www.openeuler.org/favicon.ico" /> openEuler | 20.03 LTS - 24.03 LTS, 25.09 | 512 MB \* | 5 GB |
| <img width="16" height="16" src="https://static.opensuse.org/favicon.ico" /> openSUSE | Leap 15.6, Tumbleweed (Rolling) | 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://nixos.org/favicon.svg" /> NixOS | 25.05 | 512 MB | 5 GB | | <img width="16" height="16" src="https://nixos.org/favicon.svg" /> NixOS | 25.05 | 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 |
@ -162,10 +162,10 @@ bash reinstall.sh anolis 7|8|23
fedora 41|42 fedora 41|42
nixos 25.05 nixos 25.05
debian 9|10|11|12|13 debian 9|10|11|12|13
opensuse 15.6|tumbleweed
alpine 3.19|3.20|3.21|3.22 alpine 3.19|3.20|3.21|3.22
openeuler 20.03|22.03|24.03|25.03 opensuse 15.6|16.0|tumbleweed
ubuntu 16.04|18.04|20.04|22.04|24.04|25.04 [--minimal] openeuler 20.03|22.03|24.03|25.09
ubuntu 16.04|18.04|20.04|22.04|24.04|25.10 [--minimal]
kali kali
arch arch
gentoo gentoo
@ -497,6 +497,14 @@ Open File menu > Open Image File, select the iso to be installed to get the imag
> >
> The solution is to update the system patches or manually install the `VCLibs` library <https://www.google.com/search?q=ltsc+wsappx>. > The solution is to update the system patches or manually install the `VCLibs` library <https://www.google.com/search?q=ltsc+wsappx>.
> [!WARNING]
> When installing Windows ISOs released in `May 2022` or later on GCP, the system may repeatedly reboot during the Windows installation (PE) stage. You can resolve this issue using one of the following two methods:
>
> 1. Add the `--force-boot-mode bios` parameter. The script will install Windows in `BIOS boot + MBR partition table` mode.
> <br /> - (Optional) After installation, you can convert it to `EFI boot + GPT partition table` using the command `MBR2GPT /convert /allowFullOS`.
>
> 2. Create a custom RAW image and install it via DD.
#### Considerations for Installing Windows on ARM #### Considerations for Installing Windows on ARM
Most ARM machines support installing latest Windows 11. Most ARM machines support installing latest Windows 11.
@ -539,6 +547,21 @@ Log in to the server using Remote Desktop, open Device Manager, locate the graph
- `--ssh-key /path/to/public_key` - `--ssh-key /path/to/public_key`
- `--ssh-key C:\path\to\public_key` - `--ssh-key C:\path\to\public_key`
## How to Use an Old Version
According to the Law of Bug Conservation, fixing old bugs often introduces new ones.
If you encounter such a situation, you can try using an older version.
Go to <https://github.com/bin456789/reinstall/commits/main> and find the old versions `commit_id` on the right side.
```bash
commit_id=xxxxxxx
curl -O https://raw.githubusercontent.com/bin456789/reinstall/$commit_id/reinstall.sh || wget -O ${_##*/} $_
sed -i "/^confhome.*main$/s/main/$commit_id/" reinstall.sh
bash reinstall.sh ...
```
## How to Modify the Script for Your Own ## How to Modify the Script for Your Own
1. Fork this repository. 1. Fork this repository.

View File

@ -49,14 +49,14 @@
| <img width="16" height="16" src="https://www.alpinelinux.org/alpine-logo.ico" /> Alpine | 3.19, 3.20, 3.21, 3.22 | 256 MB | 1 GB | | <img width="16" height="16" src="https://www.alpinelinux.org/alpine-logo.ico" /> Alpine | 3.19, 3.20, 3.21, 3.22 | 256 MB | 1 GB |
| <img width="16" height="16" src="https://www.debian.org/favicon.ico" /> Debian | 9, 10, 11, 12, 13 | 256 MB | 1 ~ 1.5 GB ^ | | <img width="16" height="16" src="https://www.debian.org/favicon.ico" /> Debian | 9, 10, 11, 12, 13 | 256 MB | 1 ~ 1.5 GB ^ |
| <img width="16" height="16" src="https://github.com/bin456789/reinstall/assets/7548515/f74b3d5b-085f-4df3-bcc9-8a9bd80bb16d" /> Kali | 滚动 | 256 MB | 1 ~ 1.5 GB ^ | | <img width="16" height="16" src="https://github.com/bin456789/reinstall/assets/7548515/f74b3d5b-085f-4df3-bcc9-8a9bd80bb16d" /> Kali | 滚动 | 256 MB | 1 ~ 1.5 GB ^ |
| <img width="16" height="16" src="https://documentation.ubuntu.com/server/_static/favicon.png" /> Ubuntu | 16.04 LTS - 24.04 LTS, 25.04 | 512 MB \* | 2 GB | | <img width="16" height="16" src="https://documentation.ubuntu.com/server/_static/favicon.png" /> Ubuntu | 16.04 LTS - 24.04 LTS, 25.10 | 512 MB \* | 2 GB |
| <img width="16" height="16" src="https://img.alicdn.com/imgextra/i1/O1CN01oJnJZg1yK4RzI4Rx2_!!6000000006559-2-tps-118-118.png" /> Anolis | 7, 8, 23 | 512 MB \* | 5 GB | | <img width="16" height="16" src="https://img.alicdn.com/imgextra/i1/O1CN01oJnJZg1yK4RzI4Rx2_!!6000000006559-2-tps-118-118.png" /> Anolis | 7, 8, 23 | 512 MB \* | 5 GB |
| <img width="16" height="16" src="https://www.redhat.com/favicon.ico" /> RHEL &nbsp;<img width="16" height="16" src="https://almalinux.org/fav/favicon.ico" /> AlmaLinux &nbsp;<img width="16" height="16" src="https://rockylinux.org/favicon.png" /> Rocky &nbsp;<img width="16" height="16" src="https://www.oracle.com/asset/web/favicons/favicon-32.png" /> Oracle | 8, 9, 10 | 512 MB \* | 5 GB | | <img width="16" height="16" src="https://www.redhat.com/favicon.ico" /> RHEL &nbsp;<img width="16" height="16" src="https://almalinux.org/fav/favicon.ico" /> AlmaLinux &nbsp;<img width="16" height="16" src="https://rockylinux.org/favicon.png" /> Rocky &nbsp;<img width="16" height="16" src="https://www.oracle.com/asset/web/favicons/favicon-32.png" /> Oracle | 8, 9, 10 | 512 MB \* | 5 GB |
| <img width="16" height="16" src="https://opencloudos.org/qq.ico" /> OpenCloudOS | 8, 9, Stream 23 | 512 MB \* | 5 GB | | <img width="16" height="16" src="https://opencloudos.org/qq.ico" /> OpenCloudOS | 8, 9, Stream 23 | 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://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 | 41, 42 | 512 MB \* | 5 GB | | <img width="16" height="16" src="https://fedoraproject.org/favicon.ico" /> Fedora | 41, 42 | 512 MB \* | 5 GB |
| <img width="16" height="16" src="https://www.openeuler.org/favicon.ico" /> openEuler | 20.03 LTS - 24.03 LTS, 25.03 | 512 MB \* | 5 GB | | <img width="16" height="16" src="https://www.openeuler.org/favicon.ico" /> openEuler | 20.03 LTS - 24.03 LTS, 25.09 | 512 MB \* | 5 GB |
| <img width="16" height="16" src="https://static.opensuse.org/favicon.ico" /> openSUSE | Leap 15.6, Tumbleweed (滚动) | 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://nixos.org/favicon.svg" /> NixOS | 25.05 | 512 MB | 5 GB | | <img width="16" height="16" src="https://nixos.org/favicon.svg" /> NixOS | 25.05 | 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 |
@ -162,10 +162,10 @@ bash reinstall.sh anolis 7|8|23
fedora 41|42 fedora 41|42
nixos 25.05 nixos 25.05
debian 9|10|11|12|13 debian 9|10|11|12|13
opensuse 15.6|tumbleweed
alpine 3.19|3.20|3.21|3.22 alpine 3.19|3.20|3.21|3.22
openeuler 20.03|22.03|24.03|25.03 opensuse 15.6|16.0|tumbleweed
ubuntu 16.04|18.04|20.04|22.04|24.04|25.04 [--minimal] openeuler 20.03|22.03|24.03|25.09
ubuntu 16.04|18.04|20.04|22.04|24.04|25.10 [--minimal]
kali kali
arch arch
gentoo gentoo
@ -497,6 +497,14 @@ Windows Server 2025 SERVERDATACENTER
> >
> 解决方法是更新系统补丁,或者手动安装 `VCLibs` 库 <https://www.google.com/search?q=ltsc+wsappx> > 解决方法是更新系统补丁,或者手动安装 `VCLibs` 库 <https://www.google.com/search?q=ltsc+wsappx>
> [!WARNING]
> 在 GCP 上安装 `2022年5月` 和之后发布的 Windows ISO在引导 Windows 安装界面 (PE) 时会不断反复重启。解决方法如下,二选一
>
> 1. 添加 `--force-boot-mode bios` 参数,脚本将以 `BIOS 引导 + MBR 分区表` 方式安装 Windows
> <br /> - (可选) 安装完成后用 `MBR2GPT /convert /allowFullOS` 命令转为 `EFI 引导 + GPT 分区表`
>
> 2. 自制 RAW 镜像并通过 DD 安装
#### ARM 安装 Windows 的注意事项 #### ARM 安装 Windows 的注意事项
大部分 ARM 机器都支持安装最新版 Windows 11 大部分 ARM 机器都支持安装最新版 Windows 11
@ -539,6 +547,21 @@ Windows Server 2025 SERVERDATACENTER
- `--ssh-key /path/to/public_key` - `--ssh-key /path/to/public_key`
- `--ssh-key C:\path\to\public_key` - `--ssh-key C:\path\to\public_key`
## 如何使用旧版本
根据 Bug 守恒定律,修复旧 Bug 的同时会引入新的 Bug
如果遇到这种情况,可以尝试使用旧版本
<https://github.com/bin456789/reinstall/commits/main> 右侧找到旧版本的 `commit_id`
```bash
commit_id=xxxxxxx
curl -O https://raw.githubusercontent.com/bin456789/reinstall/$commit_id/reinstall.sh || wget -O ${_##*/} $_
sed -i "/^confhome.*main$/s/main/$commit_id/" reinstall.sh
bash reinstall.sh ...
```
## 如何修改脚本自用 ## 如何修改脚本自用
1. Fork 本仓库 1. Fork 本仓库

View File

@ -54,10 +54,10 @@ Usage: $reinstall_____ anolis 7|8|23
fedora 41|42 fedora 41|42
nixos 25.05 nixos 25.05
debian 9|10|11|12|13 debian 9|10|11|12|13
opensuse 15.6|tumbleweed
alpine 3.19|3.20|3.21|3.22 alpine 3.19|3.20|3.21|3.22
openeuler 20.03|22.03|24.03|25.03 opensuse 15.6|16.0|tumbleweed
ubuntu 16.04|18.04|20.04|22.04|24.04|25.04 [--minimal] openeuler 20.03|22.03|24.03|25.09
ubuntu 16.04|18.04|20.04|22.04|24.04|25.10 [--minimal]
kali kali
arch arch
gentoo gentoo
@ -1262,7 +1262,7 @@ Continue?
20.04) codename=focal ;; 20.04) codename=focal ;;
22.04) codename=jammy ;; 22.04) codename=jammy ;;
24.04) codename=noble ;; 24.04) codename=noble ;;
25.04) codename=plucky ;; # non-lts 25.10) codename=questing ;; # non-lts
esac esac
if is_use_cloud_image; then if is_use_cloud_image; then
@ -1436,26 +1436,17 @@ Continue?
else else
# leap # leap
dir=distribution/leap/$releasever/appliances dir=distribution/leap/$releasever/appliances
if [ "$releasever" = 15.6 ]; then case "$releasever" in
file=openSUSE-Leap-$releasever-Minimal-VM.$basearch-Cloud.qcow2 15.6) file=openSUSE-Leap-$releasever-Minimal-VM.$basearch-Cloud.qcow2 ;;
# 16.0) file=Leap-$releasever-Minimal-VM.$basearch-Cloud.qcow2 ;; # 缺少 openSUSE-repos-Leap 包,导致没有源
16.0) file=Leap-$releasever-Minimal-VM.$basearch-kvm$(if [ "$basearch" = x86_64 ]; then echo '-and-xen'; fi).qcow2 ;;
esac
# 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-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
else
# https://src.opensuse.org/openSUSE/Leap/raw/branch/16.0/Leap/Leap.kiwi
# Default 比 Base 多了以下组件
# <namedCollection name="salt_minion" />
# <package name="patterns-base-salt_minion" />
# <namedCollection name="kvm_host" />
# <package name="patterns-base-kvm_host" />
# <package name="lzop" />
# <package name="wpa_supplicant" arch="x86_64,aarch64" />
# <package name="k3s-install" />
# file=Leap.x86_64-Default.raw.xz
file=Leap.x86_64-Base.raw.xz
fi
fi fi
eval ${step}_img=$mirror/$dir/$file eval ${step}_img=$mirror/$dir/$file
} }
@ -1872,8 +1863,8 @@ verify_os_name() {
'debian 9|10|11|12|13' \ 'debian 9|10|11|12|13' \
'opensuse 15.6|16.0|tumbleweed' \ 'opensuse 15.6|16.0|tumbleweed' \
'alpine 3.19|3.20|3.21|3.22' \ 'alpine 3.19|3.20|3.21|3.22' \
'openeuler 20.03|22.03|24.03|25.03' \ 'openeuler 20.03|22.03|24.03|25.09' \
'ubuntu 16.04|18.04|20.04|22.04|24.04|25.04' \ 'ubuntu 16.04|18.04|20.04|22.04|24.04|25.10' \
'redhat' \ 'redhat' \
'kali' \ 'kali' \
'arch' \ 'arch' \
@ -2965,7 +2956,7 @@ build_extra_cmdline() {
# 会将 extra.xxx=yyy 写入新系统的 /etc/modprobe.d/local.conf # 会将 extra.xxx=yyy 写入新系统的 /etc/modprobe.d/local.conf
# https://answers.launchpad.net/ubuntu/+question/249456 # https://answers.launchpad.net/ubuntu/+question/249456
# https://salsa.debian.org/installer-team/rootskel/-/blob/master/src/lib/debian-installer-startup.d/S02module-params?ref_type=heads # https://salsa.debian.org/installer-team/rootskel/-/blob/master/src/lib/debian-installer-startup.d/S02module-params?ref_type=heads
for key in confhome hold force force_cn force_old_windows_setup cloud_image main_disk \ for key in confhome hold force_boot_mode force_cn force_old_windows_setup cloud_image main_disk \
elts deb_mirror \ elts deb_mirror \
ssh_port rdp_port web_port allow_ping; do ssh_port rdp_port web_port allow_ping; do
value=${!key} value=${!key}
@ -3663,7 +3654,7 @@ remove_useless_initrd_files() {
for item in *; do for item in *; do
case "$item" in case "$item" in
# 甲骨文 arm 用自定义镜像支持设为 mlx5 vf 网卡,且不是 azure 那样显示两个网卡 # 甲骨文 arm 用自定义镜像支持设为 mlx5 vf 网卡,且不是 azure 那样显示两个网卡
amazon | google | mellanox) ;; amazon | google | mellanox | realtek) ;;
intel) intel)
( (
cd "$item" cd "$item"
@ -3783,7 +3774,7 @@ for o in ci installer debug minimal allow-ping force-cn help \
allow-ping: \ allow-ping: \
commit: \ commit: \
frpc-conf: frpc-config: frpc-toml: \ frpc-conf: frpc-config: frpc-toml: \
force: \ force-boot-mode: \
force-old-windows-setup:; do force-old-windows-setup:; do
[ -n "$long_opts" ] && long_opts+=, [ -n "$long_opts" ] && long_opts+=,
long_opts+=$o long_opts+=$o
@ -3858,11 +3849,11 @@ while true; do
shift 2 shift 2
;; ;;
--force) --force-boot-mode)
if ! { [ "$2" = bios ] || [ "$2" = efi ]; }; then if ! { [ "$2" = bios ] || [ "$2" = efi ]; }; then
error_and_exit "Invalid $1 value: $2" error_and_exit "Invalid $1 value: $2"
fi fi
force=$2 force_boot_mode=$2
shift 2 shift 2
;; ;;
--passwd | --password) --passwd | --password)

206
trans.sh
View File

@ -248,8 +248,8 @@ update_part() {
} }
is_efi() { is_efi() {
if [ -n "$force" ]; then if [ -n "$force_boot_mode" ]; then
[ "$force" = efi ] [ "$force_boot_mode" = efi ]
else else
[ -d /sys/firmware/efi/ ] [ -d /sys/firmware/efi/ ]
fi fi
@ -442,7 +442,7 @@ EOF
} }
umount_all() { umount_all() {
dirs="/mnt /os /iso /wim /installer /nbd /nbd-boot /nbd-efi /root /nix" dirs="/mnt /os /iso /wim /installer /nbd /nbd-boot /nbd-efi /nbd-test /root /nix"
regex=$(echo "$dirs" | sed 's, ,|,g') regex=$(echo "$dirs" | sed 's, ,|,g')
if mounts=$(mount | grep -Ew "on $regex" | awk '{print $3}' | tac); then if mounts=$(mount | grep -Ew "on $regex" | awk '{print $3}' | tac); then
for mount in $mounts; do for mount in $mounts; do
@ -1613,11 +1613,36 @@ install_nixos() {
done done
fi fi
# 备用方案
# 1. 从 https://mirror.nju.edu.cn/nix-channels/nixos-25.05/nixexprs.tar.xz 获取
# https://github.com/NixOS/nixpkgs/blob/nixos-25.05/pkgs/tools/package-management/nix/default.nix
# https://github.com/NixOS/nixpkgs/blob/nixos-25.05/nixos/modules/installer/tools/nix-fallback-paths.nix
# 2. 安装最新版 nix添加 nixos channel 后获取
# nix eval -f '<nixpkgs>' --raw 'nixVersions.stable.version' --extra-experimental-features nix-command
if true; then
# nix 版本号使用目标系统里面的
download $mirror/nixos-$releasever/store-paths.xz /os/store-paths.xz
apk add xz
nix_ver=$(xz -dc </os/store-paths.xz | grep -F 'vm-test-run-nix-upgrade' |
head -1 | awk -F- '{print $7}' | grep .)
rm -f /os/store-paths.xz
if is_in_china; then
sh_mirror=https://mirror.nju.edu.cn/nix
else
sh_mirror=https://releases.nixos.org/nix
fi
sh=$sh_mirror/nix-$nix_ver/install
else
# 最新版 nix 在 nixos-install 时可能会出问题
# https://github.com/bin456789/reinstall/issues/451
if is_in_china; then if is_in_china; then
sh=https://mirror.nju.edu.cn/nix/latest/install sh=https://mirror.nju.edu.cn/nix/latest/install
else else
sh=https://nixos.org/nix/install sh=https://nixos.org/nix/install
fi fi
fi
apk add xz apk add xz
wget -O- "$sh" | sh -s -- --no-daemon --no-channel-add wget -O- "$sh" | sh -s -- --no-daemon --no-channel-add
apk del xz apk del xz
@ -1757,8 +1782,7 @@ EOF
# 设置 channel # 设置 channel
if is_in_china; then if is_in_china; then
nixos-enter --root /os -- \ nixos-enter --root /os -- \
/run/current-system/sw/bin/nix-channel \ /run/current-system/sw/bin/nix-channel --add $mirror/nixos-$releasever nixos
--add https://mirrors.cernet.edu.cn/nix-channels/nixos-$releasever nixos
fi fi
# 清理 # 清理
@ -3253,6 +3277,9 @@ disable_jeos_firstboot() {
# 服务不存在时会报错 # 服务不存在时会报错
chroot $os_dir systemctl disable "$name.service" 2>/dev/null || true chroot $os_dir systemctl disable "$name.service" 2>/dev/null || true
done done
# 可选
# chroot $os_dir zypper remove -y -u jeos-firstboot
} }
create_network_manager_config() { create_network_manager_config() {
@ -3520,7 +3547,7 @@ EOF
fi fi
# opensuse # opensuse
# 1. kernel-default-base 缺少 nvme 驱动,换成 kernel-default # 1. kernel-default-base 缺少 nvme gve mlx5 mana 驱动,换成 kernel-default
# 2. 添加微码+固件 # 2. 添加微码+固件
# https://documentation.suse.com/smart/virtualization-cloud/html/minimal-vm/index.html # https://documentation.suse.com/smart/virtualization-cloud/html/minimal-vm/index.html
if grep -q opensuse $os_dir/etc/os-release; then if grep -q opensuse $os_dir/etc/os-release; then
@ -3532,11 +3559,6 @@ EOF
disable_jeos_firstboot $os_dir disable_jeos_firstboot $os_dir
# 16.0 需要安装 openssh
if ! chroot $os_dir rpm -qi openssh-server; then
chroot $os_dir zypper install -y openssh-server
fi
# 禁用 selinux # 禁用 selinux
disable_selinux $os_dir disable_selinux $os_dir
@ -3610,23 +3632,19 @@ EOF
error_and_exit "Unexpected kernel installed: $installed_kernel" error_and_exit "Unexpected kernel installed: $installed_kernel"
fi fi
# 15.6 / tumbleweed 自带的是 kernel-default-base
# 16.0 自带的是 kernel-default
# 不能同时装 kernel-default-base 和 kernel-default # 不能同时装 kernel-default-base 和 kernel-default
# 因此需要添加 --force-resolution 自动删除 kernel-default-base
if ! [ "$installed_kernel" = "$target_kernel" ]; then if ! [ "$installed_kernel" = "$target_kernel" ]; then
chroot $os_dir zypper remove -y -u $installed_kernel
# x86 必须设置一个密码否则报错arm 没有这个问题 # x86 必须设置一个密码否则报错arm 没有这个问题
# Failed to get root password hash # Failed to get root password hash
# Failed to import /etc/uefi/certs/76B6A6A0.crt # Failed to import /etc/uefi/certs/76B6A6A0.crt
# warning: %post(kernel-default-5.14.21-150500.55.83.1.x86_64) scriptlet failed, exit status 255 # warning: %post(kernel-default-5.14.21-150500.55.83.1.x86_64) scriptlet failed, exit status 255
if grep -q '^root:[:!*]' $os_dir/etc/shadow; then if grep -q '^root:[:!*]' $os_dir/etc/shadow; then
echo "root:$(mkpasswd '')" | chroot $os_dir chpasswd -e echo "root:$(mkpasswd '')" | chroot $os_dir chpasswd -e
chroot $os_dir zypper install -y $target_kernel chroot $os_dir zypper install -y --force-resolution $target_kernel
chroot $os_dir passwd -d root chroot $os_dir passwd -d root
else else
chroot $os_dir zypper install -y $target_kernel chroot $os_dir zypper install -y --force-resolution $target_kernel
fi fi
fi fi
@ -3837,23 +3855,22 @@ change_ssh_conf() {
value=$3 value=$3
sub_conf=$4 sub_conf=$4
if line="^$key .*" && grep -Exq "$line" $os_dir/etc/ssh/sshd_config; then if line="^$key .*" && grep -Exq "$line" $os_dir/etc/ssh/sshd_config 2>/dev/null; then
# 如果 sshd_config 存在此 key非注释状态则替换 # 如果 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 { elif include_line='^Include.*/etc/ssh/sshd_config.d' &&
# 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.*/etc/ssh/sshd_config.d' $os_dir/etc/ssh/sshd_config || { grep -q "$include_line" $os_dir/etc/ssh/sshd_config ||
grep -q '^Include.*/etc/ssh/sshd_config.d/' $os_dir/usr/etc/ssh/sshd_config grep -q "$include_line" $os_dir/usr/etc/ssh/sshd_config; } 2>/dev/null; then
} 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
# 如果 sshd_config 存在此 key (无论是否已注释),则替换,包括删除注释 # 如果 sshd_config 存在此 key (无论是否已注释),则替换,包括删除注释
# 否则追加 # 否则追加
line="^#?$key .*" line="^[# ]*$key .*"
if grep -Exq "$line" $os_dir/etc/ssh/sshd_config; then if grep -Exq "$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
@ -3870,7 +3887,17 @@ allow_password_login() {
allow_root_password_login() { allow_root_password_login() {
os_dir=$1 os_dir=$1
# opensuse 16/tumbleweed 安装 openssh-server-config-rootlogin
# 会生成 /usr/etc/ssh/sshd_config.d/50-permit-root-login.conf
# 但是如果用户删除了此文件,包有更新的话,可能会重新创建这个文件?
# 因此先不用这个方法
if false && [ -f $os_dir/etc/os-release ] &&
grep -iq opensuse $os_dir/etc/os-release &&
! grep -iq 15.6 $os_dir/etc/os-release; then
chroot $os_dir zypper install -y openssh-server-config-rootlogin
else
change_ssh_conf "$os_dir" PermitRootLogin yes 01-permitrootlogin.conf change_ssh_conf "$os_dir" PermitRootLogin yes 01-permitrootlogin.conf
fi
} }
change_ssh_port() { change_ssh_port() {
@ -4447,12 +4474,36 @@ install_qcow_by_copy() {
# 安装引导 # 安装引导
if is_efi; then if is_efi; then
# 只有centos 和 oracle x86_64 镜像没有efi其他系统镜像已经从efi分区复制了文件 # 只有centos 和 oracle x86_64 镜像没有efi其他系统镜像已经从efi分区复制了文件
if [ -z "$efi_part" ]; then
remove_grub_conflict_files
# openeuler 自带 grub2-efi-ia32此时安装 grub2-efi 提示已经安装了 grub2-efi-ia32不会继续安装 grub2-efi-x64 # openeuler 自带 grub2-efi-ia32此时安装 grub2-efi 提示已经安装了 grub2-efi-ia32不会继续安装 grub2-efi-x64
# 假设极端情况qcow2 制作时,安装 grub2-efi-x64 时没有挂载 efi 分区,那么 efi 文件会在系统分区下
# 但我们复制系统分区时挂载了 /boot/efi因此 efi 文件会正确地复制到 efi 分区
# 因此无需判断 qcow2 的 efi 是否是独立分区
# rhel 镜像没有源,直接 yum install 安装可能会报错
# 因此如果已经安装了要用的包就不再运行 yum install
need_install=false
need_remove_grub_conflict_files=false
[ "$(uname -m)" = x86_64 ] && arch=x64 || arch=aa64 [ "$(uname -m)" = x86_64 ] && arch=x64 || arch=aa64
if ! chroot $os_dir rpm -qi grub2-efi-$arch; then
need_install=true
need_remove_grub_conflict_files=true
elif ! chroot $os_dir rpm -qi shim-$arch || ! chroot $os_dir rpm -qi efibootmgr; then
need_install=true
fi
if $need_install; then
if $need_remove_grub_conflict_files; then
remove_grub_conflict_files
fi
chroot_dnf install efibootmgr grub2-efi-$arch shim-$arch chroot_dnf install efibootmgr grub2-efi-$arch shim-$arch
fi fi
# openeuler arm 25.09 云镜像里面的 grubaa64.efi 是用于 mbr 分区表,$root 是 hd0,msdos1
# 因此要重新下载 $root 是 hd0,gpt1 的 grubaa64.efi
if $need_reinstall_grub_efi; then
chroot_dnf reinstall grub2-efi-$arch
fi
else else
# bios # bios
remove_grub_conflict_files remove_grub_conflict_files
@ -4799,25 +4850,76 @@ EOF
lvchange -ay "$vg" lvchange -ay "$vg"
fi fi
# TODO: 系统分区应该是最后一个分区 mount_nouuid() {
# 选择最大分区 part_fstype=
os_part=$(lsblk /dev/nbd0p* --sort SIZE -no NAME,FSTYPE | grep -E 'ext4|xfs' | tail -1 | awk '{print $1}') for arg in "$@"; do
efi_part=$(lsblk /dev/nbd0p* --sort SIZE -no NAME,PARTTYPE | grep -i "$EFI_UUID" | awk '{print $1}') case "$arg" in
# 排除前两个,再选择最大分区 /dev/*)
# almalinux9 boot 分区的类型不是规定的 uuid part_fstype=$(lsblk -no FSTYPE "$arg")
# openeuler boot 分区是 fat 格式 break
boot_part=$(lsblk /dev/nbd0p* --sort SIZE -no NAME,FSTYPE | grep -E 'ext4|xfs|fat' | awk '{print $1}' | ;;
grep -vx "$os_part" | grep -vx "$efi_part" | tail -1 | awk '{print $1}') esac
done
if $is_lvm_image; then case "$part_fstype" in
os_part="mapper/$os_part" xfs) mount -o nouuid "$@" ;;
*) mount "$@" ;;
esac
}
# 可以直接选择最后一个分区为系统分区?
# almalinux9 boot 分区的类型不是规定的 uuid
# openeuler boot 分区是 vfat 格式
# openeuler arm 25.09 是 mbr 分区表, efi boot 是同一个分区vfat 格式
info "qcow2 Partitions check"
# 检测分区表类型
partition_table_format=$(get_partition_table_format /dev/nbd0)
need_reinstall_grub_efi=false
if is_efi && [ "$partition_table_format" = "msdos" ]; then
need_reinstall_grub_efi=true
fi fi
# 通过检测文件判断是什么分区
os_part='' boot_part='' efi_part=''
mkdir -p /nbd-test
for part in $(lsblk /dev/nbd0p* --sort SIZE -no NAME,FSTYPE |
grep -E ' (ext4|xfs|fat|vfat)$' | awk '{print $1}' | tac); do
mapper_part=$part
if $is_lvm_image && [ -e /dev/mapper/$part ]; then
mapper_part=mapper/$part
fi
if mount_nouuid -o ro /dev/$mapper_part /nbd-test; then
if { ls /nbd-test/etc/os-release || ls /nbd-test/*/etc/os-release; } 2>/dev/null; then
os_part=$mapper_part
fi
# shellcheck disable=SC2010
# 当 boot 作为独立分区时vmlinuz 等文件在根目录
# 当 boot 不是独立分区时vmlinuz 等文件在 /boot 目录
if ls /nbd-test/ /nbd-test/boot/ 2>/dev/null | grep -Ei '^(vmlinuz|initrd|initramfs)'; then
boot_part=$mapper_part
fi
# mbr + efi 引导 ,分区表没有 esp guid
# 因此需要用 efi 文件判断是否 efi 分区
# efi 文件可能在 efi 目录的子目录,子目录层数不定
if find /nbd-test/ -type f -ipath '/nbd-test/EFI/*.efi' 2>/dev/null | grep .; then
efi_part=$mapper_part
fi
umount /nbd-test
fi
done
info "qcow2 Partitions" info "qcow2 Partitions"
lsblk -f /dev/nbd0 -o +PARTTYPE lsblk -f /dev/nbd0 -o +PARTTYPE
# 显示 OS/EFI/Boot 文件在哪个分区
echo "---"
echo "Table: $partition_table_format"
echo "Part OS: $os_part" echo "Part OS: $os_part"
echo "Part EFI: $efi_part" echo "Part EFI: $efi_part"
echo "Part Boot: $boot_part" echo "Part Boot: $boot_part"
echo "---"
# 分区寻找方式 # 分区寻找方式
# 系统/分区 cmdline:root fstab:efi # 系统/分区 cmdline:root fstab:efi
@ -4825,25 +4927,16 @@ EOF
# ubuntu PARTUUID LABEL=UEFI # ubuntu PARTUUID LABEL=UEFI
# 其他el/ol UUID UUID # 其他el/ol UUID UUID
# read -r os_part_uuid os_part_label < <(lsblk /dev/$os_part -no UUID,LABEL) IFS=, read -r os_part_uuid os_part_label os_part_fstype \
os_part_uuid=$(lsblk /dev/$os_part -no UUID) < <(lsblk /dev/$os_part -rno UUID,LABEL,FSTYPE | tr ' ' ,)
os_part_label=$(lsblk /dev/$os_part -no LABEL)
os_part_fstype=$(lsblk /dev/$os_part -no FSTYPE)
if [ -n "$efi_part" ]; then if [ -n "$efi_part" ]; then
efi_part_uuid=$(lsblk /dev/$efi_part -no UUID) IFS=, read -r efi_part_uuid efi_part_label \
efi_part_label=$(lsblk /dev/$efi_part -no LABEL) < <(lsblk /dev/$efi_part -rno UUID,LABEL | tr ' ' ,)
fi fi
mkdir -p /nbd /nbd-boot /nbd-efi mkdir -p /nbd /nbd-boot /nbd-efi
mount_nouuid() {
case "$os_part_fstype" in
ext4) mount "$@" ;;
xfs) mount -o nouuid "$@" ;;
esac
}
# 使用目标系统的格式化程序 # 使用目标系统的格式化程序
# centos8 如果用alpine格式化xfsgrub2-mkconfig和grub2里面都无法识别xfs分区 # centos8 如果用alpine格式化xfsgrub2-mkconfig和grub2里面都无法识别xfs分区
mount_nouuid /dev/$os_part /nbd/ mount_nouuid /dev/$os_part /nbd/
@ -4879,16 +4972,17 @@ EOF
cp -a /nbd/* /os/ cp -a /nbd/* /os/
umount /nbd/ umount /nbd/
# 复制boot分区如果有 # 复制独立的boot分区如果有
if [ -n "$boot_part" ]; then if [ -n "$boot_part" ] && ! [ "$boot_part" = "$os_part" ]; then
echo Copying boot partition... echo Copying boot partition...
mount_nouuid -o ro /dev/$boot_part /nbd-boot/ mount_nouuid -o ro /dev/$boot_part /nbd-boot/
cp -a /nbd-boot/* /os/boot/ cp -a /nbd-boot/* /os/boot/
umount /nbd-boot/ umount /nbd-boot/
fi fi
# 复制efi分区如果有 # 复制独立的efi分区如果有
if [ -n "$efi_part" ]; then # 如果 efi 和 boot 是同一个分区,则复制 boot 分区时已经复制了 efi 分区的文件
if [ -n "$efi_part" ] && ! [ "$efi_part" = "$os_part" ] && ! [ "$efi_part" = "$boot_part" ]; then
echo Copying efi partition... echo Copying efi partition...
mount -o ro /dev/$efi_part /nbd-efi/ mount -o ro /dev/$efi_part /nbd-efi/
cp -a /nbd-efi/* /os/boot/efi/ cp -a /nbd-efi/* /os/boot/efi/
@ -4912,11 +5006,11 @@ EOF
umount /os/ umount /os/
umount /installer/ umount /installer/
# 如果镜像有efi分区复制其uuid # 如果镜像有独立的efi分区包括efi+boot在同一个分区复制其uuid
# 如果有相同uuid的fat分区则无法挂载 # 如果有相同uuid的fat分区则无法挂载
# 所以要先复制efi分区断开nbd再复制uuid # 所以要先复制efi分区断开nbd再复制uuid
# 复制uuid前要取消挂载硬盘 efi 分区 # 复制uuid前要取消挂载硬盘 efi 分区
if is_efi && [ -n "$efi_part_uuid" ]; then if is_efi && [ -n "$efi_part_uuid" ] && ! [ "$efi_part" = "$os_part" ]; then
info "Copy efi partition uuid" info "Copy efi partition uuid"
apk add mtools apk add mtools
mlabel -N "$(echo $efi_part_uuid | sed 's/-//')" -i /dev/$xda*1 ::$efi_part_label mlabel -N "$(echo $efi_part_uuid | sed 's/-//')" -i /dev/$xda*1 ::$efi_part_label

View File

@ -12,56 +12,90 @@ rem set ipv6_dns2=::2
@echo off @echo off
mode con cp select=437 >nul mode con cp select=437 >nul
setlocal EnableDelayedExpansion
rem 禁用 IPv6 地址标识符的随机化,防止 IPv6 和后台面板不一致 rem 禁用 IPv6 地址标识符的随机化,防止 IPv6 和后台面板不一致
netsh interface ipv6 set global randomizeidentifiers=disabled netsh interface ipv6 set global randomizeidentifiers=disabled
rem 检查是否定义了 MAC 地址 rem 检查是否定义了 MAC 地址
if defined mac_addr ( if not defined mac_addr goto :del
for /f %%a in ('wmic nic where "MACAddress='%mac_addr%'" get InterfaceIndex ^| findstr [0-9]') do set id=%%a
rem vista 没有自带 powershell
rem win11 24h2 安装后有 wmic但是过一段时间会自动删除因此有的 dd 镜像没有 wmic
if exist "%windir%\system32\wbem\wmic.exe" (
rem wmic 换行符是 \r\r\n
rem 虽然这里用了 findstr 全字匹配 ,但是结尾还是有 \r
for /f "tokens=2 delims==" %%a in (
'wmic nic where "MACAddress='%mac_addr%'" get InterfaceIndex /format:list ^| findstr "^InterfaceIndex=[0-9][0-9]*$"'
) do set id=%%a
)
if not defined id (
for /f %%a in ('powershell -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Bypass ^
-Command "(Get-WmiObject Win32_NetworkAdapter | Where-Object { $_.MACAddress -eq '%mac_addr%' }).InterfaceIndex" ^| findstr "^[0-9][0-9]*$"'
) do set id=%%a
)
if not defined id (
for /f %%a in ('powershell -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Bypass ^
-Command "(Get-CimInstance Win32_NetworkAdapter | Where-Object { $_.MACAddress -eq '%mac_addr%' }).InterfaceIndex" ^| findstr "^[0-9][0-9]*$"'
) do set id=%%a
)
if defined id ( if defined id (
rem 配置静态 IPv4 地址和网关 rem 配置静态 IPv4 地址和网关
if defined ipv4_addr if defined ipv4_gateway ( if defined ipv4_addr if defined ipv4_gateway (
rem 如果使用了 setlocal EnableDelayedExpansion
rem netsh interface ipv4 set address !id! static %ipv4_addr% gateway=%ipv4_gateway% gwmetric=0
rem !id! 变量最后有 \r 会导致语句不正确
rem %id% 变量则没有这个问题
rem gwmetric 默认值为 1自动跃点需设为 0 rem gwmetric 默认值为 1自动跃点需设为 0
netsh interface ipv4 set address !id! static !ipv4_addr! gateway=!ipv4_gateway! gwmetric=0 netsh interface ipv4 set address %id% static %ipv4_addr% gateway=%ipv4_gateway% gwmetric=0
) )
rem 配置静态 IPv4 DNS 服务器 rem 配置静态 IPv4 DNS 服务器
for %%i in (1, 2) do ( for %%i in (1, 2) do (
if defined ipv4_dns%%i ( if defined ipv4_dns%%i (
netsh interface ipv4 add | findstr "dnsservers" netsh interface ipv4 add | findstr "dnsservers" >nul
if ErrorLevel 1 ( if ErrorLevel 1 (
rem vista rem vista
netsh interface ipv4 add dnsserver !id! !ipv4_dns%%i! %%i setlocal EnableDelayedExpansion
netsh interface ipv4 add dnsserver %id% !ipv4_dns%%i! %%i
endlocal
) else ( ) else (
rem win7 rem win7
netsh interface ipv4 add dnsservers !id! !ipv4_dns%%i! %%i no setlocal EnableDelayedExpansion
netsh interface ipv4 add dnsservers %id% !ipv4_dns%%i! %%i no
endlocal
) )
) )
) )
rem 配置 IPv6 地址和网关 rem 配置 IPv6 地址和网关
if defined ipv6_addr if defined ipv6_gateway ( if defined ipv6_addr if defined ipv6_gateway (
netsh interface ipv6 set address !id! !ipv6_addr! netsh interface ipv6 set address %id% %ipv6_addr%
netsh interface ipv6 add route prefix=::/0 !id! !ipv6_gateway! netsh interface ipv6 add route prefix=::/0 %id% %ipv6_gateway%
) )
rem 配置 IPv6 DNS 服务器 rem 配置 IPv6 DNS 服务器
for %%i in (1, 2) do ( for %%i in (1, 2) do (
if defined ipv6_dns%%i ( if defined ipv6_dns%%i (
netsh interface ipv6 add | findstr "dnsservers" netsh interface ipv6 add | findstr "dnsservers" >nul
if ErrorLevel 1 ( if ErrorLevel 1 (
rem vista rem vista
netsh interface ipv6 add dnsserver !id! !ipv6_dns%%i! %%i setlocal EnableDelayedExpansion
netsh interface ipv6 add dnsserver %id% !ipv6_dns%%i! %%i
endlocal
) else ( ) else (
rem win7 rem win7
netsh interface ipv6 add dnsservers !id! !ipv6_dns%%i! %%i no setlocal EnableDelayedExpansion
) netsh interface ipv6 add dnsservers %id% !ipv6_dns%%i! %%i no
endlocal
) )
) )
) )
) )
:del
rem 删除此脚本 rem 删除此脚本
del "%~f0" del "%~f0"