GRUB 更新期间出错。在生成的 GRUB 配置文件中检测到语法错误

Eld*_*eek 7 xubuntu grub2 18.04

这个错误最初发生在 apt 升级期间,但我设法重现它update grub

sudo update-grub
[sudo] password for me: 
Sourcing file `/etc/default/grub'
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-4.15.0-72-generic
Found initrd image: /boot/initrd.img-4.15.0-72-generic
Found linux image: /boot/vmlinuz-4.15.0-60-generic
Found initrd image: /boot/initrd.img-4.15.0-60-generic
Found linux image: /boot/vmlinuz-4.15.0-20-generic
Found initrd image: /boot/initrd.img-4.15.0-20-generic
Found memtest86+ image: /boot/memtest86+.elf
Found memtest86+ image: /boot/memtest86+.bin
error: syntax error.
error: Incorrect command.
error: syntax error.
Syntax error at line 145
Syntax errors are detected in generated GRUB config file.
Ensure that there are no errors in /etc/default/grub
and /etc/grub.d/* files or please file a bug report with
/boot/grub/grub.cfg.new file attached.
Run Code Online (Sandbox Code Playgroud)

我仔细阅读/etc/default/grub了 /etc/grub.d/* 文件,没有发现任何明显的错误。

在搜索信息期间,我发现了https://unix.stackexchange.com/questions/209152/syntax-error-in-grub-cfg-on-update-grub-grub-2-memtest86,但是那里出色的故障排除步骤并没有' t 为我提供解决方案。遗憾的是,在解决问题之前,我未能备份 /boot/grub/grub.cfg.new,因此我无法提供副本,我只记得该错误是在第 145 行报告的,并且我没有看到任何问题该行区域中的 if - fi 代码块。

Eld*_*eek 5

由于尽管出现错误,我仍然能够访问系统,因此我不必 chroot 进入它,如果您无法启动进入系统,则需要 chroot。我所做的就是清除并重新安装 grub,这就成功了。

我使用的步骤如下:

  1. 我确认我已连接到互联网sudo apt-get update # ***
  2. 我清除了 grub-pc 和 grub-commonsudo apt-get purge grub-pc grub-common
  3. 我阅读了有关删除引导加载程序的警告,点击突出TAB显示“确定”并按下ENTER
  4. 我发出命令apt-get install grub-common grub-pc,当出现提示时,我点击TAB突出显示“”并按下ENTER
  5. 当出现设备选项时,我使用 UP/DN 键选择正确的驱动器 (sdX),而不是分区。

    我确保安装驱动器 [ ] /dev/sdX 旁边有一个星号(在我的例子中: [ ] /dev/sda )。如果没有,请突出显示它并按空格键将其选中。然后我点击TAB突出显示“确定”并按下ENTER

    我通过发出命令测试安装是否已完成并正常工作sudo update-grub,一切都按预期正常运行。

资料来源:https ://ubuntuforums.org/showthread.php?t=1581099