From cc7d3a6b454fad2b11438a1beb1052a8b0109d92 Mon Sep 17 00:00:00 2001 From: bin456789 Date: Thu, 22 Aug 2024 00:03:38 +0800 Subject: [PATCH] =?UTF-8?q?nixos:=20=E4=B8=8D=E4=BD=BF=E7=94=A8=20grub-mkc?= =?UTF-8?q?onfig?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit grub-mkconfig -o /boot/grub/grub.cfg 会丢失系统启动条目 --- reinstall.sh | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/reinstall.sh b/reinstall.sh index 9ec1386..0647f8a 100644 --- a/reinstall.sh +++ b/reinstall.sh @@ -3224,7 +3224,21 @@ if is_use_grub; then else error_and_exit "grub not found" fi - $grub-mkconfig -o $grub_cfg + + # nixos 手动执行 grub-mkconfig -o /boot/grub/grub.cfg 会丢失系统启动条目 + # 正确的方法是修改 configuration.nix 的 boot.loader.grub.extraEntries + # 但是修改 configuration.nix 不是很好,因此改成修改 grub.cfg + if [ -x /nix/var/nix/profiles/system/bin/switch-to-configuration ]; then + # 生成 grub.cfg + /nix/var/nix/profiles/system/bin/switch-to-configuration boot + # 手动启用 41_custom + nixos_grub_home="$(dirname "$(readlink -f "$(get_cmd_path grub-mkconfig)")")/.." + $nixos_grub_home/etc/grub.d/41_custom >>$grub_cfg + elif is_have_cmd update-grub; then + update-grub + else + $grub-mkconfig -o $grub_cfg + fi fi # 选择用 custom.cfg (linux-bios) 还是 grub.cfg (win/linux-efi)