Editing tools for /boot/grub2/grub.cfg

Most postings advise against editing grub.cfg
I’d like to remove a couple options from the menu.

Are there any good tools to do this instead of vi ??

I see that line 185 is “menuentry 'openSUSE”
and line 206 is “menuentry 'openSUSE”

Could I just use vi to delete lines 185-205 ??

That is not universal, for example mine has different code at those lines you quoted because I have added an entry via 40_custom. Have a look at the first six lines of the file. They indicate that mkconfig generates the file. So if you edit that bit out, it will be regenerated sooner or later. If you want to remove an entry, have a look in Yast Bootloader Tab = Options. But I don’t know much about Grub, so other advice might arrive here (I hope).

The advice to not edit the file, is because it is automatically generated, and is regenerated on various events (such as a kernel update).

Yes, you can remove options. But they will come back.

The real trick would be for you to write a suitable “sed” script. Then, when needed, you can do:

cd /boot/grub2
sed -f /path/to/sed/script grub.cfg > grub.cfg.new
cp grub.cfg grub.cfg.old
mv grub.cfg.new grub.cfg

That’s because you will have to do this edit frequently enough that you will want to automate it.

Personally – I put up with the lines that I don’t need. I occasionally edit “grub.cfg” (using “vi”) to make temporary changes. And, if I like the temporary changes, then I edit “/etc/default/grub” or “/etc/grub.d/40_custom” so that the changes I want will show up automatically.

On a box without Windows, I turn off “probe for foreign OSs” (or whatever the option is), so that less menu entries are generated.

I make all the files in /etc/grub.d/ non-executable except 00_header and 90_consistent. I then edit the entries in 90_consistent when I need to. It’s a bit like the grub legacy menu.lst.
I think most people here would disagree with me but I find it easier than wading through loads of lines when I’ve changed a kernel on one of the partitions. I find grub will often apply the wrong kernel entry to the wrong partition.

Make sure to clean up after next grub2 update, those files reappear.

I have a short script I run every time I get a grub update.

Are you absolutely certain that, in /etc/grub.d/ there’s absolutely only one definition which leads to the “menuentry” text “openSUSE”?
Or, have you defined such a “menuentry” which the automatic scripts ignore and blithely generate a 2nd (default) “openSUSE” “menuentry” text?
Maybe, given the current automation status, you should change your “openSUSE” “menuentry” text to something different: “my openSUSE” for example.

I had a similar problem: grub listed openSuSE13.2 1st, then Leap42.1 2nd. I now wanted 42.2 1st.

I read thru’ a huge amount of documentation (most of it for Ubuntu which is inapplicable) but got totally stuck with:

/etc/default/grub

If you change this file, run ‘grub2-mkconfig -o /boot/grub2/grub.cfg’ afterwards to update

/boot/grub2/grub.cfg.

Bash - 4.3.42 : wi grub2-mkconfig/grub2-mkconfig: usr/sbin/grub2-mkconfig /usr/share/man/man8/grub2-mkconfig.8.gz

and the contents of:

Bash - 4.3.42 : ls /etc/grub.d
00_header* 20_linux_xen* 40_custom* 90_persistent*
00_tuned* 20_memtest86+* 41_custom* 95_textmode*
10_linux* 30_os-prober* 80_suse_btrfs_snapshot* README

or the README file:

"All executable files in this directory are processed in shell expansion order.

00_: Reserved for 00_header.
10_
: Native boot entries.
20_*: Third party apps (e.g. memtest86+).

The number namespace in-between is configurable by system installer and/or
administrator. For example, you can add an entry to boot another OS as
01_otheros, 11_otheros, etc, depending on the position you want it to occupy in
the menu; and then adjust the default setting via /etc/default/grub."

Durr!

Then I found nrickert’s post:

“If you want to remove an entry, have a look in Yast Bootloader Tab = Options. But I don’t know much about Grub, so other advice might arrive here (I hope)”.

OK! Without much faith, I called up Yast, selected “Boot Loader” & “Edit Boot Disk Order”. The existing choice was /dev/sda so I added /dev/sda11 (the partition for Leap42) underneath and, what do you know, I got what I wanted - Leap42 1st, **SuSE 13.2 **2nd.

I haven’t got round to it, but when I install Tumbleweed, I hope to make it 2nd & 13.2 3rd.

Thanks nrickert!

dmk

@thebigming

As you say, you have similar problem. Thus your post is NOT an additional remark to the problem here as mentioned in the title.

This is really not a good way to advertize your problem to those that browse the forums for new problems/questions. They will miss your request and thus you will miss potential helpers. :frowning:

Please start a thread of your own with a title with keywords that will draw the attention of people that might be able to help you.

Oh yes, and please in the future use CODE tags around copied/pasted computer text in a post. It is the # button in the tool bar of the post editor. When applicable copy/paste complete, that is including the prompt, the command, the output and the next prompt.

Regards,

As a generic response to the title in this thread and not to any specific user’s problem, for editing grub2 I like to use the tool grub-customizer

It is a graphical grub2 settings manager and I find it works well for me. No need with this GUI front end to dive into detailed configuration files.

At this point in time user ‘ecos’ offers (ie packaged for openSUSE) version-4.0.6 for LEAP-42.1 and LEAP-42.2 (and also for Tumbleweed).

I note for Tumbleweed a user “KAMiKAZOW” offers a version-5.0.6. I have not tried that version.
.

@ hcw - Thanks for that. I have a response but I must dig around a bit to put it together. I’ll get back to you!

@ oldcpu - Thanks, I’ve never heard of grub-customizer but it sounds just what I need! I’ve downloaded it.

dmk