You are not logged in.

#1 2023-02-10 16:38:43

GTP
Member
Registered: 2016-10-22
Posts: 14

[Solved] Generated grub.cfg.new contains ^M characters

TL;DR: when I generate my grub.cfg with grub-mkconfig it fails complaining about a syntax error. If I inspect the generated grub.cfg.new I see a bunch of ^M characters, and if I manually remove them and substitute my current config with the manually edited one it works, but I don't know where those characters are coming from.

Greetings,

I was doing some grub customizations using grub-customizer. At a certain point I wanted to change the position of one of the boot entries, but after changing its position and trying to save the configuration the generation of the new grub config failed. I put the menu entry back in the original position and it worked again. Then I noticed that I had a duplicated entry for the UEFI settings. One is the default grub's one, the other was one that I added manually years ago. So I tried to use grub-customizer again to remove one of the two, but regardless of which one I tried to remove, saving the new configuration failed again, due to a syntax error. Due to the strange behavior of grub-customizer, I decided to give up on it and do it manually. So I edited /etc/grub.d/proxifiedScripts/custom to remove the menu entry for the UEFI settings that I added manually, and then tried to generate the config with grub-mkconfig, which failed again due to a syntax error on line 200, you can see the command's output here:

$ sudo grub-mkconfig -o /tmp/grub.cfg
[sudo] password di giacomo: 
Generating grub configuration file ...
Found theme: /boot/grub/themes/minegrub-theme/theme.txt
Found linux image: /boot/vmlinuz-linux
Found initrd image: /boot/intel-ucode.img /boot/initramfs-linux.img
Found fallback initrd image(s) in /boot:  intel-ucode.img initramfs-linux-fallback.img
Warning: os-prober will be executed to detect other bootable partitions.
Its output will be used to detect bootable binaries on them and create new boot entries.
Found Windows Boot Manager on /dev/sda1@/efi/Microsoft/Boot/bootmgfw.efi
Found Windows Boot Manager on /dev/sdb8@/efi/Microsoft/Boot/bootmgfw.efi
Adding boot menu entry for UEFI Firmware Settings ...
Adding boot menu entry for UEFI Firmware Settings ...
errore: syntax error.
errore: Incorrect command.
errore: syntax error.
Errore di sintassi alla riga 200
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
/tmp/grub.cfg.new file attached.

By inspecting the generated file, I see that there are a bunch of ^M around that line (but also in other places), and if I remove those and use the edited file as my config grub works correctly. But I don't know where those characters are coming from, lines 194-201 are about the 31_uefi-firmwarre_proxy script, but there aren't ^M in there. Any idea how I can fix this?
here you can find the generated grub.cfg.new, and here is my 31_uefi-firmwarre_proxy script.
Thank you for your help,

GTP

Last edited by GTP (2023-02-12 21:20:18)

Offline

#2 2023-02-10 18:22:32

schard
Forum Moderator
From: Hannover
Registered: 2016-05-06
Posts: 2,002
Website

Re: [Solved] Generated grub.cfg.new contains ^M characters

Why do you have DOS encoded files on your system? Find them, presumably in /etc/default/grub and dos2unix them.


macro_rules! yolo { { $($tokens:tt)* } => { unsafe { $($tokens)* } }; }

Offline

#3 2023-02-10 18:27:27

GTP
Member
Registered: 2016-10-22
Posts: 14

Re: [Solved] Generated grub.cfg.new contains ^M characters

This is a very good question and I have no idea why, or if that's the case at all, since the ^M didn't happen at every new line but only on some of those. But how can I find DOS-encoded files? Can I use find to look for text files containing ^M?

Offline

#4 2023-02-10 18:35:50

schard
Forum Moderator
From: Hannover
Registered: 2016-05-06
Posts: 2,002
Website

Re: [Solved] Generated grub.cfg.new contains ^M characters

^M is just the representation of \r in some text editors. You'll have to search for files containing lines ending with \r\n


macro_rules! yolo { { $($tokens:tt)* } => { unsafe { $($tokens)* } }; }

Offline

#5 2023-02-10 18:48:09

GTP
Member
Registered: 2016-10-22
Posts: 14

Re: [Solved] Generated grub.cfg.new contains ^M characters

Yes, but do you know how I can automatically look for those?

Offline

#6 2023-02-10 18:53:09

Head_on_a_Stick
Member
From: London
Registered: 2014-02-20
Posts: 7,771
Website

Re: [Solved] Generated grub.cfg.new contains ^M characters

Just get rid of grub-customizer. It's awful.

Offline

#7 2023-02-10 19:34:24

GTP
Member
Registered: 2016-10-22
Posts: 14

Re: [Solved] Generated grub.cfg.new contains ^M characters

Ok, but now the problem is that grub-mkconfig is generating a file containing ^M, even when I invoke it manually without using grub-customizer.

Offline

#8 2023-02-10 19:44:58

Head_on_a_Stick
Member
From: London
Registered: 2014-02-20
Posts: 7,771
Website

Re: [Solved] Generated grub.cfg.new contains ^M characters

Hmm, sorry, looks like I was wrong. Oops.

Use this to find the offending file(s):

# find /etc ! -type d -exec file "{}" \; | grep CRLF

EDIT: narrowed search to /etc/, no need to look around the entire filesystem.

Last edited by Head_on_a_Stick (2023-02-10 19:46:46)

Offline

#9 2023-02-12 18:43:13

GTP
Member
Registered: 2016-10-22
Posts: 14

