diff --git a/README.en.md b/README.en.md index 895bed4..abe9a60 100644 --- a/README.en.md +++ b/README.en.md @@ -15,7 +15,7 @@ One-Click Script to Reinstall System [中文](README.md) ## Highlights -- One-click Linux installation: Supports 18 common distributions. +- One-click Linux installation: Supports 19 common distributions. - One-click Windows installation: Uses the official ISO for installation instead of custom images. The script automatically retrieves the ISO link and installs `Virtio` and other drivers. - Supports installation in any direction, i.e., `Linux to Linux`, `Linux to Windows`, `Windows to Windows`, `Windows to Linux` - No need to input IP parameters; automatically recognizes dynamic and static IPs, supports `/32`, `/128`, `gateway outside subnet`, `IPv6 only`, `dual NIC` and other special network configurations @@ -47,7 +47,8 @@ The system requirements for the target system are as follows: | NixOS | 24.11 | 512 MB | 5 GB | | Arch | Rolling | 512 MB | 5 GB | | Gentoo | Rolling | 512 MB | 5 GB | -| 飞牛 fnOS | Beta | 512 MB | 12 GB | +| AOSC | Rolling | 512 MB | 5 GB | +| fnOS | Beta | 512 MB | 12 GB | | Windows (DD) | Any | 512 MB | Depends on image | | Windows (ISO) | Vista, 7, 8.x (Server 2008 - 2012 R2) | 512 MB | 25 GB | | Windows (ISO) | 10, 11 (Server 2016 - 2025) | 1 GB | 25 GB | diff --git a/README.md b/README.md index b3a1c5d..463349a 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ ## 亮点 -- 一键安装 Linux,支持 18 种常见发行版 +- 一键安装 Linux,支持 19 种常见发行版 - 一键安装 Windows,使用官方 ISO 安装而非自制镜像,脚本会自动获取 ISO 链接、自动安装 Virtio 等驱动 - 支持任意方向重装,即 `Linux to Linux`、`Linux to Windows`、`Windows to Windows`、`Windows to Linux` - 无需填写 IP 参数,自动识别动静态,支持 `/32`、`/128`、`网关不在子网范围内`、`纯 IPv6`、`双网卡` 等特殊网络 @@ -47,7 +47,8 @@ | NixOS | 24.11 | 512 MB | 5 GB | | Arch | 滚动 | 512 MB | 5 GB | | Gentoo | 滚动 | 512 MB | 5 GB | -| 飞牛 fnOS | 公测版 | 512 MB | 12 GB | +| 安同 AOSC | 滚动 | 512 MB | 5 GB | +| 飞牛 fnOS | 公测 | 512 MB | 12 GB | | Windows (DD) | 任何 | 512 MB | 取决于镜像 | | Windows (ISO) | Vista, 7, 8.x (Server 2008 - 2012 R2) | 512 MB | 25 GB | | Windows (ISO) | 10, 11 (Server 2016 - 2025) | 1 GB | 25 GB | @@ -143,6 +144,7 @@ bash reinstall.sh anolis 7|8|23 kali arch gentoo + aosc fnos ``` diff --git a/fix-eth-name.service b/fix-eth-name.service index 56838b1..1380c73 100644 --- a/fix-eth-name.service +++ b/fix-eth-name.service @@ -22,6 +22,7 @@ ExecStart=/usr/bin/env bash /fix-eth-name.sh ExecStart=/usr/bin/env rm -f /fix-eth-name.sh ExecStart=/usr/bin/env rm -f /etc/systemd/system/fix-eth-name.service ExecStart=/usr/bin/env rm -f /etc/systemd/system/multi-user.target.wants/fix-eth-name.service +ExecStart=/usr/bin/env rm -f /usr/lib/systemd/system-preset/01-fix-eth-name.preset [Install] WantedBy=multi-user.target diff --git a/reinstall.sh b/reinstall.sh index dbbfd17..9ba8194 100644 --- a/reinstall.sh +++ b/reinstall.sh @@ -62,6 +62,7 @@ Usage: $reinstall_____ anolis 7|8|23 kali arch gentoo + aosc fnos 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 @@ -1479,6 +1480,22 @@ Continue with DD? eval "${step}_iso='$iso'" } + setos_aosc() { + if is_in_china; then + mirror=https://mirror.nju.edu.cn/anthon/aosc-os + else + # 服务器在香港 + mirror=https://releases.aosc.io + fi + + dir=os-$basearch_alt/base + file=$(curl -L $mirror/$dir/ | grep -oP 'aosc-os_base_.*?\.tar.xz' | + sort -uV | tail -1 | grep .) + img=$mirror/$dir/$file + test_url $img 'tar.xz' + eval ${step}_img=$img + } + setos_centos_almalinux_rocky_fedora() { # el 10 需要 x86-64-v3 if [ "$basearch" = x86_64 ] && @@ -1719,6 +1736,7 @@ verify_os_name() { 'kali' \ 'arch' \ 'gentoo' \ + 'aosc' \ 'fnos' \ 'windows' \ 'dd' \ @@ -1976,7 +1994,7 @@ check_ram() { case "$distro" in netboot.xyz) echo 0 ;; alpine | debian | kali | dd) echo 256 ;; - arch | gentoo | nixos | windows) echo 512 ;; + arch | gentoo | aosc | nixos | windows) echo 512 ;; redhat | centos | almalinux | rocky | fedora | oracle | ubuntu | anolis | opencloudos | openeuler) echo 1024 ;; opensuse | fnos) echo -1 ;; # 没有安装模式 esac @@ -3749,7 +3767,7 @@ mkdir_clear "$tmp" # 强制忽略/强制添加 --ci 参数 # debian 不强制忽略 ci 留作测试 case "$distro" in -dd | windows | netboot.xyz | kali | alpine | arch | gentoo | nixos) +dd | windows | netboot.xyz | kali | alpine | arch | gentoo | aosc | nixos | fnos) if is_use_cloud_image; then echo "ignored --ci" unset cloud_image diff --git a/trans.sh b/trans.sh index 8bc42b9..1894cc1 100644 --- a/trans.sh +++ b/trans.sh @@ -1651,6 +1651,12 @@ add_fix_eth_name_systemd_service() { download "$confhome/fix-eth-name.sh" "$os_dir/fix-eth-name.sh" download "$confhome/fix-eth-name.service" "$os_dir/etc/systemd/system/fix-eth-name.service" chroot "$os_dir" systemctl enable fix-eth-name + + # aosc 首次开机会执行 preset-all + # 因此需要设置 fix-eth-name 的 preset 状态 + # 不然首次开机 /etc/systemd/system/multi-user.target.wants/fix-eth-name.service 会被删除 + # 通常 /etc/systemd/system-preset/ 文件夹要新建,因此不放在这里 + echo 'enable fix-eth-name.service' >"$os_dir/usr/lib/systemd/system-preset/01-fix-eth-name.preset" } basic_init() { @@ -1706,9 +1712,16 @@ basic_init() { add_fix_eth_name_systemd_service $os_dir } -install_arch_gentoo() { +install_arch_gentoo_aosc() { info "install $distro" + network_app=$( + case "$distro" in + arch | gentoo) echo systemd-networkd ;; + aosc) echo network-manager ;; + esac + ) + set_locale() { echo "C.UTF-8 UTF-8" >>$os_dir/etc/locale.gen chroot $os_dir locale-gen @@ -1906,6 +1919,22 @@ EOF chroot $os_dir emerge sys-kernel/gentoo-kernel-bin } + install_aosc() { + # 解压系统 + apk add wget tar xz + wget "$img" -O- | tar xpJ --numeric-owner --xattrs-include='*.*' -C $os_dir + apk del wget tar xz + + # 添加 swap + create_swap_if_ram_less_than 1024 $os_dir/swapfile + + # 挂载伪文件系统 + mount_pseudo_fs $os_dir + + # 生成 initramfs + chroot $os_dir update-initramfs + } + os_dir=/os # 挂载分区 @@ -1927,8 +1956,49 @@ EOF chroot $os_dir systemd-firstboot --force --timezone=Asia/Shanghai # gentoo 不会自动创建 machine-id clear_machine_id $os_dir - chroot $os_dir systemctl enable systemd-networkd - chroot $os_dir systemctl enable systemd-resolved + + # 网络配置 + case "$network_app" in + systemd-networkd) + chroot $os_dir systemctl enable systemd-networkd + chroot $os_dir systemctl enable systemd-resolved + + apk add cloud-init + # 第二次运行会报错 + useradd systemd-network || true + create_cloud_init_network_config net.cfg + cat -n net.cfg + # 正常应该是 -D gentoo,但 alpine 的 cloud-init 包缺少 gentoo 配置 + cloud-init devel net-convert -p net.cfg -k yaml -d out -D alpine -O networkd + cp out/etc/systemd/network/10-cloud-init-eth*.network $os_dir/etc/systemd/network/ + + # 删除网卡名匹配 + sed -i '/^Name=/d' $os_dir/etc/systemd/network/10-cloud-init-eth*.network + + # 清理 + rm -rf net.cfg out + apk del cloud-init + + # 显示网络配置 + cat -n $os_dir/etc/systemd/network/10-cloud-init-eth*.network + ;; + network-manager) + chroot $os_dir systemctl enable NetworkManager + + # 可以直接用 alpine 的 cloud-init 生成 Network Manager 配置 + create_cloud_init_network_config /net.cfg + create_network_manager_config /net.cfg "$os_dir" + rm /net.cfg + ;; + esac + + # 修正网卡名 + add_fix_eth_name_systemd_service $os_dir + + # arch gentoo 网络配置是用 alpine cloud-init 生成的 + # cloud-init 版本够新,因此无需修复 onlink 网关 + + # ssh chroot $os_dir systemctl enable sshd allow_root_password_login $os_dir if is_need_change_ssh_port; then @@ -1938,29 +2008,6 @@ EOF # 修改密码 change_root_password $os_dir - # 网络配置 - apk add cloud-init - # 第二次运行会报错 - useradd systemd-network || true - create_cloud_init_network_config net.cfg - cat -n net.cfg - # 正常应该是 -D gentoo,但 alpine 的 cloud-init 包缺少 gentoo 配置 - cloud-init devel net-convert -p net.cfg -k yaml -d out -D alpine -O networkd - cp out/etc/systemd/network/10-cloud-init-eth*.network $os_dir/etc/systemd/network/ - - # 清理 - rm -rf net.cfg out - apk del cloud-init - - # 删除网卡名匹配 - sed -i '/^Name=/d' $os_dir/etc/systemd/network/10-cloud-init-eth*.network - - # 修正网卡名 - add_fix_eth_name_systemd_service $os_dir - - # arch gentoo 网络配置是用 alpine cloud-init 生成的 - # cloud-init 版本够新,因此无需修复 onlink 网关 - # ntp 用 systemd 自带的 # TODO: vm agent + 随机数生成器 @@ -1985,8 +2032,9 @@ EOF # fstab # fstab 可不写 efi 条目, systemd automount 会自动挂载 + # fstab 头部有使用说明,因此用 >> apk add arch-install-scripts - genfstab -U $os_dir | sed '/swap/d' >$os_dir/etc/fstab + genfstab -U $os_dir | sed '/swap/d' >>$os_dir/etc/fstab apk del arch-install-scripts # 删除 resolv.conf,不然 systemd-resolved 无法创建软链接 @@ -2307,7 +2355,8 @@ create_part() { mkfs.ext4 -F -L os /dev/$xda*1 #1 os mkfs.ext4 -F -L installer /dev/$xda*2 #2 installer fi - elif [ "$distro" = alpine ] || [ "$distro" = arch ] || [ "$distro" = gentoo ] || [ "$distro" = nixos ]; then + elif [ "$distro" = alpine ] || [ "$distro" = arch ] || [ "$distro" = gentoo ] || + [ "$distro" = nixos ] || [ "$distro" = aosc ]; then # alpine 本身关闭了 64bit ext4 # https://gitlab.alpinelinux.org/alpine/alpine-conf/-/blob/3.18.1/setup-disk.in?ref_type=tags#L908 # 而且 alpine 的 extlinux 不兼容 64bit ext4 @@ -6087,9 +6136,9 @@ trans() { alpine) install_alpine ;; - arch | gentoo) + arch | gentoo | aosc) create_part - install_arch_gentoo + install_arch_gentoo_aosc ;; nixos) create_part