优化代码

This commit is contained in:
bin456789 2024-03-31 00:47:13 +08:00
parent f2e1cb8b89
commit ffa7b63d93
No known key found for this signature in database
GPG Key ID: EE301B386DE6C11B
7 changed files with 42 additions and 35 deletions

View File

@ -11,7 +11,6 @@ One-click reinstallation script
## Highlights
- 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.
@ -92,7 +91,6 @@ Parameters:
### Feature 2: DD
- Supports gzip, xz formats.
- For machines with static IP, DD Windows, and the script will automatically configure the IP.
```bash
@ -102,7 +100,6 @@ bash reinstall.sh dd --img https://example.com/xxx.xz
### Feature 3: Reboot to Alpine Rescue System (Live OS)
- Can be connected via SSH to perform manual DD, modify partitions, manually install Arch / Gentoo, etc.
- If the disk content is not modified, rebooting again will return to the original system.
```bash

View File

@ -91,7 +91,6 @@ bash reinstall.sh centos 7|8|9 (8|9 为 stream 版本)
### 功能 2: DD
- 支持 gzip、xz 格式
- 静态 IP 的机器 DD Windows会自动配置好 IP
```bash
@ -101,7 +100,6 @@ bash reinstall.sh dd --img https://example.com/xxx.xz
### 功能 3: 重启到 Alpine 救援系统 (Live OS)
- 可用 ssh 连接,进行手动 DD、修改分区、手动安装 Arch / Gentoo 等操作
- 如果没有修改硬盘内容,再次重启将回到原系统
```bash

View File

@ -116,7 +116,7 @@ fix_networkd_conf() {
# Gateway=2602::1
# GatewayOnLink=yes
if ! confs=$(ls /etc/systemd/network/10-cloud-init-*.network); then
if ! confs=$(ls /etc/systemd/network/10-cloud-init-*.network 2>/dev/null); then
return
fi
@ -163,7 +163,7 @@ fix_wicked_conf() {
# default 1.1.1.1 - -
# default 2602::1 - -
if ! confs=$(ls /etc/sysconfig/network/ifroute-*); then
if ! confs=$(ls /etc/sysconfig/network/ifroute-* 2>/dev/null); then
return
fi

View File

@ -1528,25 +1528,25 @@ EOF
}
mod_initrd_alpine() {
# virt 内核添加 ipv6 模块
# hack 1 virt 内核添加 ipv6 模块
if virt_dir=$(ls -d $tmp_dir/lib/modules/*-virt 2>/dev/null); then
ipv6_dir=$virt_dir/kernel/net/ipv6
mkdir -p $ipv6_dir
modloop_file=/tmp/modloop_file
modloop_dir=/tmp/modloop_dir
curl -Lo $modloop_file $nextos_modloop
if is_in_windows; then
# cygwin 没有 unsquashfs
7z e $modloop_file ipv6.ko -r -y -o$ipv6_dir
else
install_pkg unsquashfs
mkdir_clear $modloop_dir
unsquashfs -f -d $modloop_dir $modloop_file 'modules/*/kernel/net/ipv6/ipv6.ko'
find $modloop_dir -name ipv6.ko -exec cp {} $ipv6_dir/ \;
if ! [ -f $ipv6_dir/ipv6.ko ]; then
mkdir -p $ipv6_dir
modloop_file=/tmp/modloop_file
modloop_dir=/tmp/modloop_dir
curl -Lo $modloop_file $nextos_modloop
if is_in_windows; then
# cygwin 没有 unsquashfs
7z e $modloop_file ipv6.ko -r -y -o$ipv6_dir
else
install_pkg unsquashfs
mkdir_clear $modloop_dir
unsquashfs -f -d $modloop_dir $modloop_file 'modules/*/kernel/net/ipv6/ipv6.ko'
find $modloop_dir -name ipv6.ko -exec cp {} $ipv6_dir/ \;
fi
fi
fi
# hack 1 添加 ipv6 模块
insert_into_file init after 'configure_ip\(\)' <<EOF
depmod
modprobe ipv6
@ -2056,3 +2056,8 @@ else
echo "Password: 123@@@"
echo "Reboot to start the installation."
fi
if is_in_windows; then
echo 'Run this command to reboot:'
echo 'shutdown /r /t 0'
fi

View File

@ -708,7 +708,6 @@ EOF
install_alpine() {
hack_lowram_modloop=true
hack_lowram_swap=true
mount / -o remount,size=100%
if $hack_lowram_modloop; then
# 预先加载需要的模块
@ -2871,6 +2870,9 @@ EOF
# 并调用本文件的 create_ifupdown_config 方法
: main
# 允许 ramdisk 使用所有内存,默认是 50%
mount / -o remount,size=100%
# arm要手动从硬件同步时间避免访问https出错
# do 机器第二次运行会报错
hwclock -s || true

11
ttys.sh
View File

@ -1,16 +1,14 @@
#!/bin/sh
prefix=$1
is_in_windows() {
[ "$(uname -o)" = Cygwin ] || [ "$(uname -o)" = Msys ]
}
# 不要在 windows 上使用,因为不准确
# 在原系统上使用,也可能不准确?例如安装了 cloud 内核的甲骨文?
# 最后一个 tty 是主 tty显示的信息最全
is_first=true
for tty in ttyS0 ttyAMA0 tty0; do
# hytron 有ttyS0 但无法写入
# cygwin 没有 tty0所以 windows 下 tty0 免检
if { [ "$tty" = tty0 ] && is_in_windows; } || stty -g -F "/dev/$tty" >/dev/null 2>&1; then
if stty -g -F "/dev/$tty" >/dev/null 2>&1; then
if $is_first; then
is_first=false
else
@ -19,7 +17,8 @@ for tty in ttyS0 ttyAMA0 tty0; do
printf "%s" "$prefix$tty"
if [ "$prefix" = "console=" ] && [ "$tty" = ttyS0 ]; then
if [ "$prefix" = "console=" ] &&
{ [ "$tty" = ttyS0 ] || [ "$tty" = ttyAMA0 ]; }; then
printf ",115200n8"
fi
fi

View File

@ -20,11 +20,7 @@ for %%F in ("X:\drivers\*.inf") do (
)
rem 等待加载分区
rem 没有 timeout 命令
rem 没有加载网卡驱动,无法用 ping 来等待
echo wscript.sleep(5000) > X:\sleep.vbs
cscript //nologo X:\sleep.vbs
del X:\sleep.vbs
call :sleep 5000
echo rescan | diskpart
rem 判断 efi 还是 bios
@ -110,4 +106,14 @@ rename X:\setup.exe.disabled setup.exe
rem 运行 X:\setup.exe 的话
rem vista 会找不到安装源
rem server 23h2 会无法运行
Y:\setup.exe /emsport:COM1 /emsbaudrate:115200
rem Y:\setup.exe /emsport:COM1 /emsbaudrate:115200
Y:\setup.exe
exit /b
:sleep
rem 没有 timeout 命令
rem 没有加载网卡驱动,无法用 ping 来等待
echo wscript.sleep(%~1) > X:\sleep.vbs
cscript //nologo X:\sleep.vbs
del X:\sleep.vbs
exit /b