Syntax error in grub.cfg on update-grub

I run Ubuntu 20.04 and have this error when I do an update-grub command:

root@ubuntu:/# update-grub
Sourcing file `/etc/default/grub'
Sourcing file `/etc/default/grub.d/init-select.cfg'
Création du fichier de configuration GRUB…
Image Linux trouvée : /boot/vmlinuz-5.8.0-25-generic
Image mémoire initiale trouvée : /boot/initrd.img-5.8.0-25-generic
Image Linux trouvée : /boot/vmlinuz-5.4.0-53-generic
CentOS Linux 8 (Core) trouvé sur /dev/sdb9
Image Linux trouvée : /boot/vmlinuz-5.8.0-25-generic
Image mémoire initiale trouvée : /boot/initrd.img-5.8.0-25-generic
Image Linux trouvée : /boot/vmlinuz-5.4.0-53-generic
CentOS Linux 8 (Core) trouvé sur /dev/sdb9
Image Linux trouvée : /boot/vmlinuz-5.8.0-25-generic
Image mémoire initiale trouvée : /boot/initrd.img-5.8.0-25-generic
Image Linux trouvée : /boot/vmlinuz-5.4.0-53-generic
Image Linux trouvée : /boot/vmlinuz-5.8.0-25-generic
Image mémoire initiale trouvée : /boot/initrd.img-5.8.0-25-generic
Image Linux trouvée : /boot/vmlinuz-5.4.0-53-generic
CentOS Linux 8 (Core) trouvé sur /dev/sdb9
Image Linux trouvée : /boot/vmlinuz-5.8.0-25-generic
Image mémoire initiale trouvée : /boot/initrd.img-5.8.0-25-generic
Image Linux trouvée : /boot/vmlinuz-5.4.0-53-generic
Adding boot menu entry for UEFI Firmware Settings
erreur : syntax error.
erreur : Incorrect command.
erreur : syntax error.
erreur : Incorrect command.
erreur : syntax error.
Erreur de syntaxe à la ligne 159
Des erreurs de syntaxe sont détectées dans le fichier de configuration
de GRUB. Veuillez vérifier qu'il n'y a pas d'erreur dans les fichiers
/etc/default/grub et /etc/grub.d/*. Sinon veuillez signaler un bogue
en joignant le fichier /boot/grub/grub.cfg.new.

I checked the file /boot/grub/grub.cfg.new at line 159 as suggested, and here is the snippet corresponding to the line and its surroundings:

152 ### END /etc/grub.d/31_linux_xen ###
153 
154 ### BEGIN /etc/grub.d/34_memtest86+ ###
155 ### END /etc/grub.d/34_memtest86+ ###
156 
157 ### BEGIN /etc/grub.d/35_os-prober_proxy ###
158 submenu "Options avancées pour Ubuntu"{
159 function gfxmode {
160         set gfxpayload="${1}"
161         if [ "${1}" = "keep" ]; then
162                 set vt_handoff=vt.handoff=7
163         else
164                 set vt_handoff=
165         fi
166 }
167 if [ "${recordfail}" != 1 ]; then
168   if [ -e ${prefix}/gfxblacklist.txt ]; then
169     if hwmatch ${prefix}/gfxblacklist.txt 3; then
170       if [ ${match} = 0 ]; then
171         set linux_gfx_mode=keep
172       else
173         set linux_gfx_mode=text
174       fi
175     else
176       set linux_gfx_mode=text
177     fi
178   else
179     set linux_gfx_mode=keep
180   fi
181 else
182   set linux_gfx_mode=text
183 fi
184 export linux_gfx_mode

I can see that there seems to be a problem with line 158 submenu "Options avancées pour Ubuntu"{ which never closes its "{" but I am unable to find where this comes from…

I already tried running boot-repair (as suggested on this answer GRUB error: syntax error. error: Incorrect command)
but the first command asked to launch is:
sudo chroot "/mnt/boot-sav/mapper/isw_cbgbbifgbg_Volume1p2" dpkg --configure -a
and it gives me the same problem of syntax error.

Asked By: Gabriel Cretin

||

The update-grub command executes grub-mkconfig -o /boot/grub/grub.cfg "$@", which in turn executes the scripts in directory /etc/grub.d/. Those scripts create the contents of grub.cfg, and the comment lines like

### BEGIN /etc/grub.d/35_os-prober_proxy ###

will indicate which script is responsible for each part of the grub.cfg file.

In your case, you should probably investigate the /etc/grub.d/35_os-prober_proxy script, and possibly the scripts immediately after it in the directory (in default ASCII alphanumberical sorting order).

On the other hand, in my Debian 10 system, the function gfxmode { line is part of the output of /etc/grub.d/10_linux, which is responsible for generating the plain Linux boot entries, then there is another script 20_linux_xen to create boot entries for Xen-style virtualization if it’s installed, and then 30_os-prober to detect and add boot entries for other operating systems. Apparently Ubuntu does things somewhat differently, but it makes me suspect the parts of grub.cfg may have been produced out of order somehow.

Answered By: telcoM

With

  • debian trixie
  • grub-customizer 5.2.3

Run:

sudo cp /boot/grub/grub.cfg.new /. # put your home path here
sudo rm /boot/grub/grub.cfg.new
grub-customizer 

Then push the revert button (right-upper position) and apply.

Categories: Answers Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.