Operating Systems list order on grub2 (openSuse 12.2)

Hi, there!
How can I change the order of the list of Operating Systems to boot on Grub 2?
I couldn’t find this option by mean of Yast.

Can somebody help me?

Thank you very much.

Under GRUB legacy you would have to edit menu.lst.

There should be a comparable file under GRUB 2.

There should be manuals for GRUB 2 explaining this.

As best as I can tell, there is no method included to set the menu order. You can however edit the grub.cfg file, once you understand how it is constructed, to move menu entries around. Any such changes will be over written on the next grub 2 update. A few certain things seem to occur.

  1. The top entry, just called openSUSE, will be the more recent kernel version installed on the system.
  2. The advanced option will be all kernel versions installed, they seem be displayed with the most recent on top. The most recent kernel installed with then appear twice taking the openSUSE name and its full name by kernel version.
  3. The menu entries for a standard load and its recovery entry are shown in pairs, standard first, recovery second.
  4. If a Windows boot entry is found, it will appear on the first menu screen, below the advanced menu entry. (Most recent first entry called openSUSE, Advanced menu options second and Windows option, third, if it exists.)

I have a bash script, useful in managing and editing Grub 2 files you can find here:

GNU Grub2 Command Help/Config Editor - Version: 1.80 - Blogs - openSUSE Forums

Thank You,

“Simply” add your own pipe in /etc/grub.d/30_os-prober to achieve the sort order you want. Depending on what you have to sort and how, the command line might be more or less tricky. For example, on a sytem where os-prober outputs this:


# os-prober
  No volume groups found
/dev/sda1:Windows NT/2000/XP (loader):Windows:chain
/dev/sda13:Fedora release 16 (Verne):Fedora:linux
/dev/sda15:Debian GNU/Linux (squeeze/sid):Debian:linux
/dev/sda6:Ubuntu 12.04.1 LTS (12.04):Ubuntu:linux
/dev/sdb1:Windows NT/2000/XP (loader):Windows1:chain
/dev/sdb3:FreeBSD:FreeBSD 8.1-RELEASE:freebsd
/dev/sdb6:Arch Linux (rolling):archlinux:linux

The following sort command would put Windows entries last:

# os-prober** | sort -t ":" -k 2**
  No volume groups found
/dev/sdb6:Arch Linux (rolling):archlinux:linux
/dev/sda15:Debian GNU/Linux (squeeze/sid):Debian:linux
/dev/sda13:Fedora release 16 (Verne):Fedora:linux
/dev/sdb3:FreeBSD:FreeBSD 8.1-RELEASE:freebsd
/dev/sda6:Ubuntu 12.04.1 LTS (12.04):Ubuntu:linux
/dev/sdb1:Windows NT/2000/XP (loader):Windows1:chain
/dev/sda1:Windows NT/2000/XP (loader):Windows:chain

This one would put Windows entries first:

# os-prober **| sort -r -t ":" -k 2**
  No volume groups found
/dev/sda1:Windows NT/2000/XP (loader):Windows:chain
/dev/sdb1:Windows NT/2000/XP (loader):Windows1:chain
/dev/sda6:Ubuntu 12.04.1 LTS (12.04):Ubuntu:linux
/dev/sdb3:FreeBSD:FreeBSD 8.1-RELEASE:freebsd
/dev/sda13:Fedora release 16 (Verne):Fedora:linux
/dev/sda15:Debian GNU/Linux (squeeze/sid):Debian:linux
/dev/sdb6:Arch Linux (rolling):archlinux:linux

So if you want Windows entrie to appear after all other entries (at least the ones detected by os-prober) you would have to replace this line in /etc/grub.d/30_os-prober

OSPROBED="`os-prober | tr ' ' '^' | paste -s -d ' '`"

with:

OSPROBED="`os-prober **| sort -t ":" -k 2** | tr ' ' '^' | paste -s -d ' '`"

That’s a very simple case though. If you need a more complicated sorting, you might have to use a more complicated command, which could involve some awk and sed magic.

