8

This error originally occurred during an apt upgrade but I managed to reproduce it with 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.

I perused /etc/default/grub and /etc/grub.d/* files and didn't find any obvious errors.

During my search for information I found https://unix.stackexchange.com/questions/209152/syntax-error-in-grub-cfg-on-update-grub-grub-2-memtest86 but the excellent troubleshooting steps there didn't result in a solution for me. Sadly I failed to backup /boot/grub/grub.cfg.new prior to resolving the problem so I cannot provide a copy, all I recall is that the error was reported on line 145 and there were not any issues that I could see with the if - fi code block in the area of that line.

Elder Geek
  • 36,752

1 Answers1

5

Since I was able to access the system despite the error, I didn't have to chroot into it which will be necessary if you cannot boot into the system. What I did was purge and reinstall grub which did the trick.

The steps I used are as follows:

  1. I confirmed that I had an internet connection with sudo apt-get update # ***
  2. I purged grub-pc and grub-common with sudo apt-get purge grub-pc grub-common
  3. I read the warning about removing the bootloader, hit TAB to highlight "OK" and pressed ENTER.
  4. I issued the command apt-get install grub-common grub-pc and when prompted I hit TAB to highlight "" and pressed ENTER
  5. When presented with the device option, I used the UP/DN keys to select the correct drive (sdX) NOT a partition.

    I made sure the installation drive [] /dev/sdX had an asterisk next to it ( in my case: [] /dev/sda ). If it doesn't, highlight it and press the SPACE bar to select it. Then I hit TAB to highlight "OK" and pressed ENTER

    I tested that the installation was complete and working by issuing the command sudo update-grub and everything worked error free as expected.

Sources: https://ubuntuforums.org/showthread.php?t=1581099

Elder Geek
  • 36,752