Re: [Solved] Generated grub.cfg.new contains ^M characters

Thank you Head_on_a_Stick for the onliner, I ran it as root and this is the result:

[root@lenovo ~]# find /etc ! -type d -exec file "{}" \; | grep CRLF
/etc/foldingathome/config.xml.pacsave: exported SGML document, ASCII text, with CRLF line terminators

So the only file with DOS-style line termination isn't related at all to GRUB sad
Do you have any other idea on what might be the cause of this issue?
Thank you for your help,

GTP

Offline

#10 2023-02-12 18:50:37

schard
Forum Moderator
From: Hannover
Registered: 2016-05-06
Posts: 2,002
Website

Re: [Solved] Generated grub.cfg.new contains ^M characters

Weird. What happens when you delete /boot/grub/grub.cfg first and then run grub-mkconfig?


macro_rules! yolo { { $($tokens:tt)* } => { unsafe { $($tokens)* } }; }

Offline

#11 2023-02-12 19:05:32

GTP
Member
Registered: 2016-10-22
Posts: 14

Re: [Solved] Generated grub.cfg.new contains ^M characters

Still the same problem, here is the full output:

[root@lenovo ~]# mv /boot/grub/grub.cfg /boot/grub/grub.cfg.bak 
[root@lenovo ~]# grub-mkconfig -o /boot/grub/grub.cfg
Generating grub configuration file ...
Found theme: /boot/grub/themes/minegrub-theme/theme.txt
Found linux image: /boot/vmlinuz-linux
Found initrd image: /boot/intel-ucode.img /boot/initramfs-linux.img
Found fallback initrd image(s) in /boot:  intel-ucode.img initramfs-linux-fallback.img
Warning: os-prober will be executed to detect other bootable partitions.
Its output will be used to detect bootable binaries on them and create new boot entries.
Found Windows Boot Manager on /dev/sda1@/efi/Microsoft/Boot/bootmgfw.efi
Found Windows Boot Manager on /dev/sdb8@/efi/Microsoft/Boot/bootmgfw.efi
Adding boot menu entry for UEFI Firmware Settings ...
Adding boot menu entry for UEFI Firmware Settings ...
errore: syntax error.
errore: Incorrect command.
errore: syntax error.
Errore di sintassi alla riga 200
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.

And here you can find the generated grub.cfg.new.

Offline

#12 2023-02-12 19:55:55

Head_on_a_Stick
Member
From: London
Registered: 2014-02-20
Posts: 7,771
Website

Re: [Solved] Generated grub.cfg.new contains ^M characters

GTP wrote:

And here you can find the generated grub.cfg.new.

That's a very annoying way to share files. Please use a pastebin site instead, preferably one without adverts and javascript. See the "Applications" ArchWIki page for some sensible suggestions.

grub.cfg.new wrote:
### BEGIN /etc/grub.d/30_os-prober_proxy ###
[...]
### BEGIN /etc/grub.d/31_uefi-firmware_proxy ###
[...]
### BEGIN /etc/grub.d/45_custom_proxy ###

Those files appear to be the cause of the aberrant CRLF characters. From where did you obtain them? There are also other files not supplied by any official packages (/etc/grub.d/{42_grml,44_uefi-firmware_proxy}).

Check

pacman -Qk grub

Looks like /etc/grub.d/30_os-prober is missing. Did you edit and re-name the file?

The specific error:

GTP wrote:
Errore di sintassi alla riga 200

Is caused by the incomplete if clause in /etc/grub.d/31_uefi-firmware_proxy. I've seen that before: https://bbs.archlinux.org/viewtopic.php?id=283281

As I said earlier, you should remove grub-customizer. It's messing things up even when not invoked. You should probably also file a bug against that package. IMO it shouldn't even be in the repositories. It's a POS.

EDIT: I wish I could type :-(

Last edited by Head_on_a_Stick (2023-02-12 20:10:22)

Offline

#13 2023-02-12 21:02:20

GTP
Member
Registered: 2016-10-22
Posts: 14

Re: [Solved] Generated grub.cfg.new contains ^M characters

Head_on_a_Stick, you were totally right.
I first run pacman, and it complained about three missing files:

$ pacman -Qk grub
attenzione: grub: /etc/grub.d/30_os-prober (File o directory non esistente)
attenzione: grub: /etc/grub.d/30_uefi-firmware (File o directory non esistente)
attenzione: grub: /etc/grub.d/40_custom (File o directory non esistente)
grub: 1112 file totali, mancano 3 file

Then I uninstalled grub-customizer, and grub-mkconfig started working again.

However pacman still says there are 3 missing files, should I reinstall grub?

Sorry about the way I shared the config files, I know it isn't ideal. But since the issue was about line endings if I shared those on a pastebin site the actual line termination characters would have been lost. I'll try to file a bug report about grub-customizer.

Offline

#14 2023-02-12 21:08:03

Head_on_a_Stick
Member
From: London
Registered: 2014-02-20
Posts: 7,771
Website

Re: [Solved] Generated grub.cfg.new contains ^M characters

GTP wrote:

should I reinstall grub?

Yes. That should replace the missing files.

Offline

#15 2023-02-12 21:19:47

GTP
Member
Registered: 2016-10-22
Posts: 14

Re: [Solved] Generated grub.cfg.new contains ^M characters

Indeed, now according to pacman all files are there. Thank you very much for your help!

Offline

Board footer

Powered by FluxBB