From b9b447c15a057a0d78f8cf17ae904659e1381cc4 Mon Sep 17 00:00:00 2001 From: bin456789 Date: Sun, 30 Jul 2023 00:32:05 +0800 Subject: [PATCH] =?UTF-8?q?core:=20=E4=BF=AE=E6=94=B9=20grub.cfg=20?= =?UTF-8?q?=E6=9F=A5=E6=89=BE=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- reinstall.sh | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/reinstall.sh b/reinstall.sh index 9ac41a0..ebecc9f 100644 --- a/reinstall.sh +++ b/reinstall.sh @@ -897,19 +897,23 @@ build_cmdline info 'create grub config' # linux grub if ! is_in_windows; then - # 找到主配置 grub.cfg - if ! is_efi; then - except_efi=(-not -path '/boot/efi/*') + # 找出主配置文件(含有menuentry|blscfg) + # 如果是efi,先搜索efi目录 + if is_efi; then + efi_dir='/boot/efi' fi - grub_cfg=$(find /boot -type f -name grub.cfg "${except_efi[@]}" -exec grep -E -l 'menuentry|blscfg' {} \;) + grub_cfg=$( + find $efi_dir /boot/grub* \ + -type f -name grub.cfg \ + -exec grep -E -l 'menuentry|blscfg' {} \; | xargs -0 | head -1 + ) # 在x86 efi机器上,不同版本的 grub 可能用 linux 或 linuxefi 加载内核 # 通过检测原有的条目有没有 linuxefi 字样就知道当前 grub 用哪一种 - search_files=$(find /boot -type f -name grub.cfg) if [ -d /boot/loader/entries/ ]; then - search_files+=" /boot/loader/entries/" + entries="/boot/loader/entries/" fi - if grep -q -r -E '^[[:blank:]]*linuxefi[[:blank:]]' $search_files; then + if grep -q -r -E '^[[:blank:]]*linuxefi[[:blank:]]' $grub_cfg $entries; then efi=efi fi fi