There should be more helpful answers … lol!

Would be nice to have a Yast module to configure the boot order,like in grub 1…just dreaming!:slight_smile:

I don’t pretend to have fully understood it, but there is a lot of info here:
openSUSE 12.2: Chapter 10. The Boot Loader GRUB2

And what seems to be on first look, a nice tutorial here:
GRUB 2 bootloader - Full tutorial

And as some of you know only too well, I am a bit of an idiot when it comes to linuxery, but here is a GUI Grub customizer app, it needs to be compiled from sorce, but there is a very clear step-by-step… I have just done it, and although I have not yet messed with my GRUB2, and am using a sandbox non-vital install ATM, it seems to work, or at least start… The last step, launching it, must of course be changed to # kdesu grub-customizer

https://answers.launchpad.net/grub-customizer/+faq/1397

Some instructions for use here (for 'buntu, but still):

How to Configure the Linux Grub2 Boot Menu the Easy Way - How-To Geek

Well… It SEEMS to work, but the menu changes I make seem not to take effect. Also the environment needs to be adjusted to suit openSuse layout…
Here is what I have done, I could not find one entry, perhaps someone could point me in the right direction!

http://snag.gy/uOdYG.jpg

If it’s about sorting boot entries, I implemented this feature in the meantime in updategrub. You just need to install this package from my repo, set the variables GRUB_OS_PROBER_SORT and GRUB_OS_PROBER_SKIP in /etc/default/grub and refresh the Grub menu - as often as you need - with the command:

# updategrub -a

The option “-a” means that it is going to use an alternate os-prober script called 30_os-prober_alt. This script is included in updategrub package.

Here’s what I’m using:


GRUB_OS_PROBER_SORT="Ubuntu Mint openSUSE Mandriva Fedora Arch Debian Gentoo FreeBSD NetBSD OpenBSD Windows"
GRUB_OS_PROBER_SKIP="recovery failsafe fallback single-user"

If you’re afraid of writing grub.cfg (I bet you are) or don’t trust me (I bet you don’t), you can add the option “-d” to print the menu to standard ouput and do what you want with this output - including redirecting it to a file.

# updategrub -ad

This command won’t modify grub.cfg.
Although updategrub will work with os-prober 1.49 from standard repo and doesn’t require a higher version, it will work even better with os-prober 1.56 from my repo. (last time I checked openSUSE 12.2 was still using os-prober 1.49 . Right now, I don’t know, as the package search doesn’t seem to respond.)

Thank-you and Merci, M. PTA! I don’t really NEED atm to mess with the grub2, but I thought I would do some reading around on the subj… The one thing I would like is easily to be able to change the menu entries, to a more friendly customised format. I have temporarily two installs of of MSWIn, Grub2 identifies them as:
“Microsoft Windows XP Professional (on /dev/sda1)”
“Microsoft Windows XP Professional (on /dev/sdb1)”

I would prefer to see “Old XP” and “New XP” for example…, Or “XP on SSD” and “XP on old HDD”

ps Of course I trust you! You are one of the top-notch openSuse guru’s!

On 2012-09-15 03:46, please try again wrote:
> That’s a very simple case though. If you need a more complicated
> sorting, you might have to use a more complicated command, which could
> involve some awk and sed magi

Wow :frowning:

So you can not simply edit a menu file to your heart content, and hope
it is left alone? This is so “unlinux”…


Cheers / Saludos,

Carlos E. R.
(from 11.4 x86_64 “Celadon” (Minas Tirith))

The names of the boot entries written to grub.cfg are based on the output of os-prober - more precisely the second field ($LONGNAME)

 # os-prober
 No volume groups found
/dev/sda1:**Windows NT/2000/XP (loader)**:Windows:chain
/dev/sda13:Fedora release 16 (Verne):Fedora:linux
/dev/sda15:Debian GNU/Linux (squeeze/sid):Debian:linux
/dev/sda2:OpenBSD:OpenBSD 4.7:openbsd
/dev/sda3:FreeBSD:FreeBSD 7.2-RELEASE:freebsd
/dev/sda6:Ubuntu 12.04.1 LTS (precise):Ubuntu:linux
/dev/sdb1:**Windows NT/2000/XP (loader)**:Windows1:chain
/dev/sdb3:FreeBSD:FreeBSD 8.1-RELEASE:freebsd

The names for other Linux distros are build after the rules defined in /usr/lib/os-probes/mounted/90linux-distro. It is easy to modify these rules (I did for openSUSE to print the codename - you don’t see openSUSE here because I’m running os-prober under openSUSE, and none Linux distro is looking for itself). The names for Windows are taken from /usr/lib/os-probes/mounted/20microsoft. I don’t have Windows installed - despite the output above. I only have 10 years old NTldr in a FAT16 partition that os-prober sees as “Windows NT/2000/XP (loader)” (see the code below) . But you might be able to achieve what you want by editing your boot.ini under Windows. os-prober is attempting to parse this file if it exists.


# 2000/XP/NT4.0
if  -z "$found" ] && item_in_dir -q ntldr "$2" && item_in_dir -q ntdetect.com "$2"; then
	long="Windows NT/2000/XP"
	short=Windows
	ini=$(item_in_dir boot.ini "$2")
	if  -n "$ini" ]; then
		multicount="$(grep -e "^multi" "$2/$ini" | wc -l)"
		scsicount="$(grep -e "^scsi" "$2/$ini" | wc -l)"
		msoscount="$(expr "${multicount}" + "${scsicount}")"
		if  "$msoscount" -eq 1 ]; then
			# We need to remove a Carriage Return at the end of
			# the line...
			defaultmspart="$(grep -e "^default=" "$2/$ini" | cut -d '=' -f2 | tr -d '\r')"
			# Escape any backslashes in defaultmspart
			grepexp="^$(echo "$defaultmspart" | sed -e 's/\\/\\\\/')="
			# Colons not allowed; replace by spaces
			# Accented characters (non UTF-8) cause debconf to
			# hang, so we fall back to the default if the name
			# contains any weird characters.
			long="$(grep -e "$grepexp" "$2/$ini" | cut -d '"' -f2 | \
				tr ':' ' ' | LC_ALL=C grep -v '^a-zA-Z0-9 &()/_-]')"
			if  -z "$long" ]; then
				long="Windows NT/2000/XP"
			fi
		**else
			long="Windows NT/2000/XP (loader)"
		fi**

		found=true
	fi
