From abdbf03eb040b537af8b618d037b872c8e60576f Mon Sep 17 00:00:00 2001 From: bin456789 Date: Fri, 10 Jan 2025 00:43:25 +0800 Subject: [PATCH] =?UTF-8?q?core:=20=E4=BC=98=E5=8C=96=E6=97=A7=E5=86=85?= =?UTF-8?q?=E6=A0=B8=E5=88=A0=E9=99=A4=E7=9A=84=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- reinstall.sh | 10 +++++--- trans.sh | 70 ++++++++++++++++++++++++++++++++-------------------- 2 files changed, 49 insertions(+), 31 deletions(-) diff --git a/reinstall.sh b/reinstall.sh index 6d8c867..8c3433b 100644 --- a/reinstall.sh +++ b/reinstall.sh @@ -1048,6 +1048,12 @@ setos() { # cloud.debian.org 同样在瑞典,不是 cdn fi + is_virt && flavour=-cloud || flavour= + # debian 10 云内核 vultr efi vnc 没有显示 + [ "$releasever" -le 10 ] && flavour= + # 甲骨文 arm64 cloud 内核 vnc 没有显示 + [ "$basearch_alt" = arm64 ] && flavour= + if is_use_cloud_image; then # cloud image # debian --ci 用此标记要是否要换 elts 源 @@ -1098,10 +1104,6 @@ Continue? initrd_dir=debian/dists/$codename/main/installer-$basearch_alt/current/images/netboot/debian-installer/$basearch_alt - is_virt && flavour=-cloud || flavour= - # 甲骨文 arm64 cloud 内核 vnc 没有显示 - [ "$basearch_alt" = arm64 ] && flavour= - eval ${step}_vmlinuz=https://$initrd_mirror/$initrd_dir/linux eval ${step}_initrd=https://$initrd_mirror/$initrd_dir/initrd.gz eval ${step}_ks=$confhome/debian.cfg diff --git a/trans.sh b/trans.sh index 071b08b..2742d9f 100644 --- a/trans.sh +++ b/trans.sh @@ -2632,22 +2632,22 @@ EOF fi fi - # 检测机器是否能用 cloud 内核 + # 标记所有内核为自动安装 + pkgs=$(chroot $os_dir apt-mark showmanual linux-image* linux-headers*) + chroot $os_dir apt-mark auto $pkgs + + # 安装合适的内核 + kernel_package=$kernel # shellcheck disable=SC2046 - if ls $os_dir/boot/vmlinuz-*-cloud-$(get_axx64) 2>/dev/null && + # 检测机器是否能用 cloud 内核 + if [[ "$kernel_package" = 'linux-image-cloud-*' ]] && ! sh /can_use_cloud_kernel.sh "$xda" $(get_eths); then - - chroot_apt_install $os_dir "linux-image-$(get_axx64)" - - # 标记云内核包 - # apt-mark showmanual 结果为空,返回值也是 0 - if pkgs=$(chroot $os_dir apt-mark showmanual "linux-*-cloud-$(get_axx64)" | grep .); then - chroot $os_dir apt-mark auto $pkgs - - # 使用 autoremove - chroot_apt_autoremove $os_dir - fi + kernel_package=$(echo "$kernel_package" | sed 's/-cloud//') fi + chroot_apt_install $os_dir "$kernel_package" + + # 使用 autoremove 删除非最佳内核 + chroot_apt_autoremove $os_dir # 微码+固件 if fw_pkgs=$(get_ucode_firmware_pkgs) && [ -n "$fw_pkgs" ]; then @@ -3163,6 +3163,23 @@ chroot_apt_install() { DEBIAN_FRONTEND=noninteractive chroot $os_dir apt-get install -y "$@" } +chroot_apt_remove() { + os_dir=$1 + shift + + # 不能用 apt remove --purge -y xxx yyy + # 因为如果索引里没有其中一个,会报错,另一个也不会删除 + # 因此需要分开删除 + for package in "$@"; do + # apt list 会提示 WARNING: apt does not have a stable CLI interface. Use with caution in scripts. + # 但又不能用 apt-get list + if chroot $os_dir apt list --installed "$package" | grep -q installed; then + # 删除 resolvconf 时会弹出建议重启,因此添加 noninteractive + DEBIAN_FRONTEND=noninteractive chroot $os_dir apt-get remove --purge -y "$package" + fi + done +} + chroot_apt_autoremove() { os_dir=$1 @@ -3577,14 +3594,6 @@ configfile \$prefix/grub.cfg EOF fi - # 更新包索引 - chroot $os_dir apt-get update - - # 安装最佳内核 - flavor=$(get_ubuntu_kernel_flavor) - echo "Use kernel flavor: $flavor" - chroot_apt_install $os_dir "linux-image-$flavor" - # 自带内核: # 常规版本 generic # minimal 20.04/22.04 kvm # 后台 vnc 无显示 @@ -3592,14 +3601,21 @@ EOF # debian cloud 内核不支持 ahci,ubuntu virtual 支持 - # 标记旧内核包 + # 标记所有内核为自动安装 # 注意排除 linux-base - if pkgs=$(chroot $os_dir apt-mark showmanual linux-* | grep -E 'generic|virtual|kvm' | grep -v $flavor); then - chroot $os_dir apt-mark auto $pkgs + # 返回值始终为 0 + pkgs=$(chroot $os_dir apt-mark showmanual \ + linux-generic linux-virtual linux-kvm \ + linux-image* linux-headers*) + chroot $os_dir apt-mark auto $pkgs - # 使用 autoremove - chroot_apt_autoremove $os_dir - fi + # 安装最佳内核 + flavor=$(get_ubuntu_kernel_flavor) + echo "Use kernel flavor: $flavor" + chroot_apt_install $os_dir "linux-image-$flavor" + + # 使用 autoremove 删除多余内核 + chroot_apt_autoremove $os_dir # 安装固件+微码 if fw_pkgs=$(get_ucode_firmware_pkgs) && [ -n "$fw_pkgs" ]; then