mirror of
https://github.com/bin456789/reinstall.git
synced 2025-01-18 20:39:14 +08:00
core: 优化旧内核删除的逻辑
This commit is contained in:
parent
57220ccc39
commit
abdbf03eb0
10
reinstall.sh
10
reinstall.sh
@ -1048,6 +1048,12 @@ setos() {
|
|||||||
# cloud.debian.org 同样在瑞典,不是 cdn
|
# cloud.debian.org 同样在瑞典,不是 cdn
|
||||||
fi
|
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
|
if is_use_cloud_image; then
|
||||||
# cloud image
|
# cloud image
|
||||||
# debian --ci 用此标记要是否要换 elts 源
|
# debian --ci 用此标记要是否要换 elts 源
|
||||||
@ -1098,10 +1104,6 @@ Continue?
|
|||||||
|
|
||||||
initrd_dir=debian/dists/$codename/main/installer-$basearch_alt/current/images/netboot/debian-installer/$basearch_alt
|
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}_vmlinuz=https://$initrd_mirror/$initrd_dir/linux
|
||||||
eval ${step}_initrd=https://$initrd_mirror/$initrd_dir/initrd.gz
|
eval ${step}_initrd=https://$initrd_mirror/$initrd_dir/initrd.gz
|
||||||
eval ${step}_ks=$confhome/debian.cfg
|
eval ${step}_ks=$confhome/debian.cfg
|
||||||
|
70
trans.sh
70
trans.sh
@ -2632,22 +2632,22 @@ EOF
|
|||||||
fi
|
fi
|
||||||
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
|
# 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
|
! sh /can_use_cloud_kernel.sh "$xda" $(get_eths); then
|
||||||
|
kernel_package=$(echo "$kernel_package" | sed 's/-cloud//')
|
||||||
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
|
|
||||||
fi
|
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
|
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 "$@"
|
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() {
|
chroot_apt_autoremove() {
|
||||||
os_dir=$1
|
os_dir=$1
|
||||||
|
|
||||||
@ -3577,14 +3594,6 @@ configfile \$prefix/grub.cfg
|
|||||||
EOF
|
EOF
|
||||||
fi
|
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
|
# 常规版本 generic
|
||||||
# minimal 20.04/22.04 kvm # 后台 vnc 无显示
|
# minimal 20.04/22.04 kvm # 后台 vnc 无显示
|
||||||
@ -3592,14 +3601,21 @@ EOF
|
|||||||
|
|
||||||
# debian cloud 内核不支持 ahci,ubuntu virtual 支持
|
# debian cloud 内核不支持 ahci,ubuntu virtual 支持
|
||||||
|
|
||||||
# 标记旧内核包
|
# 标记所有内核为自动安装
|
||||||
# 注意排除 linux-base
|
# 注意排除 linux-base
|
||||||
if pkgs=$(chroot $os_dir apt-mark showmanual linux-* | grep -E 'generic|virtual|kvm' | grep -v $flavor); then
|
# 返回值始终为 0
|
||||||
chroot $os_dir apt-mark auto $pkgs
|
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
|
flavor=$(get_ubuntu_kernel_flavor)
|
||||||
fi
|
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
|
if fw_pkgs=$(get_ucode_firmware_pkgs) && [ -n "$fw_pkgs" ]; then
|
||||||
|
Loading…
x
Reference in New Issue
Block a user