fi

It probably reads “Microsoft Windows XP Professional” from your boot.ini. Just change this name there - but don’t ask me if it’s going to hurt Windows. I believe it won’t (but don’t ask me!).

What are you talking about? You can edit any the menu files you like the way you like - but don’t hope it is left alone in the os-prober section. (Put such static entries in /etc/grub.d/40_custom - if you ever decide to use Grub2 under 11.4 lol!) I personnally don’t have time to edit menus on dozens of systems. That’s why I write scripts. BTW the post you quoted is old. As I said, I implemented sorting and skipping boot entries the meantime.

On 2012-11-08 13:46, please try again wrote:

>
> What are you talking about? You can edit any the menu files you like
> the way you like - but don’t hope it is left alone in the os-prober
> section. (Put such static entries in /etc/grub.d/40_custom - if you ever
> decide to use Grub2 under 11.4 lol!) I personnally don’t have time to
> edit menus on dozens of systems. That’s why I write scripts. BTW the
> post you quoted is old. As I said, I implemented sorting and skipping
> boot entries the meantime.

Heh, I don’t intend to install grub 2 on this machine. And my desktop is
12.1, so not that one, either. I’m simply trying to understand grub2. So
I don’t understand, that os-prober is something that runs automatically
at some stage, or is it part of your scripts?

About the old post, I did not notice: this thread has jumped into the
recent posts position in thunderbird, there are some posts from today.


