From e92dcb86a92835eab782d2dd79e8e984fbbf70c8 Mon Sep 17 00:00:00 2001 From: bin456789 Date: Tue, 23 Jul 2024 00:15:22 +0800 Subject: [PATCH] =?UTF-8?q?ubuntu:=20=E6=94=AF=E6=8C=81=20Ubuntu=20Pro=20?= =?UTF-8?q?=E8=BF=98=E7=94=9F=E6=95=88=E7=9A=84=E6=97=A7=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.en.md | 4 +-- README.md | 4 +-- reinstall.sh | 30 ++++++++++++++----- trans.sh | 85 +++++++++++++++++++++++++++++++++++++++++----------- 4 files changed, 94 insertions(+), 29 deletions(-) diff --git a/README.en.md b/README.en.md index 31ba7a2..1193a51 100644 --- a/README.en.md +++ b/README.en.md @@ -27,7 +27,7 @@ Reinstall server with one-click [中文](README.md) | Alpine | 3.17, 3.18, 3.19, 3.20 | 256 MB | 1 GB | | Debian | 9, 10, 11, 12 | 256 MB | 1 ~ 1.5 GB ^ | | Kali | Rolling | 256 MB | 1 ~ 1.5 GB ^ | -| Ubuntu | 20.04, 22.04, 24.04 | 512 MB \* | 2 GB | +| Ubuntu | 16.04, 18.04, 20.04, 22.04, 24.04 | 512 MB \* | 2 GB | | CentOS | 9 | 512 MB \* | 5 GB | | Anolis | 7, 8 | 512 MB \* | 5 GB | | RedHat   Alma   Rocky | 8, 9 | 512 MB \* | 5 GB | @@ -155,9 +155,9 @@ bash reinstall.sh centos 9 fedora 39|40 debian 9|10|11|12 openeuler 20.03|22.03|24.03 - ubuntu 20.04|22.04|24.04 alpine 3.17|3.18|3.19|3.20 opensuse 15.5|15.6|tumbleweed + ubuntu 16.04|18.04|20.04|22.04|24.04 kali arch gentoo diff --git a/README.md b/README.md index 7fdd2cf..a3e845d 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ | Alpine | 3.17, 3.18, 3.19, 3.20 | 256 MB | 1 GB | | Debian | 9, 10, 11, 12 | 256 MB | 1 ~ 1.5 GB ^ | | Kali | 滚动 | 256 MB | 1 ~ 1.5 GB ^ | -| Ubuntu | 20.04, 22.04, 24.04 | 512 MB \* | 2 GB | +| Ubuntu | 16.04, 18.04, 20.04, 22.04, 24.04 | 512 MB \* | 2 GB | | CentOS | 9 | 512 MB \* | 5 GB | | Anolis | 7, 8 | 512 MB \* | 5 GB | | RedHat   Alma   Rocky | 8, 9 | 512 MB \* | 5 GB | @@ -155,9 +155,9 @@ bash reinstall.sh centos 9 fedora 39|40 debian 9|10|11|12 openeuler 20.03|22.03|24.03 - ubuntu 20.04|22.04|24.04 alpine 3.17|3.18|3.19|3.20 opensuse 15.5|15.6|tumbleweed + ubuntu 16.04|18.04|20.04|22.04|24.04 kali arch gentoo diff --git a/reinstall.sh b/reinstall.sh index b663cbc..fa3d801 100644 --- a/reinstall.sh +++ b/reinstall.sh @@ -41,9 +41,9 @@ Usage: $reinstall____ centos 9 fedora 39|40 debian 9|10|11|12 openeuler 20.03|22.03|24.03 - ubuntu 20.04|22.04|24.04 alpine 3.17|3.18|3.19|3.20 opensuse 15.5|15.6|tumbleweed + ubuntu 16.04|18.04|20.04|22.04|24.04 kali arch gentoo @@ -852,6 +852,8 @@ setos() { setos_ubuntu() { case "$releasever" in + 16.04) codename=xenial ;; + 18.04) codename=bionic ;; 20.04) codename=focal ;; 22.04) codename=jammy ;; 24.04) codename=noble ;; @@ -870,12 +872,26 @@ setos() { else ci_mirror=https://cloud-images.ubuntu.com fi - # 20.04/22.04 minimal 镜像没有 aarch64 - if { { [ "$releasever" = 20.04 ] || [ "$releasever" = 22.04 ]; } && [ "$basearch_alt" = amd64 ]; } || - [ "$releasever" = 24.04 ]; then - eval ${step}_img=$ci_mirror/minimal/releases/$codename/release/ubuntu-$releasever-minimal-cloudimg-$basearch_alt.img + + # 22.04 和以下没有 minimal aarch64 镜像 + is_have_minimal_image() { + [ "$basearch_alt" = amd64 ] || [ "$releasever" = 24.04 ] + } + + get_suffix() { + if [ "$releasever" = 16.04 ]; then + if is_efi; then + echo -uefi1 + else + echo -disk1 + fi + fi + } + + if is_have_minimal_image; then + eval ${step}_img="$ci_mirror/minimal/releases/$codename/release/ubuntu-$releasever-minimal-cloudimg-$basearch_alt$(get_suffix).img" else - eval ${step}_img=$ci_mirror/releases/$releasever/release/ubuntu-$releasever-server-cloudimg-$basearch_alt.img + eval ${step}_img="$ci_mirror/releases/$releasever/release/ubuntu-$releasever-server-cloudimg-$basearch_alt$(get_suffix).img" fi else # 传统安装 @@ -1256,9 +1272,9 @@ verify_os_name() { 'fedora 39|40' \ 'debian 9|10|11|12' \ 'openeuler 20.03|22.03|24.03' \ - 'ubuntu 20.04|22.04|24.04' \ 'alpine 3.17|3.18|3.19|3.20' \ 'opensuse 15.5|15.6|tumbleweed' \ + 'ubuntu 16.04|18.04|20.04|22.04|24.04' \ 'kali' \ 'arch' \ 'gentoo' \ diff --git a/trans.sh b/trans.sh index 8f1dc8a..9de7427 100644 --- a/trans.sh +++ b/trans.sh @@ -2263,10 +2263,31 @@ chroot_dnf() { chroot_apt_autoremove() { os_dir=$1 - conf=$os_dir/etc/apt/apt.conf.d/01autoremove - sed -i.orig 's/VersionedKernelPackages/x/; s/NeverAutoRemove/x/' $conf + change_confs() { + action=$1 + + # 只有 16.04 有 01autoremove-kernels + # 16.04 结束支持后删除 + for conf in 01autoremove 01autoremove-kernels; do + file=$os_dir/etc/apt/apt.conf.d/$conf + case "$action" in + change) + if [ -f $file ]; then + sed -i.orig 's/VersionedKernelPackages/x/; s/NeverAutoRemove/x/' $file + fi + ;; + restore) + if [ -f $file.orig ]; then + mv $file.orig $file + fi + ;; + esac + done + } + + change_confs change DEBIAN_FRONTEND=noninteractive chroot $os_dir apt autoremove --purge -y - mv $conf.orig $conf + change_confs restore } del_default_user() { @@ -2600,6 +2621,18 @@ EOF done fi + # 16.04 arm64 镜像没有 grub 引导文件 + if is_efi && ! [ -d $os_dir/boot/efi/EFI/ubuntu ]; then + DEBIAN_FRONTEND=noninteractive chroot $os_dir \ + apt-get upgrade --reinstall -y efibootmgr shim "grub-efi-$(get_axx64)" + + cat <"$os_dir/boot/efi/EFI/ubuntu/grub.cfg" +search.fs_uuid $os_part_uuid root +set prefix=(\$root)'/boot/grub' +configfile \$prefix/grub.cfg +EOF + fi + # 安装最佳内核 flavor=$(get_ubuntu_kernel_flavor) echo "Use kernel flavor: $flavor" @@ -2621,6 +2654,14 @@ EOF # 使用 autoremove chroot_apt_autoremove $os_dir fi + + # 16.04 镜像用 ifupdown/networking 管理网络 + # 要安装 resolveconf,不然 /etc/resolv.conf 为空 + if [ "$releasever" = 16.04 ]; then + chroot $os_dir apt install -y resolvconf + ln -sf /run/resolvconf/resolv.conf $os_dir/etc/resolv.conf.orig + fi + # 安装 bios 引导 if ! is_efi; then chroot $os_dir grub-install /dev/$xda @@ -3531,22 +3572,30 @@ get_ubuntu_kernel_flavor() { # http://git.annexia.org/?p=virt-what.git;a=blob;f=virt-what.in;hb=HEAD { # busybox blkid 不显示 sr0 的 UUID - apk add lsblk - - if is_dmi_contains "amazon" || is_dmi_contains "ec2"; then - flavor=aws - elif is_dmi_contains "Google Compute Engine" || is_dmi_contains "GoogleCloud"; then - flavor=gcp - elif is_dmi_contains "OracleCloud"; then - flavor=oracle - elif is_dmi_contains "7783-7084-3265-9085-8269-3286-77"; then - flavor=azure - elif lsblk -o UUID,LABEL | grep -i 9796-932E | grep -i config-2; then - flavor=ibm - elif is_virt; then - flavor=virtual-hwe-$releasever + if [ "$releasever" = 16.04 ]; then + if is_virt; then + flavor=virtual-hwe-$releasever + else + flavor=generic-hwe-$releasever + fi else - flavor=generic-hwe-$releasever + apk add lsblk + + if is_dmi_contains "amazon" || is_dmi_contains "ec2"; then + flavor=aws + elif is_dmi_contains "Google Compute Engine" || is_dmi_contains "GoogleCloud"; then + flavor=gcp + elif is_dmi_contains "OracleCloud"; then + flavor=oracle + elif is_dmi_contains "7783-7084-3265-9085-8269-3286-77"; then + flavor=azure + elif lsblk -o UUID,LABEL | grep -i 9796-932E | grep -i config-2; then + flavor=ibm + elif is_virt; then + flavor=virtual-hwe-$releasever + else + flavor=generic-hwe-$releasever + fi fi } >&2 echo $flavor