2

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.

  • When it has errors, it writes grub.cfg.new. What does line 145 show. When I had that error, I had left off a closing } in my 40_custom and error line was end of file, so took a bit to find it. It will recreate the .new file with another grub-update. – oldfred Dec 28 '19 at 20:18
  • @oldfred Thank you, I no long have access to the file. It disappeared upon successful resolution and I didn't think to back it up. Regardless I think my answer is easier than hunting for code errors in all the grub.d files. – Elder Geek Dec 28 '19 at 20:39
  • 1
    That also works, as it resets everything back to grub defaults. – oldfred Dec 28 '19 at 22:24
2

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.