Compare commits

..

3 Commits

4 changed files with 63 additions and 49 deletions

View File

@ -46,7 +46,7 @@ The system requirements for the target system are as follows:
| System | Version | Memory | Disk |
| ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------- | --------- | ---------------- |
| <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.20, 3.21, 3.22, 3.23 | 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://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.10 | 512 MB \* | 2 GB |
@ -57,11 +57,11 @@ The system requirements for the target system are as follows:
| <img width="16" height="16" src="https://fedoraproject.org/favicon.ico" /> Fedora | 42, 43 | 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, 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.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://www.gentoo.org/assets/img/logo/gentoo-g.png" /> Gentoo | Rolling | 512 MB | 5 GB |
| <img width="16" height="16" src="https://aosc.io/distros/aosc-os.svg" /> AOSC OS | Rolling | 512 MB | 5 GB |
| <img width="16" height="16" src="https://www.fnnas.com/favicon.ico" /> fnOS | Beta | 512 MB | 8 GB |
| <img width="16" height="16" src="https://www.fnnas.com/favicon.ico" /> fnOS | 1 | 512 MB | 8 GB |
| <img width="16" height="16" src="https://blogs.windows.com/wp-content/uploads/prod/2022/09/cropped-Windows11IconTransparent512-32x32.png" /> Windows (DD) | Any | 512 MB | Depends on image |
| <img width="16" height="16" src="https://blogs.windows.com/wp-content/uploads/prod/2022/09/cropped-Windows11IconTransparent512-32x32.png" /> Windows (ISO) | Vista, 7, 8.x (Server 2008 - 2012 R2) | 512 MB | 25 GB |
| <img width="16" height="16" src="https://blogs.windows.com/wp-content/uploads/prod/2022/09/cropped-Windows11IconTransparent512-32x32.png" /> Windows (ISO) | 10, 11 (Server 2016 - 2025) | 1 GB | 25 GB |
@ -159,10 +159,11 @@ bash reinstall.sh anolis 7|8|23
almalinux 8|9|10
opencloudos 8|9|23
centos 9|10
fnos 1
nixos 25.11
fedora 42|43
nixos 25.05
debian 9|10|11|12|13
alpine 3.19|3.20|3.21|3.22
alpine 3.20|3.21|3.22|3.23
opensuse 15.6|16.0|tumbleweed
openeuler 20.03|22.03|24.03|25.09
ubuntu 16.04|18.04|20.04|22.04|24.04|25.10 [--minimal]
@ -170,7 +171,6 @@ bash reinstall.sh anolis 7|8|23
arch
gentoo
aosc
fnos
redhat --img="http://access.cdn.redhat.com/xxx.qcow2"
```

View File

@ -46,7 +46,7 @@
| 系统 | 版本 | 内存 | 硬盘 |
| ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------- | --------- | ------------ |
| <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.20, 3.21, 3.22, 3.23 | 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://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.10 | 512 MB \* | 2 GB |
@ -57,11 +57,11 @@
| <img width="16" height="16" src="https://fedoraproject.org/favicon.ico" /> Fedora | 42, 43 | 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, 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.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://www.gentoo.org/assets/img/logo/gentoo-g.png" /> Gentoo | 滚动 | 512 MB | 5 GB |
| <img width="16" height="16" src="https://aosc.io/distros/aosc-os.svg" /> 安同 OS | 滚动 | 512 MB | 5 GB |
| <img width="16" height="16" src="https://www.fnnas.com/favicon.ico" /> 飞牛 fnOS | 公测 | 512 MB | 8 GB |
| <img width="16" height="16" src="https://www.fnnas.com/favicon.ico" /> 飞牛 fnOS | 1 | 512 MB | 8 GB |
| <img width="16" height="16" src="https://blogs.windows.com/wp-content/uploads/prod/2022/09/cropped-Windows11IconTransparent512-32x32.png" /> Windows (DD) | 任何 | 512 MB | 取决于镜像 |
| <img width="16" height="16" src="https://blogs.windows.com/wp-content/uploads/prod/2022/09/cropped-Windows11IconTransparent512-32x32.png" /> Windows (ISO) | Vista, 7, 8.x (Server 2008 - 2012 R2) | 512 MB | 25 GB |
| <img width="16" height="16" src="https://blogs.windows.com/wp-content/uploads/prod/2022/09/cropped-Windows11IconTransparent512-32x32.png" /> Windows (ISO) | 10, 11 (Server 2016 - 2025) | 1 GB | 25 GB |
@ -159,10 +159,11 @@ bash reinstall.sh anolis 7|8|23
almalinux 8|9|10
opencloudos 8|9|23
centos 9|10
fnos 1
nixos 25.11
fedora 42|43
nixos 25.05
debian 9|10|11|12|13
alpine 3.19|3.20|3.21|3.22
alpine 3.20|3.21|3.22|3.23
opensuse 15.6|16.0|tumbleweed
openeuler 20.03|22.03|24.03|25.09
ubuntu 16.04|18.04|20.04|22.04|24.04|25.10 [--minimal]
@ -170,7 +171,6 @@ bash reinstall.sh anolis 7|8|23
arch
gentoo
aosc
fnos
redhat --img="http://access.cdn.redhat.com/xxx.qcow2"
```

