mirror of
https://github.com/bin456789/reinstall.git
synced 2025-01-19 04:49:13 +08:00
core: 不重要的优化
This commit is contained in:
parent
35221e56b7
commit
9486a37c09
29
README.en.md
29
README.en.md
@ -149,10 +149,35 @@ bash reinstall.sh centos 9
|
|||||||
> When installing other systems, can monitor the progress through various methods (SSH, HTTP 80 port, VNC in the background, serial console).
|
> When installing other systems, can monitor the progress through various methods (SSH, HTTP 80 port, VNC in the background, serial console).
|
||||||
> Even if errors occur during the installation process, you can still install Alpine via SSH.
|
> Even if errors occur during the installation process, you can still install Alpine via SSH.
|
||||||
|
|
||||||
|
<details>
|
||||||
|
|
||||||
|
<summary>Experimental Features</summary>
|
||||||
|
|
||||||
|
Install Debian using a cloud image, suitable for machines with slower CPUs
|
||||||
|
|
||||||
|
```bash
|
||||||
|
bash reinstall.sh debian --ci
|
||||||
|
```
|
||||||
|
|
||||||
|
Install CentOS, Alma, Rocky, Fedora using ISO, only supports machines with more than 2G of memory and dynamic IP
|
||||||
|
|
||||||
|
```bash
|
||||||
|
bash reinstall.sh centos --installer
|
||||||
|
```
|
||||||
|
|
||||||
|
Install Ubuntu using ISO, only supports machines with more than 1G of memory and dynamic IP
|
||||||
|
|
||||||
|
```bash
|
||||||
|
bash reinstall.sh ubuntu --installer
|
||||||
|
```
|
||||||
|
|
||||||
|
</details>
|
||||||
|
|
||||||
### Feature 2: DD
|
### Feature 2: DD
|
||||||
|
|
||||||
- Supports `raw`, `vhd`, `gzip` and `xz` formatted images
|
- Supports `raw`, `vhd` images or those compressed with `xz` or `gzip`.
|
||||||
- When using DD with a Windows image, the script will automatically expand the system partition. For static IP machines, the IP will be configured automatically, and it may take a few minutes to take effect on first boot
|
- When deploy a Windows image, the system disk will be expanded, and machines with static IPs will have their IPs configured. However, it may take a few minutes after the first boot for the configuration to take effect.
|
||||||
|
- When deploy a Linux image, the system disk **will not** be expanded, and machines with static IPs **will not** have their IPs configured.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
bash reinstall.sh dd --img https://example.com/xxx.xz
|
bash reinstall.sh dd --img https://example.com/xxx.xz
|
||||||
|
29
README.md
29
README.md
@ -149,10 +149,35 @@ bash reinstall.sh centos 9
|
|||||||
> 安装其它系统时,可通过多种方式(SSH、HTTP 80 端口、后台 VNC、串行控制台)查看安装进度。
|
> 安装其它系统时,可通过多种方式(SSH、HTTP 80 端口、后台 VNC、串行控制台)查看安装进度。
|
||||||
> 即使安装过程出错,也能通过 SSH 安装到 Alpine。
|
> 即使安装过程出错,也能通过 SSH 安装到 Alpine。
|
||||||
|
|
||||||
|
<details>
|
||||||
|
|
||||||
|
<summary>实验性功能</summary>
|
||||||
|
|
||||||
|
用云镜像安装 Debian,适合于 CPU 较慢的机器
|
||||||
|
|
||||||
|
```bash
|
||||||
|
bash reinstall.sh debian --ci
|
||||||
|
```
|
||||||
|
|
||||||
|
用 ISO 安装 CentOS, Alma, Rocky, Fedora ,仅支持内存大于 2G 且为动态 IP 的机器
|
||||||
|
|
||||||
|
```bash
|
||||||
|
bash reinstall.sh centos --installer
|
||||||
|
```
|
||||||
|
|
||||||
|
用 ISO 安装 Ubuntu ,仅支持内存大于 1G 且为动态 IP 的机器
|
||||||
|
|
||||||
|
```bash
|
||||||
|
bash reinstall.sh ubuntu --installer
|
||||||
|
```
|
||||||
|
|
||||||
|
</details>
|
||||||
|
|
||||||
### 功能 2: DD
|
### 功能 2: DD
|
||||||
|
|
||||||
- 支持 `raw`、`vhd`、`gzip`、`xz` 格式的镜像
|
- 支持 `raw` `vhd` 或者经过 `xz` `gzip` 压缩的镜像
|
||||||
- DD Windows 镜像时,会自动扩展系统盘。静态的机器会自动配置好 IP,可能首次开机几分钟后才生效
|
- DD Windows 镜像时,会扩展系统盘,静态 IP 的机器会配置好 IP,可能首次开机几分钟后才生效
|
||||||
|
- DD Linux 镜像时,**不会**扩展系统盘,静态 IP 的机器**不会**配置好 IP
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
bash reinstall.sh dd --img https://example.com/xxx.xz
|
bash reinstall.sh dd --img https://example.com/xxx.xz
|
||||||
|
@ -129,7 +129,7 @@ test_internet() {
|
|||||||
echo 'Testing Internet Connection...'
|
echo 'Testing Internet Connection...'
|
||||||
|
|
||||||
# debian 没有 nslookup,因此用 ping
|
# debian 没有 nslookup,因此用 ping
|
||||||
for i in $(seq 5); do
|
for i in $(seq 10); do
|
||||||
if is_need_test_ipv4 && ping -c1 -W5 -I "$ethx" "$ipv4_dns1" >/dev/null 2>&1; then
|
if is_need_test_ipv4 && ping -c1 -W5 -I "$ethx" "$ipv4_dns1" >/dev/null 2>&1; then
|
||||||
echo "IPv4 has internet."
|
echo "IPv4 has internet."
|
||||||
ipv4_has_internet=true
|
ipv4_has_internet=true
|
||||||
|
35
reinstall.sh
35
reinstall.sh
@ -844,6 +844,19 @@ setos() {
|
|||||||
directory=extended-lts
|
directory=extended-lts
|
||||||
initrd_mirror=archive.debian.org
|
initrd_mirror=archive.debian.org
|
||||||
fi
|
fi
|
||||||
|
if is_in_china; then
|
||||||
|
warn "
|
||||||
|
Due to the lack of Debian Freexian ELTS instaler mirrors in China, the installation time may be longer.
|
||||||
|
Continue?
|
||||||
|
|
||||||
|
由于没有 Debian Freexian ELTS 国内安装源,安装时间可能会比较长。
|
||||||
|
继续安装?
|
||||||
|
"
|
||||||
|
read -r -p '[y/N]: '
|
||||||
|
if ! [[ "$REPLY" = [Yy] ]]; then
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
if is_in_china; then
|
if is_in_china; then
|
||||||
# ftp.cn.debian.org 不在国内还严重丢包
|
# ftp.cn.debian.org 不在国内还严重丢包
|
||||||
@ -1089,7 +1102,7 @@ setos() {
|
|||||||
if [ -z "$iso" ]; then
|
if [ -z "$iso" ]; then
|
||||||
# 查找时将 windows longhorn serverdatacenter 改成 windows server 2008 serverdatacenter
|
# 查找时将 windows longhorn serverdatacenter 改成 windows server 2008 serverdatacenter
|
||||||
image_name=${image_name/windows longhorn server/windows server 2008 server}
|
image_name=${image_name/windows longhorn server/windows server 2008 server}
|
||||||
echo "iso url is not set. Try to find it."
|
echo "iso url is not set. Attempting to find it automatically."
|
||||||
find_windows_iso
|
find_windows_iso
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -1424,7 +1437,7 @@ install_pkg() {
|
|||||||
# https://github.com/chef/os_release
|
# https://github.com/chef/os_release
|
||||||
case "$id" in
|
case "$id" in
|
||||||
fedora | centos | rhel) is_have_cmd dnf && pkg_mgr=dnf || pkg_mgr=yum ;;
|
fedora | centos | rhel) is_have_cmd dnf && pkg_mgr=dnf || pkg_mgr=yum ;;
|
||||||
debian | ubuntu) pkg_mgr=apt ;;
|
debian | ubuntu) pkg_mgr=apt-get ;;
|
||||||
opensuse | suse) pkg_mgr=zypper ;;
|
opensuse | suse) pkg_mgr=zypper ;;
|
||||||
alpine) pkg_mgr=apk ;;
|
alpine) pkg_mgr=apk ;;
|
||||||
arch) pkg_mgr=pacman ;;
|
arch) pkg_mgr=pacman ;;
|
||||||
@ -1437,7 +1450,7 @@ install_pkg() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# 查找方法 2
|
# 查找方法 2
|
||||||
for mgr in dnf yum apt pacman zypper emerge apk opkg nix-env; do
|
for mgr in dnf yum apt-get pacman zypper emerge apk opkg nix-env; do
|
||||||
is_have_cmd $mgr && pkg_mgr=$mgr && return
|
is_have_cmd $mgr && pkg_mgr=$mgr && return
|
||||||
done
|
done
|
||||||
|
|
||||||
@ -1454,7 +1467,7 @@ install_pkg() {
|
|||||||
;;
|
;;
|
||||||
xz)
|
xz)
|
||||||
case "$pkg_mgr" in
|
case "$pkg_mgr" in
|
||||||
apt) pkg="xz-utils" ;;
|
apt-get) pkg="xz-utils" ;;
|
||||||
*) pkg="xz" ;;
|
*) pkg="xz" ;;
|
||||||
esac
|
esac
|
||||||
;;
|
;;
|
||||||
@ -1472,14 +1485,14 @@ install_pkg() {
|
|||||||
;;
|
;;
|
||||||
fdisk)
|
fdisk)
|
||||||
case "$pkg_mgr" in
|
case "$pkg_mgr" in
|
||||||
apt) pkg="fdisk" ;;
|
apt-get) pkg="fdisk" ;;
|
||||||
apk) pkg="util-linux-misc" ;;
|
apk) pkg="util-linux-misc" ;;
|
||||||
*) pkg="util-linux" ;;
|
*) pkg="util-linux" ;;
|
||||||
esac
|
esac
|
||||||
;;
|
;;
|
||||||
hexdump)
|
hexdump)
|
||||||
case "$pkg_mgr" in
|
case "$pkg_mgr" in
|
||||||
apt) pkg="bsdmainutils" ;;
|
apt-get) pkg="bsdmainutils" ;;
|
||||||
*) pkg="util-linux" ;;
|
*) pkg="util-linux" ;;
|
||||||
esac
|
esac
|
||||||
;;
|
;;
|
||||||
@ -1492,7 +1505,7 @@ install_pkg() {
|
|||||||
;;
|
;;
|
||||||
nslookup | dig)
|
nslookup | dig)
|
||||||
case "$pkg_mgr" in
|
case "$pkg_mgr" in
|
||||||
apt) pkg="dnsutils" ;;
|
apt-get) pkg="dnsutils" ;;
|
||||||
pacman) pkg="bind" ;;
|
pacman) pkg="bind" ;;
|
||||||
apk | emerge) pkg="bind-tools" ;;
|
apk | emerge) pkg="bind-tools" ;;
|
||||||
yum | dnf | zypper) pkg="bind-utils" ;;
|
yum | dnf | zypper) pkg="bind-utils" ;;
|
||||||
@ -1559,9 +1572,9 @@ install_pkg() {
|
|||||||
add_community_repo_for_alpine
|
add_community_repo_for_alpine
|
||||||
apk add $pkg
|
apk add $pkg
|
||||||
;;
|
;;
|
||||||
apt)
|
apt-get)
|
||||||
[ -z "$apt_updated" ] && apt update && apt_updated=1
|
[ -z "$apt_updated" ] && apt-get update && apt_updated=1
|
||||||
DEBIAN_FRONTEND=noninteractive apt install -y $pkg
|
DEBIAN_FRONTEND=noninteractive apt-get install -y $pkg
|
||||||
;;
|
;;
|
||||||
opkg)
|
opkg)
|
||||||
[ -z "$opkg_updated" ] && opkg update && opkg_updated=1
|
[ -z "$opkg_updated" ] && opkg update && opkg_updated=1
|
||||||
@ -1605,7 +1618,7 @@ install_pkg() {
|
|||||||
cmd_to_pkg
|
cmd_to_pkg
|
||||||
install_pkg_real
|
install_pkg_real
|
||||||
fi
|
fi
|
||||||
done
|
done >&2
|
||||||
}
|
}
|
||||||
|
|
||||||
check_ram() {
|
check_ram() {
|
||||||
|
38
trans.sh
38
trans.sh
@ -59,13 +59,21 @@ add_community_repo() {
|
|||||||
# 有时网络问题下载失败,导致脚本中断
|
# 有时网络问题下载失败,导致脚本中断
|
||||||
# 因此需要重试
|
# 因此需要重试
|
||||||
apk() {
|
apk() {
|
||||||
retry 5 command apk "$@"
|
retry 5 command apk "$@" >&2
|
||||||
}
|
}
|
||||||
|
|
||||||
# busybox 的 wget 没有重试功能
|
# 在没有设置 set +o pipefail 的情况下,限制下载大小:
|
||||||
|
# retry 5 command wget | head -c 1048576 会触发 retry,下载 5 次
|
||||||
|
# command wget "$@" --tries=5 | head -c 1048576 不会触发 wget 自带的 retry,只下载 1 次
|
||||||
wget() {
|
wget() {
|
||||||
echo "$@" | grep -o 'http[^ ]*' >&2
|
echo "$@" | grep -o 'http[^ ]*' >&2
|
||||||
retry 5 command wget "$@"
|
if command wget 2>&1 | grep -q BusyBox; then
|
||||||
|
# busybox wget 没有重试功能
|
||||||
|
retry 5 command wget "$@"
|
||||||
|
else
|
||||||
|
# 原版 wget 自带重试功能
|
||||||
|
command wget --tries=5 --progress=bar:force "$@"
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
is_have_cmd() {
|
is_have_cmd() {
|
||||||
@ -396,6 +404,9 @@ is_dmi_contains() {
|
|||||||
cache_dmi_and_virt
|
cache_dmi_and_virt
|
||||||
echo "$_dmi" | grep -Eiwq "$1"
|
echo "$_dmi" | grep -Eiwq "$1"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
show_netconf() {
|
||||||
|
grep -r . /dev/netconf/
|
||||||
}
|
}
|
||||||
|
|
||||||
get_ra_to() {
|
get_ra_to() {
|
||||||
@ -413,6 +424,8 @@ get_ra_to() {
|
|||||||
echo
|
echo
|
||||||
ip addr | cat -n
|
ip addr | cat -n
|
||||||
echo
|
echo
|
||||||
|
show_netconf | cat -n
|
||||||
|
echo
|
||||||
fi
|
fi
|
||||||
eval "$1='$_ra'"
|
eval "$1='$_ra'"
|
||||||
}
|
}
|
||||||
@ -1189,6 +1202,7 @@ install_nixos() {
|
|||||||
# 2. 用 nix 安装 nixos-install-tools (nixos-xxx)
|
# 2. 用 nix 安装 nixos-install-tools (nixos-xxx)
|
||||||
# 3. 运行 nixos-generate-config 生成配置 + 编辑
|
# 3. 运行 nixos-generate-config 生成配置 + 编辑
|
||||||
# 4. 运行 nixos-install
|
# 4. 运行 nixos-install
|
||||||
|
# https://nixos.org/manual/nixos/stable/index.html#sec-installing-from-other-distro
|
||||||
|
|
||||||
# nix 安装方式 分支 版本
|
# nix 安装方式 分支 版本
|
||||||
# apk add nix 3.20 2.22.0 # nix 本体跟 alpine 正常的软件一样,不在 /nix/store 里面
|
# apk add nix 3.20 2.22.0 # nix 本体跟 alpine 正常的软件一样,不在 /nix/store 里面
|
||||||
@ -2296,8 +2310,8 @@ EOF
|
|||||||
! sh /can_use_cloud_kernel.sh "$xda" $eths; then
|
! sh /can_use_cloud_kernel.sh "$xda" $eths; then
|
||||||
|
|
||||||
cp_resolv_conf $os_dir
|
cp_resolv_conf $os_dir
|
||||||
chroot $os_dir apt update
|
chroot $os_dir apt-get update
|
||||||
DEBIAN_FRONTEND=noninteractive chroot $os_dir apt install -y linux-image-$axx64
|
DEBIAN_FRONTEND=noninteractive chroot $os_dir apt-get install -y linux-image-$axx64
|
||||||
|
|
||||||
# 标记云内核包
|
# 标记云内核包
|
||||||
# apt-mark showmanual 结果为空,返回值也是 0
|
# apt-mark showmanual 结果为空,返回值也是 0
|
||||||
@ -2312,12 +2326,12 @@ EOF
|
|||||||
|
|
||||||
if [ "$releasever" -le 11 ]; then
|
if [ "$releasever" -le 11 ]; then
|
||||||
cp_resolv_conf $os_dir
|
cp_resolv_conf $os_dir
|
||||||
chroot $os_dir apt update
|
chroot $os_dir apt-get update
|
||||||
|
|
||||||
if true; then
|
if true; then
|
||||||
# 将 debian 11 设置为 12 一样的网络管理器
|
# 将 debian 11 设置为 12 一样的网络管理器
|
||||||
# 可解决 ifupdown dhcp 不支持 24位掩码+不规则网关的问题
|
# 可解决 ifupdown dhcp 不支持 24位掩码+不规则网关的问题
|
||||||
DEBIAN_FRONTEND=noninteractive chroot $os_dir apt install -y netplan.io
|
DEBIAN_FRONTEND=noninteractive chroot $os_dir apt-get install -y netplan.io
|
||||||
chroot $os_dir systemctl disable networking resolvconf
|
chroot $os_dir systemctl disable networking resolvconf
|
||||||
chroot $os_dir systemctl enable systemd-networkd systemd-resolved
|
chroot $os_dir systemctl enable systemd-networkd systemd-resolved
|
||||||
rm_resolv_conf $os_dir
|
rm_resolv_conf $os_dir
|
||||||
@ -2331,7 +2345,7 @@ EOF
|
|||||||
|
|
||||||
else
|
else
|
||||||
# debian 11 默认不支持 rdnss,要安装 rdnssd 或者 nm
|
# debian 11 默认不支持 rdnss,要安装 rdnssd 或者 nm
|
||||||
DEBIAN_FRONTEND=noninteractive chroot $os_dir apt install -y rdnssd
|
DEBIAN_FRONTEND=noninteractive chroot $os_dir apt-get install -y rdnssd
|
||||||
# 不会自动建立链接,因此不能删除
|
# 不会自动建立链接,因此不能删除
|
||||||
restore_resolv_conf $os_dir
|
restore_resolv_conf $os_dir
|
||||||
fi
|
fi
|
||||||
@ -2666,7 +2680,7 @@ chroot_apt_autoremove() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
change_confs change
|
change_confs change
|
||||||
DEBIAN_FRONTEND=noninteractive chroot $os_dir apt autoremove --purge -y
|
DEBIAN_FRONTEND=noninteractive chroot $os_dir apt-get autoremove --purge -y
|
||||||
change_confs restore
|
change_confs restore
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3010,8 +3024,8 @@ EOF
|
|||||||
# 安装最佳内核
|
# 安装最佳内核
|
||||||
flavor=$(get_ubuntu_kernel_flavor)
|
flavor=$(get_ubuntu_kernel_flavor)
|
||||||
echo "Use kernel flavor: $flavor"
|
echo "Use kernel flavor: $flavor"
|
||||||
chroot $os_dir apt update
|
chroot $os_dir apt-get update
|
||||||
DEBIAN_FRONTEND=noninteractive chroot $os_dir apt install -y "linux-image-$flavor"
|
DEBIAN_FRONTEND=noninteractive chroot $os_dir apt-get install -y "linux-image-$flavor"
|
||||||
|
|
||||||
# 自带内核:
|
# 自带内核:
|
||||||
# 常规版本 generic
|
# 常规版本 generic
|
||||||
@ -3032,7 +3046,7 @@ EOF
|
|||||||
# 16.04 镜像用 ifupdown/networking 管理网络
|
# 16.04 镜像用 ifupdown/networking 管理网络
|
||||||
# 要安装 resolveconf,不然 /etc/resolv.conf 为空
|
# 要安装 resolveconf,不然 /etc/resolv.conf 为空
|
||||||
if [ "$releasever" = 16.04 ]; then
|
if [ "$releasever" = 16.04 ]; then
|
||||||
chroot $os_dir apt install -y resolvconf
|
chroot $os_dir apt-get install -y resolvconf
|
||||||
ln -sf /run/resolvconf/resolv.conf $os_dir/etc/resolv.conf.orig
|
ln -sf /run/resolvconf/resolv.conf $os_dir/etc/resolv.conf.orig
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user