core: 不重要的优化

This commit is contained in:
bin456789 2024-12-06 22:50:05 +08:00
parent b00b4cded0
commit 702fc03920
No known key found for this signature in database
GPG Key ID: EE301B386DE6C11B
2 changed files with 61 additions and 44 deletions

View File

@ -7,14 +7,16 @@ confhome=https://raw.githubusercontent.com/bin456789/reinstall/main
confhome_cn=https://www.ghproxy.cc/https://raw.githubusercontent.com/bin456789/reinstall/main confhome_cn=https://www.ghproxy.cc/https://raw.githubusercontent.com/bin456789/reinstall/main
# confhome_cn=https://jihulab.com/bin456789/reinstall/-/raw/main # confhome_cn=https://jihulab.com/bin456789/reinstall/-/raw/main
# 默认密码
DEFAULT_PASSWORD=123@@@ DEFAULT_PASSWORD=123@@@
# 用于判断 reinstall.sh 和 trans.sh 是否兼容 # 用于判断 reinstall.sh 和 trans.sh 是否兼容
SCRIPT_VERSION=4BACD833-A585-23BA-6CBB-9AA4E08E0002 SCRIPT_VERSION=4BACD833-A585-23BA-6CBB-9AA4E08E0002
# 记录要用到的 windows 程序,运行时输出删除 cr # 记录要用到的 windows 程序,运行时输出删除 \r
WINDOWS_EXES="cmd powershell wmic reg diskpart netsh bcdedit mountvol" WINDOWS_EXES='cmd powershell wmic reg diskpart netsh bcdedit mountvol'
# 强制 linux 程序输出英文,防止 grep 不到想要的内容
# https://www.gnu.org/software/gettext/manual/html_node/The-LANGUAGE-variable.html # https://www.gnu.org/software/gettext/manual/html_node/The-LANGUAGE-variable.html
export LC_ALL=C export LC_ALL=C
@ -1255,12 +1257,11 @@ Continue?
# 很多国内源缺少 aarch64 tumbleweed appliances # 很多国内源缺少 aarch64 tumbleweed appliances
# https://download.opensuse.org/ports/aarch64/tumbleweed/appliances/ # https://download.opensuse.org/ports/aarch64/tumbleweed/appliances/
# https://mirrors.nju.edu.cn/opensuse/ports/aarch64/tumbleweed/appliances/
# https://mirrors.ustc.edu.cn/opensuse/ports/aarch64/tumbleweed/appliances/ # https://mirrors.ustc.edu.cn/opensuse/ports/aarch64/tumbleweed/appliances/
# https://mirrors.tuna.tsinghua.edu.cn/opensuse/ports/aarch64/tumbleweed/appliances/ # https://mirrors.tuna.tsinghua.edu.cn/opensuse/ports/aarch64/tumbleweed/appliances/
if is_in_china; then if is_in_china; then
mirror=https://mirror.sjtu.edu.cn/opensuse mirror=https://mirror.nju.edu.cn/opensuse
else else
mirror=https://ftp.gwdg.de/pub/opensuse mirror=https://ftp.gwdg.de/pub/opensuse
fi fi
@ -2448,7 +2449,7 @@ install_grub_linux_efi() {
curl -Lo $tmp/$grub_efi $mirror/releases/$fedora_ver/Everything/$basearch/os/EFI/BOOT/$grub_efi curl -Lo $tmp/$grub_efi $mirror/releases/$fedora_ver/Everything/$basearch/os/EFI/BOOT/$grub_efi
else else
if is_in_china; then if is_in_china; then
mirror=https://mirror.sjtu.edu.cn/opensuse mirror=https://mirror.nju.edu.cn/opensuse
else else
mirror=https://ftp.gwdg.de/pub/opensuse mirror=https://ftp.gwdg.de/pub/opensuse
fi fi
@ -3638,7 +3639,7 @@ if is_efi; then
fi fi
# 有的机器开启了 kexec例如腾讯云轻量 debian要禁用 # 有的机器开启了 kexec例如腾讯云轻量 debian要禁用
if ! is_in_windows && [ -f /etc/default/kexec ]; then if [ -f /etc/default/kexec ]; then
sed -i 's/LOAD_KEXEC=true/LOAD_KEXEC=false/' /etc/default/kexec sed -i 's/LOAD_KEXEC=true/LOAD_KEXEC=false/' /etc/default/kexec
fi fi
@ -3689,9 +3690,9 @@ if is_need_grub_extlinux; then
if is_in_windows; then if is_in_windows; then
install_grub_win install_grub_win
else else
# linux aarch64 原系统的 grub 可能无法启动 alpine 3.19 的内核 # linux efi 使用外部 grub因为
# 要用去除了内核 magic number 校验的 grub # 1. 原系统 grub 可能没有去除 aarch64 内核 magic number 校验
# 为了方便测试linux x86 efi 也采用外部 grub # 2. 原系统可能不是用 grub
if is_efi; then if is_efi; then
install_grub_linux_efi install_grub_linux_efi
fi fi

View File

@ -1130,10 +1130,17 @@ EOF
install_alpine() { install_alpine() {
info "install alpine" info "install alpine"
hack_lowram_modloop=true need_ram=512
hack_lowram_swap=true swap_size=$(get_need_swap_size $need_ram)
[ "$swap_size" -gt 0 ] && hack_lowram=true || hack_lowram=false
if $hack_lowram_modloop; then # alpine 安装时会自动检测安装需要的 firmware
# https://github.com/alpinelinux/alpine-conf/blob/3.18.1/setup-disk.in#L421
# 但如果没有 modloop 则无法检测
# 所以删除 modloop 前先记录用到的 firmware 包
fw_pkgs=$(get_alpine_firmware_pkgs)
if $hack_lowram; then
# 预先加载需要的模块 # 预先加载需要的模块
if rc-service -q modloop status; then if rc-service -q modloop status; then
modules="ext4 vfat nls_utf8 nls_cp437" modules="ext4 vfat nls_utf8 nls_cp437"
@ -1156,8 +1163,8 @@ install_alpine() {
mount_part_basic_layout /os /os/boot/efi mount_part_basic_layout /os /os/boot/efi
# 创建 swap # 创建 swap
if $hack_lowram_swap; then if $hack_lowram; then
create_swap 256 /os/swapfile create_swap $swap_size /os/swapfile
fi fi
# 网络配置 # 网络配置
@ -1175,7 +1182,7 @@ install_alpine() {
rc-update add hwclock boot rc-update add hwclock boot
# 通过 setup-alpine 安装会启用以下几个服务 # 通过 setup-alpine 安装会启用以下几个服务
# https://github.com/alpinelinux/alpine-conf/blob/c5131e9a038b09881d3d44fb35e86851e406c756/setup-alpine.in#L189 # https://github.com/alpinelinux/alpine-conf/blob/3.18.1/setup-alpine.in#L229
# boot # boot
rc-update add networking boot rc-update add networking boot
@ -1257,10 +1264,9 @@ install_alpine() {
mount_pseudo_fs /os mount_pseudo_fs /os
# setup-disk 会自动选择固件,但不包括微码? # setup-disk 会自动选择固件,但不包括微码?
# https://github.com/alpinelinux/alpine-conf/blob/e18384a85e93c9cad30437a0a06802a3f385e550/setup-disk.in#L421 # https://github.com/alpinelinux/alpine-conf/blob/3.18.1/setup-disk.in#L421
# shellcheck disable=SC2046 if fw_pkgs="$fw_pkgs $(get_ucode_firmware_pkgs)" && [ -n "$fw_pkgs" ]; then
if is_need_ucode_firmware; then chroot /os apk add $fw_pkgs
chroot /os apk add $(get_ucode_firmware_pkgs)
fi fi
# 3.19 或以上,非 efi 需要手动安装 grub # 3.19 或以上,非 efi 需要手动安装 grub
@ -1605,9 +1611,8 @@ EOF
fi fi
# firmware + microcode # firmware + microcode
if is_need_ucode_firmware; then if fw_pkgs=$(get_ucode_firmware_pkgs) && [ -n "$fw_pkgs" ]; then
# shellcheck disable=SC2046 chroot $os_dir pacman -Syu --noconfirm $fw_pkgs
chroot $os_dir pacman -Syu --noconfirm $(get_ucode_firmware_pkgs)
fi fi
# arm 的内核有多种选择,默认是 linux-aarch64所以要添加 --noconfirm # arm 的内核有多种选择,默认是 linux-aarch64所以要添加 --noconfirm
@ -1723,9 +1728,8 @@ EOF
fi fi
# firmware + microcode # firmware + microcode
if is_need_ucode_firmware; then if fw_pkgs=$(get_ucode_firmware_pkgs) && [ -n "$fw_pkgs" ]; then
# shellcheck disable=SC2046 chroot $os_dir emerge $fw_pkgs
chroot $os_dir emerge $(get_ucode_firmware_pkgs)
fi fi
# 安装 grub + 内核 # 安装 grub + 内核
@ -2479,19 +2483,36 @@ restore_resolv_conf() {
fi fi
} }
is_need_ucode_firmware() { # 抄 https://github.com/alpinelinux/alpine-conf/blob/3.18.1/setup-disk.in#L421
! is_virt && [ -n "$(get_ucode_firmware_pkgs)" ] get_alpine_firmware_pkgs() {
# 需要有 modloop不然 modinfo 会报错
ensure_service_started modloop >&2
# 如果不在单独的文件夹,则用 linux-firmware-other
# 如果在单独的文件夹,则用 linux-firmware-xxx
# 如果不需要 firmware则用 linux-firmware-none
firmware_pkgs=$(
cd /sys/module && modinfo -F firmware -- * 2>/dev/null |
awk -F/ '{print $1 == $0 ? "linux-firmware-other" : "linux-firmware-"$1}' |
sort -u
)
# 使用 command 因为自己覆盖了 apk 添加了 >&2
retry 5 command apk search --quiet --exact ${firmware_pkgs:-linux-firmware-none}
} }
get_ucode_firmware_pkgs() { get_ucode_firmware_pkgs() {
is_virt && return
case "$distro" in case "$distro" in
centos | almalinux | rocky | oracle | redhat | anolis | opencloudos | openeuler) os=elol ;; centos | almalinux | rocky | oracle | redhat | anolis | opencloudos | openeuler) os=elol ;;
*) os=$distro ;; *) os=$distro ;;
esac esac
case "$os-$(get_cpu_vendor)" in case "$os-$(get_cpu_vendor)" in
# setup-alpine 会自动选择 firmware # alpine 的 linux-firmware 以文件夹进行拆分
# https://github.com/alpinelinux/alpine-conf/blob/e18384a85e93c9cad30437a0a06802a3f385e550/setup-disk.in#L421 # setup-alpine 会自动安装需要的 firmwaremodloop 没挂载则无效)
# https://github.com/alpinelinux/alpine-conf/blob/3.18.1/setup-disk.in#L421
alpine-intel) echo intel-ucode ;; alpine-intel) echo intel-ucode ;;
alpine-amd) echo amd-ucode ;; alpine-amd) echo amd-ucode ;;
alpine-*) ;; alpine-*) ;;
@ -2568,10 +2589,9 @@ EOF
cp_resolv_conf $os_dir cp_resolv_conf $os_dir
disable_selinux_kdump $os_dir disable_selinux_kdump $os_dir
if is_need_ucode_firmware; then if fw_pkgs=$(get_ucode_firmware_pkgs) && [ -n "$fw_pkgs" ]; then
is_have_cmd_on_disk $os_dir dnf && mgr=dnf || mgr=yum is_have_cmd_on_disk $os_dir dnf && mgr=dnf || mgr=yum
# shellcheck disable=SC2046 chroot $os_dir $mgr install -y $fw_pkgs
chroot $os_dir $mgr install -y $(get_ucode_firmware_pkgs)
fi fi
restore_resolv_conf $os_dir restore_resolv_conf $os_dir
@ -2640,7 +2660,7 @@ EOF
fi fi
# 微码+固件 # 微码+固件
if is_need_ucode_firmware; then if fw_pkgs=$(get_ucode_firmware_pkgs) && [ -n "$fw_pkgs" ]; then
# debian 10 11 的 iucode-tool 在 contrib 里面 # debian 10 11 的 iucode-tool 在 contrib 里面
# debian 12 的 iucode-tool 在 main 里面 # debian 12 的 iucode-tool 在 main 里面
[ "$releasever" -ge 12 ] && [ "$releasever" -ge 12 ] &&
@ -2661,8 +2681,7 @@ EOF
fi fi
done done
# shellcheck disable=SC2046 chroot_apt_install $os_dir $fw_pkgs
chroot_apt_install $os_dir $(get_ucode_firmware_pkgs)
fi fi
if [ "$releasever" -le 11 ]; then if [ "$releasever" -le 11 ]; then
@ -2720,9 +2739,8 @@ EOF
chroot $os_dir zypper remove -y kernel-default-base chroot $os_dir zypper remove -y kernel-default-base
# 固件+微码 # 固件+微码
if is_need_ucode_firmware; then if fw_pkgs=$(get_ucode_firmware_pkgs) && [ -n "$fw_pkgs" ]; then
# shellcheck disable=SC2046 chroot $os_dir zypper install -y $fw_pkgs
chroot $os_dir zypper install -y $(get_ucode_firmware_pkgs)
fi fi
# 选择新内核 # 选择新内核
@ -3355,9 +3373,8 @@ install_qcow_by_copy() {
fi fi
# firmware + microcode # firmware + microcode
if is_need_ucode_firmware; then if fw_pkgs=$(get_ucode_firmware_pkgs) && [ -n "$fw_pkgs" ]; then
# shellcheck disable=SC2046 chroot_dnf install $fw_pkgs
chroot_dnf install $(get_ucode_firmware_pkgs)
fi fi
# 删除云镜像自带的 dhcp 配置,防止歧义 # 删除云镜像自带的 dhcp 配置,防止歧义
@ -3544,9 +3561,8 @@ EOF
fi fi
# 安装固件+微码 # 安装固件+微码
if is_need_ucode_firmware; then if fw_pkgs=$(get_ucode_firmware_pkgs) && [ -n "$fw_pkgs" ]; then
# shellcheck disable=SC2046 chroot_apt_install $os_dir $fw_pkgs
chroot_apt_install $os_dir $(get_ucode_firmware_pkgs)
fi fi
# 16.04 镜像用 ifupdown/networking 管理网络 # 16.04 镜像用 ifupdown/networking 管理网络