View File

@ -22,6 +22,22 @@ export LC_ALL=C
# 不要漏了最后的 $PATH否则会找不到 windows 系统程序例如 diskpart
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:$PATH
# 如果不是 bash 的话,继续执行会有语法错误,因此在这里判断是否 bash
if [ -z "$BASH" ]; then
if [ -f /etc/alpine-release ]; then
if ! apk add bash; then
echo "Error while install bash." >&2
exit 1
fi
fi
if command -v bash >/dev/null; then
exec bash "$0" "$@"
else
echo "Please run this script with bash." >&2
exit 1
fi
fi
# 记录日志,过滤含有 password 的行
exec > >(tee >(grep -iv password >>/reinstall.log)) 2>&1
THIS_SCRIPT=$(readlink -f "$0")
@ -35,11 +51,6 @@ trap_err() {
sed -n "$line_no"p "$THIS_SCRIPT"
}
if ! { [ -n "$BASH" ] && [ -n "$BASH_VERSION" ]; }; then
echo "Please run this script with bash." >&2
exit 1
fi
usage_and_exit() {
if is_in_windows; then
reinstall_____='.\reinstall.bat'
@ -53,10 +64,11 @@ Usage: $reinstall_____ anolis 7|8|23
oracle 8|9|10
almalinux 8|9|10
centos 9|10
fnos 1
nixos 25.11
fedora 42|43
nixos 25.05
debian 9|10|11|12|13
alpine 3.19|3.20|3.21|3.22
alpine 3.20|3.21|3.22|3.23
opensuse 15.6|16.0|tumbleweed
openeuler 20.03|22.03|24.03|25.09
ubuntu 16.04|18.04|20.04|22.04|24.04|25.10 [--minimal]
@ -64,7 +76,6 @@ Usage: $reinstall_____ anolis 7|8|23
arch
gentoo
aosc
fnos
redhat --img="http://access.cdn.redhat.com/xxx.qcow2"
dd --img="http://xxx.com/yyy.zzz" (raw image stores in raw/vhd/tar/gz/xz/zst)
windows --image-name="windows xxx yyy" --lang=xx-yy
@ -909,7 +920,7 @@ get_windows_iso_link() {
esac
;;
homebasic | homepremium | ultimate) echo _ ;;
business | enterprise) "$edition" ;;
business | enterprise) echo "$edition" ;;
esac
;;
7)
@ -1487,8 +1498,8 @@ Continue?
dir=distribution/leap/$releasever/appliances
case "$releasever" in
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 ;;
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 ;;
esac
# https://src.opensuse.org/openSUSE/Leap-Images/src/branch/leap-16.0/kiwi-templates-Minimal/Minimal.kiwi
@ -1907,11 +1918,12 @@ verify_os_name() {
'almalinux 8|9|10' \
'rocky 8|9|10' \
'oracle 8|9|10' \
'fnos 1' \
'fedora 42|43' \
'nixos 25.05' \
'nixos 25.11' \
'debian 9|10|11|12|13' \
'opensuse 15.6|16.0|tumbleweed' \
'alpine 3.19|3.20|3.21|3.22' \
'alpine 3.20|3.21|3.22|3.23' \
'openeuler 20.03|22.03|24.03|25.09' \
'ubuntu 16.04|18.04|20.04|22.04|24.04|25.10' \
'redhat' \
@ -1919,7 +1931,6 @@ verify_os_name() {
'arch' \
'gentoo' \
'aosc' \
'fnos' \
'windows' \
'dd' \
'netboot.xyz'; do

View File

@ -1630,9 +1630,9 @@ install_nixos() {
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
# 1. 从 https://mirror.nju.edu.cn/nix-channels/nixos-25.11/nixexprs.tar.xz 获取
# https://github.com/NixOS/nixpkgs/blob/nixos-25.11/pkgs/tools/package-management/nix/default.nix
# https://github.com/NixOS/nixpkgs/blob/nixos-25.11/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
@ -2756,14 +2756,6 @@ mount_pseudo_fs() {
fi
}
get_yq_name() {
if grep -q '3\.1[6789]' /etc/alpine-release; then
echo yq
else
echo yq-go
fi
}
create_cloud_init_network_config() {
ci_file=$1
recognize_static6=${2:-true}
@ -2775,7 +2767,7 @@ create_cloud_init_network_config() {
mkdir -p "$(dirname "$ci_file")"
touch "$ci_file"
apk add "$(get_yq_name)"
apk add yq-go
need_set_dns4=false
need_set_dns6=false
@ -2889,7 +2881,7 @@ create_cloud_init_network_config() {
yq -i "del(.network.config[$config_id] | select(has(\"address\") | not))" $ci_file
fi
apk del "$(get_yq_name)"
apk del yq-go
# 查看文件
info "Cloud-init network config"
@ -3252,7 +3244,7 @@ remove_cloud_init() {
# disable 会出现一堆提示信息,也无法 disable
for unit in $(
chroot $os_dir systemctl list-unit-files |
grep -E '^(cloud-init-.*|cloud-config|cloud-final)\.(service|socket)' | grep enabled | awk '{print $1}'
grep -E '^(cloud-init|cloud-init-.*|cloud-config|cloud-final)\.(service|socket)' | grep enabled | awk '{print $1}'
); do
# 服务不存在时会报错
if chroot $os_dir systemctl -q is-enabled "$unit"; then
@ -3269,7 +3261,7 @@ remove_cloud_init() {
;;
zypper)
# 加上 -u 才会删除依赖
chroot $os_dir zypper remove -y -u cloud-init
chroot $os_dir zypper remove -y -u cloud-init cloud-init-config-suse
;;
apt-get)
# ubuntu 25.04 开始有 cloud-init-base
@ -3658,24 +3650,35 @@ EOF
fi
# rpm -qi 不支持通配符
installed_kernel=$(chroot $os_dir rpm -qa 'kernel-*' --qf '%{NAME}\n' | grep -v firmware)
if ! [ "$(echo "$installed_kernel" | wc -l)" -eq 1 ]; then
error_and_exit "Unexpected kernel installed: $installed_kernel"
origin_kernel=$(chroot $os_dir rpm -qa 'kernel-*' --qf '%{NAME}\n' | grep -v firmware)
if ! [ "$(echo "$origin_kernel" | wc -l)" -eq 1 ]; then
error_and_exit "Unexpected kernel installed: $origin_kernel"
fi
# 能同时装 kernel-default-base 和 kernel-default
# 16.0 能同时装 kernel-default-base 和 kernel-default
# tw 不能同时装 kernel-default-base 和 kernel-default
# 因此需要添加 --force-resolution 自动删除 kernel-default-base
if ! [ "$installed_kernel" = "$target_kernel" ]; then
if ! [ "$origin_kernel" = "$target_kernel" ]; then
# x86 必须设置一个密码否则报错arm 没有这个问题
# Failed to get root password hash
# 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
need_password_workaround=false
if grep -q '^root:[:!*]' $os_dir/etc/shadow; then
need_password_workaround=true
fi
if $need_password_workaround; then
echo "root:$(mkpasswd '')" | chroot $os_dir chpasswd -e
chroot $os_dir zypper install -y --force-resolution $target_kernel
fi
# 安装新内核
chroot $os_dir zypper install -y --force-resolution $target_kernel
# 删除旧内核
if chroot $os_dir rpm -q $origin_kernel; then
chroot $os_dir zypper remove -y --force-resolution $origin_kernel
fi
if $need_password_workaround; then
chroot $os_dir passwd -d root
else
chroot $os_dir zypper install -y --force-resolution $target_kernel
fi
fi