core: 优化代码

This commit is contained in:
bin456789 2024-03-17 00:08:48 +08:00
parent ada822deb3
commit a77094937b
No known key found for this signature in database
GPG Key ID: EE301B386DE6C11B
5 changed files with 84 additions and 65 deletions

View File

@ -10,15 +10,17 @@ One-click reinstallation script
## Highlights
- By default, the official installation program is used. When the memory requirements of the installation program are not met, the official cloud image (Cloud Image) will be used.
- The script does not include third-party links or homemade packages; all resources are obtained in real-time from the source site.
- Installing using official cloud images (Cloud Image) allows bypassing the [memory requirements](https://access.redhat.com/articles/rhel-limits#minimum-required-memory-3) of traditional network installations, resulting in faster installation speed.
- Using official cloud images for installation ensures fast installation speed and can also avoid issues with netboot installation on machines with limited memory.
- Compatible with 512M + 5G small servers and supports installing Alpine on 256M small servers.
- Compatible with all network conditions, including dynamic/static IPv4/IPv6 and pure IPv4/IPv6.
- Supports installing Windows using the official ISO.
- Supports reinstalling Windows as Linux or Windows itself.
- Supports BIOS, EFI, ARM.
- The original system partition supports LVM, Btrfs.
- Supports installing Alpine, Arch, openSUSE, Gentoo, and can also install these systems from them.
- Progress of DD and cloud image installation can be viewed through SSH, browser, serial console, and web panel VNC.
- The script does not include third-party links or homemade packages; all resources are obtained in real-time from the source site.
- Includes many comments.
## Download (Current system is Linux)
@ -62,8 +64,9 @@ All features can be used on both Linux and Windows.
### Feature 1: Install Linux
- Machines with static IP installing CentOS, Alma, Rocky, Fedora, Debian, Ubuntu must include the parameter `--ci`.
- If it is uncertain whether the machine has a static or dynamic IP, you can also add the parameter `--ci` to increase the installation success rate.
- The parameter --ci indicates forced usage of the cloud image for installation.
- Machines with static IP installing CentOS, Alma, Rocky, Fedora, Ubuntu must include the parameter `--ci`.
- If it is uncertain whether the machine has a static or dynamic IP, you can also add the parameter `--ci`.
```bash
bash reinstall.sh centos 7|8|9 (8|9 for the stream version)
@ -73,9 +76,9 @@ bash reinstall.sh centos 7|8|9 (8|9 for the stream version)
debian 10|11|12
ubuntu 20.04|22.04
alpine 3.16|3.17|3.18|3.19
opensuse 15.5|tumbleweed (only supports cloud image)
arch (only supports amd64 cloud image)
gentoo (only supports amd64 cloud image)
opensuse 15.5|tumbleweed
arch (not supports ARM)
gentoo (not supports ARM)
If no version number is entered, the latest version will be installed.
```
@ -159,18 +162,23 @@ Use `Dism++` File menu > Open Image File, select the iso to be installed to get
- 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))
- Azure ([MANA Network Adapter](https://learn.microsoft.com/zh-cn/azure/virtual-network/accelerated-networking-mana-windows))
3. Vista (Server 2008) and 32-bit systems may lack drivers.
4. If the machine has a static IP, the IP will be automatically set after installation.
5. Can bypass Windows 11 hardware restrictions.
6. Supports Azure ARM (Hyper-V), does not support Oracle ARM (KVM).
7. The process `wsappx` will occupy CPU for a long time after installing the image `zh-cn_windows_10_enterprise_ltsc_2021_x64_dvd_033b7312.iso`.
4. For EFI machines without CSM enabled, Windows 7 (Server 2008 R2) cannot be installed.
5. If the machine has a static IP, the IP will be automatically set after installation.
6. Can bypass Windows 11 hardware restrictions.
7. Supports Windows 11 on ARM, exclusively for Hyper-V (Azure), not compatible with KVM (Oracle Cloud).
8. The process `wsappx` will occupy CPU for a long time after installing the image `zh-cn_windows_10_enterprise_ltsc_2021_x64_dvd_033b7312.iso`.
This is an issue with the image, and the solution is to install the `VCLibs` library.
<https://www.google.com/search?q=ltsc+wsappx>
8. The following website provides iso links.
9. The following website provides iso links.
<https://massgrave.dev/genuine-installation-media.html>
<https://massgrave.dev/genuine-installation-media.html> (Recommended, iso sourced from official channels, updated monthly, includes the latest patches)
<https://www.microsoft.com/software-download/windows10> (Need to open it with a mobile User-Agent)
<https://www.microsoft.com/software-download/windows11>
## Memory Requirements
@ -186,14 +194,6 @@ Use `Dism++` File menu > Open Image File, select the iso to be installed to get
| Windows 8.1 (Server 2012 R2) or below | 512M | - |
| Windows 10 (Server 2016) or above | 1G | - |
## Network Requirements
Install Linux using the `Install Mode` requires the machine to be able to automatically obtain an IP address.
Other cases support static IP, IPv6 (including installing Alpine, Linux cloud image, Windows iso, dd).
No need to fill in the static IP address when running the script.
## Virtualization Requirements
Not supported on OpenVZ, LXC virtual machines.
@ -233,10 +233,6 @@ You can try the following methods:
<https://raw.githubusercontent.com/bin456789/reinstall/main/reinstall.sh>
## TODO
- Install mode: Static IP, IPv6, multiple NICs
## Thanks
Thanks to the following businesses for providing free servers.

View File

@ -10,15 +10,16 @@
## 亮点
- 默认使用官方安装程序,不满足安装程序内存要求时,将使用官方云镜像 (Cloud Image)
- 不含第三方链接和自制包,所有资源均实时从源站点获得
- 适配 512M + 5G 小鸡,并支持 256M 小鸡安装 Alpine
- 使用官方云镜像 (Cloud Image) 安装,可绕过传统网络安装的 [内存要求](https://access.redhat.com/articles/rhel-limits#minimum-required-memory-3),且安装速度更快
- 支持 512M + 5G 小鸡,也支持 256M 小鸡安装 Alpine
- 支持所有网络情况,包括动静态 IPv4/IPv6纯 IPv4/IPv6
- 支持用官方 iso 安装 Windows
- 支持 Windows 重装成 Linux重装 Windows
- 支持 Windows 重装成 Linux支持重装 Windows
- 支持 BIOS、EFI、ARM
- 原系统分区支持 LVM、Btrfs
- 支持安装 Alpine、Arch、openSUSE、Gentoo也可从这些系统安装
- 可通过 SSH、浏览器、串行控制台、后台 VNC 查看 DD、云镜像安装进度
- 不含第三方链接和自制包,所有资源均实时从源站点获得
- 有很多注释
## 下载(当前系统是 Linux
@ -62,8 +63,9 @@ certutil -urlcache -f -split https://raw.gitmirror.com/bin456789/reinstall/main/
### 功能 1: 安装 Linux
- 静态 IP 的机器安装 CentOS、Alma、Rocky、Fedora、Debian、Ubuntu必须添加参数 `--ci`
- 如果不清楚机器是静态 IP 还是动态 IP也可添加参数 `--ci`,增加安装成功率
- 参数 `--ci` 表示强制使用云镜像安装
- 静态 IP 的机器安装 CentOS、Alma、Rocky、Fedora、Ubuntu必须使用 `--ci` 参数
- 如果不清楚机器是静态 IP 还是动态 IP也可使用 `--ci`
```bash
bash reinstall.sh centos 7|8|9 (8|9 为 stream 版本)
@ -73,9 +75,9 @@ bash reinstall.sh centos 7|8|9 (8|9 为 stream 版本)
debian 10|11|12
ubuntu 20.04|22.04
alpine 3.16|3.17|3.18|3.19
opensuse 15.5|tumbleweed (只支持云镜像)
arch (只支持 amd64 云镜像)
gentoo (只支持 amd64 云镜像)
opensuse 15.5|tumbleweed
arch (暂不支持 ARM)
gentoo (暂不支持 ARM)
不输入版本号,则安装最新版
```
@ -159,18 +161,23 @@ Windows Server 2022 SERVERDATACENTER
- 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/zh-cn/azure/virtual-network/accelerated-networking-mana-windows))
3. Vista (Server 2008) 和 32 位系统可能会缺少驱动
4. 静态 IP 的机器,安装后会自动配置好 IP
5. 可绕过 Windows 11 硬件限制
6. 支持 Azure ARM (Hyper-V),不支持甲骨文 ARM (KVM)
7. `zh-cn_windows_10_enterprise_ltsc_2021_x64_dvd_033b7312.iso` 此镜像安装后 `wsappx` 进程会长期占用 CPU
4. 未开启 CSM 的 EFI 机器,无法安装 Windows 7 (Server 2008 R2)
5. 静态 IP 的机器,安装后会自动配置好 IP
6. 可绕过 Windows 11 硬件限制
7. 支持 Windows 11 on ARM仅限 Hyper-V (Azure) ,不支持 KVM (甲骨文云)
8. `zh-cn_windows_10_enterprise_ltsc_2021_x64_dvd_033b7312.iso` 此镜像安装后 `wsappx` 进程会长期占用 CPU
这是镜像的问题,解决方法是安装 `VCLibs`
<https://www.google.com/search?q=ltsc+wsappx>
8. 以下网站可找到 iso 链接
9. 以下网站可找到 iso 链接
<https://massgrave.dev/genuine-installation-media.html>
<https://massgrave.dev/genuine-installation-media.html> (推荐iso 来自官方,每月更新,包含最新补丁)
<https://www.microsoft.com/software-download/windows10> (需用手机 User-Agent 打开)
<https://www.microsoft.com/software-download/windows11>
## 内存要求
@ -186,14 +193,6 @@ Windows Server 2022 SERVERDATACENTER
| Windows 8.1 (Server 2012 R2) 或以下 | 512M | - |
| Windows 10 (Server 2016) 或以上 | 1G | - |
## 网络要求
用`安装模式`安装 Linux 要求能自动获取 IP 地址
其他情况支持静态 IP、IPv6包括安装 Alpine、Linux 云镜像、Windows iso、dd
运行脚本时不需要填写静态 IP 地址
## 虚拟化要求
不支持 OpenVZ、LXC 虚拟机
@ -233,10 +232,6 @@ Windows Server 2022 SERVERDATACENTER
<https://raw.githubusercontent.com/bin456789/reinstall/main/reinstall.sh>
## TODO
- 安装模式:静态 IP、IPv6、多网卡
## 感谢
感谢以下商家提供白嫖机器

View File

@ -77,10 +77,11 @@ curl() {
else
ret=$?
if [ $ret -eq 22 ]; then
# 404 错误
# 403 404 错误
return $ret
fi
fi
sleep 1
done
}
@ -209,12 +210,23 @@ test_url_real() {
# 用 dd 限制下载 1M
# 并过滤 curl 23 错误dd限制了空间
# 也可用 ulimit -f 但好像 cygwin 不支持
curl -Lr 0-1048575 "$url" \
1> >(dd bs=1M count=1 of=$tmp_file iflag=fullblock 2>/dev/null) \
2> >(grep -v 'curl: (23)' >&2) ||
if [ ! $? -eq 23 ]; then
failed "$url not accessible"
echo $url
for i in $(seq 5 -1 0); do
if command curl --insecure --connect-timeout 10 -Lfr 0-1048575 "$url" \
1> >(dd bs=1M count=1 of=$tmp_file iflag=fullblock 2>/dev/null) \
2> >(grep -v 'curl: (23)' >&2); then
break
else
ret=$?
msg="$url not accessible"
case $ret in
22) failed "$msg" ;; # 403 404
23) break ;; # 限制了空间
*) [ $i -eq 0 ] && failed "$msg" ;; # 其他错误
esac
sleep 1
fi
done
if [ -n "$expect_type" ]; then
# gzip的mime有很多种写法
@ -388,7 +400,6 @@ setos() {
[ "$releasever" -eq 10 ] && [ "$basearch_alt" = amd64 ] && flavour=
# shellcheck disable=SC2034
kernel=linux-image$flavour-$basearch_alt
fi
}
@ -459,7 +470,8 @@ setos() {
if is_in_china; then
ci_mirror=https://mirrors.tuna.tsinghua.edu.cn/gentoo
else
ci_mirror=https://mirror.leaseweb.com/gentoo
# ci_mirror=https://mirror.leaseweb.com/gentoo # 不支持 ipv6
ci_mirror=https://distfiles.gentoo.org
fi
if [ "$basearch_alt" = arm64 ]; then
@ -1331,7 +1343,18 @@ build_nextos_cmdline() {
nextos_cmdline="root=live:$nextos_squashfs inst.ks=$nextos_ks"
fi
nextos_cmdline+=" $(echo_tmp_ttys)"
if [ $nextos_distro = debian ]; then
if [ "$basearch" = "x86_64" ]; then
# debian 不遵循最后一个 tty 为主 tty 的规则
# 设置ttyS0,tty0,最终结果是ttyS0
:
else
# debian arm 不设置 tty 无法启动
nextos_cmdline+=" $(echo_tmp_ttys)"
fi
else
nextos_cmdline+=" $(echo_tmp_ttys)"
fi
# nextos_cmdline+=" mem=256M"
}

View File

@ -98,9 +98,13 @@ download() {
fi
fi
# stdbuf 在 coreutils 包里面
if ! is_have_cmd aria2c; then
apk add aria2 coreutils
apk add aria2
fi
# stdbuf 在 coreutils 包里面
if ! is_have_cmd stdbuf; then
apk add coreutils
fi
# 阿里云源检测 user-agent 禁止 axel/aria2 下载
@ -1274,7 +1278,7 @@ modify_windows() {
# 下载共同的子脚本
# 可能 unattend.xml 已经设置了ExtendOSPartition不过运行resize没副作用
bats="windows-resize.bat windows-set-netconf.bat"
bats="windows-set-netconf.bat windows-resize.bat"
download $confhome/windows-resize.bat $os_dir/windows-resize.bat
create_win_set_netconf_script $os_dir/windows-set-netconf.bat
@ -2534,7 +2538,7 @@ EOF
}
# 脚本入口
# debian initrd 会寻找 : main
# debian initrd 会寻找 main
# 并调用本文件的 create_ifupdown_config 方法
: main

View File

@ -20,6 +20,7 @@ rem 没有加载网卡驱动,无法用 ping 来等待
echo wscript.sleep(5000) > X:\sleep.vbs
cscript //nologo X:\sleep.vbs
del X:\sleep.vbs
echo rescan | diskpart
rem 判断 efi 还是 bios
rem 或者用 https://learn.microsoft.com/windows-hardware/manufacture/desktop/boot-to-uefi-mode-or-legacy-bios-mode