ubuntu: 支持 Ubuntu Pro 还生效的旧版本

This commit is contained in:
bin456789 2024-07-23 00:15:22 +08:00
parent 55880439a1
commit e92dcb86a9
No known key found for this signature in database
GPG Key ID: EE301B386DE6C11B
4 changed files with 94 additions and 29 deletions

View File

@ -27,7 +27,7 @@ Reinstall server with one-click [中文](README.md)
| <img width="16" height="16" src="https://www.alpinelinux.org/alpine-logo.ico" /> Alpine | 3.17, 3.18, 3.19, 3.20 | 256 MB | 1 GB |
| <img width="16" height="16" src="https://www.debian.org/favicon.ico" /> Debian | 9, 10, 11, 12 | 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://netplan.readthedocs.io/en/latest/_static/favicon.png" /> Ubuntu | 20.04, 22.04, 24.04 | 512 MB \* | 2 GB |
| <img width="16" height="16" src="https://netplan.readthedocs.io/en/latest/_static/favicon.png" /> Ubuntu | 16.04, 18.04, 20.04, 22.04, 24.04 | 512 MB \* | 2 GB |
| <img width="16" height="16" src="https://www.centos.org/assets/img/favicon.png" /> CentOS | 9 | 512 MB \* | 5 GB |
| <img width="16" height="16" src="https://img.alicdn.com/imgextra/i1/O1CN01oJnJZg1yK4RzI4Rx2_!!6000000006559-2-tps-118-118.png" /> Anolis | 7, 8 | 512 MB \* | 5 GB |
| <img width="16" height="16" src="https://www.redhat.com/favicon.ico" /> RedHat &nbsp; <img width="16" height="16" src="https://almalinux.org/fav/favicon.ico" /> Alma &nbsp; <img width="16" height="16" src="https://rockylinux.org/favicon.png" /> 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

View File

@ -27,7 +27,7 @@
| <img width="16" height="16" src="https://www.alpinelinux.org/alpine-logo.ico" /> Alpine | 3.17, 3.18, 3.19, 3.20 | 256 MB | 1 GB |
| <img width="16" height="16" src="https://www.debian.org/favicon.ico" /> Debian | 9, 10, 11, 12 | 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://netplan.readthedocs.io/en/latest/_static/favicon.png" /> Ubuntu | 20.04, 22.04, 24.04 | 512 MB \* | 2 GB |
| <img width="16" height="16" src="https://netplan.readthedocs.io/en/latest/_static/favicon.png" /> Ubuntu | 16.04, 18.04, 20.04, 22.04, 24.04 | 512 MB \* | 2 GB |
| <img width="16" height="16" src="https://www.centos.org/assets/img/favicon.png" /> CentOS | 9 | 512 MB \* | 5 GB |
| <img width="16" height="16" src="https://img.alicdn.com/imgextra/i1/O1CN01oJnJZg1yK4RzI4Rx2_!!6000000006559-2-tps-118-118.png" /> Anolis | 7, 8 | 512 MB \* | 5 GB |
| <img width="16" height="16" src="https://www.redhat.com/favicon.ico" /> RedHat &nbsp; <img width="16" height="16" src="https://almalinux.org/fav/favicon.ico" /> Alma &nbsp; <img width="16" height="16" src="https://rockylinux.org/favicon.png" /> 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

View File

@ -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' \

View File

@ -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 <<EOF >"$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