[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Help! syntax error when using grub2-mkconfig -o /boot/grub2/grub.cfg

From: Jordan Uggla
Subject: Re: Help! syntax error when using grub2-mkconfig -o /boot/grub2/grub.cfg in Fedora 17
Date: Wed, 18 Jul 2012 10:26:20 -0700

On Wed, Jul 18, 2012 at 1:44 AM, Ford Han <address@hidden> wrote:
> Hi, I come across syntax error when using grub2-mkconfig -o
> /boot/grub2/grub.cfg in Fedora 17, pls help!!!
> The following is the whole process:
> 1. I installed Win7 first, and then Ubuntu 12.04 LTS, at this time grub can
> correctly find win7 and Ubuntu and both can boot.
> Finally I installed Fedora 17. Now Grub can now detect Win7 and Fedora and
> both can boot too. But Ubuntu is not in the boot list. I want to show all of
> the three systems in the list.
> 2. I try to boot the Ubuntu with commands in GRUB2 boot prompts following
> the steps in section Encountering the dreaded GRUB 2 boot prompt at
> I used the following commands according to my situation, and all commands
> succeed and Ubuntu boot normally. (hd0,7) is the root partition for Ubuntu
> and (hd0,6) is the /boot partition.
> set root=(hd0,7)
> linux   (hd0,6)/vmlinuz-3.2.0-26-generic-pae root=/dev/sda7 ro quiet splash
> $vt_handoff
> initrd  (hd0,6)/initrd.img-3.2.0-26-generic-pae
> 3. I want to modify the grub.cfg to show all the three systems in the boot
> list.
> 1). I boot into Fedora17, I add one file named 15_Ubuntu in the directory
> /etc/grub.d. Below is its content. All the commands are same as what I used
> in grub2 boot prompt above.
> #!/bin/sh -e
> exec tail -n +3 $0
> # This file provides an easy way to add custom menu entries.  Simply type
> the
> # menu entries you want to add after this comment.  Be careful not to change
> # the 'exec tail' line above.

As the comment above explains, you need to simply enter the menu entry
you want after the comment with nothing else. Everything after the
second line in the file will be added directly to the grub.cfg, and
therefore everything after the second line needs to be valid grub

> echo "Adding Ubuntu to GRUB 2"
> cat << EOF

As grub-script does not have here documents (yet) this is where your
syntax error is. Even if here documents were supported by grub, this
code would print the menu entry to the screen at boot, not actually
create a menu entry. Similarly, the echo command above would have been
executed at boot, not during grub-mkconfig.

> menuentry "Ubuntu, with Linux 3.2.0-26-generic-pae" {
> set root=(hd0,7)
> linux   (hd0,6)/vmlinuz-3.2.0-26-generic-pae root=/dev/sda7 ro quiet splash
> $vt_handoff
> initrd  (hd0,6)/initrd.img-3.2.0-26-generic-pae
> }
> 2). Then I use the grub2-mkconfig command to re-create the grub.cfg file:
> grub2-mkconfig -o /boot/grub2/grub.cfg
> The output says there are errors:
> Generating grub.cfg ...
> Found linux image: /boot/vmlinuz-3.4.4-5.fc17.i686
> Found initrd image: /boot/initramfs-3.4.4-5.fc17.i686.img
> Found linux image: /boot/vmlinuz-3.3.4-5.fc17.i686
> Found initrd image: /boot/initramfs-3.3.4-5.fc17.i686.img
>   No volume groups found
> Found Windows 7 (loader) on /dev/sda1
> Found Windows 7 (loader) on /dev/sda2
> error: syntax error.
> error: Incorrect command.
> error: syntax error.
> Syntax error at line 175
> 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/grub2/ file attached.done
> These commands have been verified in GRUB 2 boot prompts. I do not know
> which line is line 175 and where is the specific error.

You can see what is on line 175 by looking at the file,

> 3). If I remove the newly added file 15_Ubuntu from directory /etc/grub.d
> and grub2-mkconfig again, the output has no error messages.

Which is expected since that is what is generating invalid syntax.

I would recommend adding your custom entries to
/boot/grub2/custom.cfg, creating the file if it doesn't already exist.
This file isn't checked for syntax errors when grub-mkconfig is run
(and you don't need to re-run grub-mkconfig after adding or changing
it) but you can check it yourself by running "grub-script-check

Jordan Uggla (Jordan_U on

reply via email to

[Prev in Thread] Current Thread [Next in Thread]