mirror of
https://github.com/bin456789/reinstall.git
synced 2025-01-18 20:39:14 +08:00
特殊处理外部 grub 引导的机器,例如 cloudcone
This commit is contained in:
parent
d821d5b541
commit
cfd2421462
@ -157,7 +157,12 @@ d-i partman/early_command string true; \
|
||||
|
||||
# debian 10 没有 /target/etc/ssh/sshd_config.d/ 文件夹
|
||||
# kali ssh 默认关闭
|
||||
# 另一种方法处理 cloudcone
|
||||
# if [ "$link_grub_dir" = 1 ]; then mkdir /target/boot/grub2; echo 'chainloader (hd0)+1' >/target/boot/grub2/grub.cfg; fi; \
|
||||
d-i preseed/late_command string true; \
|
||||
link_grub_dir="$(grep -o 'extra\.link_grub_dir=[^ ]*' /proc/cmdline | cut -d= -f2)"; \
|
||||
if [ "$link_grub_dir" = 1 ]; then ln -s grub /target/boot/grub2; fi; \
|
||||
|
||||
in-target systemctl enable ssh; \
|
||||
echo "PermitRootLogin yes" >/target/etc/ssh/sshd_config.d/01-permitrootlogin.conf || \
|
||||
echo "PermitRootLogin yes" >>/target/etc/ssh/sshd_config
|
||||
|
54
reinstall.sh
54
reinstall.sh
@ -1435,6 +1435,14 @@ is_efi() {
|
||||
fi
|
||||
}
|
||||
|
||||
is_grub_dir_linked() {
|
||||
# cloudcone 重装前/重装后(方法1)
|
||||
[ "$(readlink -f /boot/grub/grub.cfg)" = /boot/grub2/grub.cfg ] ||
|
||||
[ "$(readlink -f /boot/grub2/grub.cfg)" = /boot/grub/grub.cfg ] ||
|
||||
# cloudcone 重装后(方法2)
|
||||
{ [ -f /boot/grub2/grub.cfg ] && [ "$(cat /boot/grub2/grub.cfg)" = 'chainloader (hd0)+1' ]; }
|
||||
}
|
||||
|
||||
is_secure_boot_enabled() {
|
||||
if is_efi; then
|
||||
if is_in_windows; then
|
||||
@ -1919,6 +1927,11 @@ build_extra_cmdline() {
|
||||
elif [ -n "$nextos_mirrorlist" ]; then
|
||||
extra_cmdline+=" extra.mirrorlist='$nextos_mirrorlist'"
|
||||
fi
|
||||
|
||||
# cloudcone 特殊处理
|
||||
if is_grub_dir_linked; then
|
||||
finalos_cmdline+=" extra.link_grub_dir=1"
|
||||
fi
|
||||
}
|
||||
|
||||
echo_tmp_ttys() {
|
||||
@ -2961,10 +2974,49 @@ if is_use_grub; then
|
||||
fi
|
||||
fi
|
||||
|
||||
# cloudcone 从光驱的 grub 启动,再加载硬盘的 grub.cfg
|
||||
# menuentry "Grub 2" --id grub2 {
|
||||
# set root=(hd0,msdos1)
|
||||
# configfile /boot/grub2/grub.cfg
|
||||
# }
|
||||
|
||||
# 加载后 $prefix 依然是光驱的 (hd96)/boot/grub
|
||||
# 导致找不到 $prefix 目录的 grubenv,因此读取不到 next_entry
|
||||
# 以下方法为 cloudcone 重新加载 grubenv
|
||||
|
||||
# 需查找 2*2 个文件夹
|
||||
# 分区:系统 / boot
|
||||
# 文件夹:grub / grub2
|
||||
# shellcheck disable=SC2121,SC2154
|
||||
# cloudcone debian 能用但 ubuntu 模板用不了
|
||||
# ubuntu 模板甚至没显示 reinstall menuentry
|
||||
load_grubenv_if_not_loaded() {
|
||||
if ! [ -s $prefix/grubenv ]; then
|
||||
for dir in /boot/grub /boot/grub2 /grub /grub2; do
|
||||
set grubenv="($root)$dir/grubenv"
|
||||
if [ -s $grubenv ]; then
|
||||
load_env --file $grubenv
|
||||
if [ "${next_entry}" ]; then
|
||||
set default="${next_entry}"
|
||||
set next_entry=
|
||||
save_env --file $grubenv next_entry
|
||||
else
|
||||
set default="0"
|
||||
fi
|
||||
return
|
||||
fi
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
# 生成 grub 配置
|
||||
# 实测 centos 7 lvm 要手动加载 lvm 模块
|
||||
echo $target_cfg
|
||||
del_empty_lines <<EOF | tee $target_cfg
|
||||
|
||||
get_function_content load_grubenv_if_not_loaded >$target_cfg
|
||||
|
||||
del_empty_lines <<EOF | tee -a $target_cfg
|
||||
set timeout_style=menu
|
||||
set timeout=5
|
||||
menuentry "$(get_entry_name)" {
|
||||
$(! is_in_windows && echo 'insmod lvm')
|
||||
|
Loading…
x
Reference in New Issue
Block a user