Cheers / Saludos,

Carlos E. R.
(from 11.4 x86_64 “Celadon” (Minas Tirith))

GRUB2 comes with program that auto-generates configuration file - grub-mkconfig. This program mostly calls scripts in /etc/grub.d and puts output of these scripts in grub.cfg. One such script calls os-prober. os-prober itself is not part of GRUB2, it is maintained by Debian.

Well, you could. I originally wrote updateGrub2 to install Grub2 on 12.1 (UEFI and BIOS) where it wasn’t the default. But I applied so many modications to this script - and Grub2 has changed a lot too between version 1.99 and version 2.0 - that I can not guarantee that it will still work for installing, as it was intended to install version 1.99, not 2.00 (they really changed a lot of things).

A little bit of both. Every time you refresh the boot menu - either with /usr/sbin/grub2-mkconfig or with my script (which finally calls grub2-mkconfig too), the scripts found in /etc/grub.d are executed in increasing numerical order, provided they are executable (if you don’t want a script to be executed, it suffices to clear its executable bit).

# find /etc/grub.d -type f -executable | sort -n
/etc/grub.d/00_header
/etc/grub.d/05_menu_color
/etc/grub.d/10_linux
/etc/grub.d/20_linux_xen
/etc/grub.d/20_ppc_terminfo
**/etc/grub.d/30_os-prober**
/etc/grub.d/40_custom
/etc/grub.d/41_custom
/etc/grub.d/90_persistent

The script /etc/grub.d/30_os-prober is part of Grub2, not os-prober. You can disable the execution of this script by setting the following variable in /etc/default/grub:

GRUB_DISABLE_OS_PROBER=true

And you should if you’re not multi-booting, since you won’t need os-prober at all. In this case, the os-prober section in grub.cfg will be empty:


### BEGIN /etc/grub.d/30_os-prober_alt ###
### END /etc/grub.d/30_os-prober_alt ###

Now, I rewrote 30_os-prober in my package and gave it the name 30_os-prober_alt. When you run updategrub with the option -a, it will use this script (which provides a couple nice features) instead of the ugly boring default one. That’s all. Well … actually not quite, but that’s all for today. :Z

On 2012-11-08 15:06, please try again wrote:
>
> robin_listas;2502237 Wrote:
>>
>> Heh, I don’t intend to install grub 2 on this machine. And my desktop
>> is 12.1, so not that one, either.
>>
>
> Well, you could. I originally wrote updateGrub2 to install Grub2 on
> 12.1 (UEFI and BIOS) where it wasn’t the default.

Heh, I’m not that adventurous with my main system :wink:

But I’ll keep this post for reference, sooner or later I’ll have to go
to grub 2 so I’ll better learn how to use it.


Cheers / Saludos,

Carlos E. R.
(from 11.4 x86_64 “Celadon” (Minas Tirith))

Thankyou for this! I tried editing boot.ini to read “OldMSWin” and then ran

#grub2-mkconfig -o "/boot/grub/grub.cfg"


Grub2 updated itself, and did indeed find my new entry in the boot.ini file (yehay!), BUT on reboot, the menu stayed the same… I wonder if this is to do with the openSuse branding part of GRUB2? The little GUI app I mentioned above seemed also to make the required changes, but on reboot, the menu remains resolutely the same…

ps
One good thing that all this has reminded me… That MSWin is very annoying, and compared to openSuse 12.2 takes an age to boot and load, and then hours updating itself, and then more hours updating its virus databases, and then adobe flash and Java and Norton and McAfee and god knows who else have to have a turn at updating and spinning the egg-timer… I never actually use MSWINXP, but for some reason I like it to be there, like a sort of uncomfortable comfort blanket…

Oops! Just re-read my own post and realised that the command I should have done was:

grub2-mkconfig -o "/boot/grub2/grub.cfg"

Which still does not work, BUT a change I had made earlier using the grub-customizer app DID now show up in the menu…

(time for bed, and I foresee a busy weekend!)