Icons for other distros in boot menu.

I don’t know if this topic has been discussed already, but here’s a quick howto. (AFAIK) this feature is missing but quite easy to implement. Here’s a patch against /etc/grub.d/30_os-prober (will submit it too):


--- 30_os-prober        2012-10-11 00:22:10.460633650 -0700
+++ 30_os-prober_alt    2012-10-23 18:30:41.460655441 -0700
@@ -23,6 +23,7 @@
 
 export TEXTDOMAIN=grub2
 export TEXTDOMAINDIR="${datarootdir}/locale"
+**declare -l CLASS**
 
 . "/usr/share/grub2/grub-mkconfig_lib"
 
@@ -112,6 +113,7 @@
   LONGNAME="`echo ${OS} | cut -d ':' -f 2 | tr '^' ' '`"
   LABEL="`echo ${OS} | cut -d ':' -f 3 | tr '^' ' '`"
   BOOT="`echo ${OS} | cut -d ':' -f 4`"
+  **CLASS=$LABEL **
 
   if  -z "${LONGNAME}" ] ; then
     LONGNAME="${LABEL}"
@@ -186,7 +188,7 @@
 
        if  "x$is_first_entry" = xtrue ]; then
             cat << EOF
-menuentry '$(echo "$OS" | grub_quote)' --class gnu-linux --class gnu --class os \$menuentry_id_option 'osprober-gnulinux-simple-$boot_device_id' {
+menuentry '$(echo "$OS" | grub_quote)' **--class ${CLASS}** --class gnu-linux --class gnu --class os \$menuentry_id_option 'osprober-gnulinux-simple-$boot_device_id' {
 EOF
            save_default_entry | sed -e "s/^/	/"
            printf '%s
' "${prepare_boot_cache}"
@@ -206,7 +208,7 @@
        fi
        title="${LLABEL} $onstr"
         cat << EOF
-       menuentry '$(echo "$title" | grub_quote)' --class gnu-linux --class gnu --class os \$menuentry_id_option 'osprober-gnulinux-$LKERNEL-${recovery_params}-$boot_device_id' {
+       menuentry '$(echo "$title" | grub_quote)' **--class ${CLASS}** --class gnu-linux --class gnu --class os \$menuentry_id_option 'osprober-gnulinux-$LKERNEL-${recovery_params}-$boot_device_id' {
 EOF
        save_default_entry | sed -e "s/^/		/"
        printf '%s
' "${prepare_boot_cache}" | sed -e "s/^/	/"

Though it might not be desirable to modify this script. Therefore until it is fixed, a better approach is to use** updateGrub2** with option -a to refresh the menu. Among other things, this option runs grub2-mkconfig with an alternate os-prober script (called 30_os-prober_alt and included in package updategrub](http://software.opensuse.org/package/updategrub?search_term=updategrub)) and adds a couple other features (that I already described in this post/thread: Installing Grub2 with updateGrub2 #9).

To use updateGrub2, just install the package updategrub from my repo, as described here updategrub for openSUSE Legacy Grub (not update-grub!).

Here are the commands again to add the correct repo (for openSUSE 12.2):

# su -l 
$ zypper ar http://download.opensuse.org/repositories/home:/please_try_again/openSUSE_12.2/ PTA
$ zypper refresh -r PTA
$ zypper in updategrub

This package includes 4 scripts:

updategrub requires os-prober (which is already installed on 12.2), but it doesn’t require the latest version (in my repo). Thus you don’t need to change os-prober vendor. However if you want to use all the features - such as support for BSD OSes in Grub2 or for Windows ans ELILO UEFI boot loaders - or have some bugs solved - such as truncated kernel options in boot entries, you should use os-prober 1.56, which has these features added and these bugs fixed.

|
|
When installed under 12.2, a symlink “updategrub” to updateGrub2 will be created, while under previous releases, updategrub will be symlinked to updateLegacyGrub.|

Back to topic… Assuming you’re using openSUSE Grub2 theme, which is the default, after rewriting the Grub menu with

updategrub -a

you should see icons for other OSes (not just for Windows) in boot menu:

http://imageshack.us/a/img337/2539/grubscreen122.png

You won’t see an icon for ArchLinux, as in this example, because this icon doesn’t exist. Thus, if an icon for another Linux distro or another OS is missing, here’s how to add it:

  • Run os-prober to find out the short name of the distro/OS. This is the 3rd field in os-prober output:
# 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**
/dev/sdb6:Arch Linux (rolling):**archlinux**:linux

I didn’t expect “Windows1” here, and I should probably add a 4th. field to the BSDs, but let us focus on ArchLinux for now.

  • Create a .png icon with the lowercase
    short name of the distro (in this case, it is the same) and put this icon in /boot/grub2/themes/openSUSE/icons. The size of this icon doens’t seem to matter, but if you export a .svg to a 256x256 bitmap, it will look great.
# find /boot/grub2/themes/openSUSE/icons -type f
**/boot/grub2/themes/openSUSE/icons/mandriva.png**
/boot/grub2/themes/openSUSE/icons/linuxmint.png
/boot/grub2/themes/openSUSE/icons/fedora.png
/boot/grub2/themes/openSUSE/icons/gentoo.png
/boot/grub2/themes/openSUSE/icons/opensuse.png
/boot/grub2/themes/openSUSE/icons/macosx.png
**/boot/grub2/themes/openSUSE/icons/netbsd.png**
/boot/grub2/themes/openSUSE/icons/windows.png
/boot/grub2/themes/openSUSE/icons/kubuntu.png
**/boot/grub2/themes/openSUSE/icons/mageia.png**
/boot/grub2/themes/openSUSE/icons/ubuntu.png
/boot/grub2/themes/openSUSE/icons/recovery.png
**/boot/grub2/themes/openSUSE/icons/freebsd.png**
/boot/grub2/themes/openSUSE/icons/debian.png
**/boot/grub2/themes/openSUSE/icons/archlinux.png
****/boot/grub2/themes/openSUSE/icons/openbsd.png**
/boot/grub2/themes/openSUSE/icons/sabayon.png

Some icons are already included in package grub2-branding-openSUSE-12.2 and permanently stored in /usr/share/grub2/themes/openSUSE/icons. The ones in bold were added by me. I would like to put these icons in a package … but I’m not sure if it would be legal to redistribute them (and if so how many different licenses I should include in the package… :question: )

Hi please_try_again,

This how-to is very nice. You have something similar for ubuntu… :wink:

Hi DaaX.

This 30_os-prober_alt didn’t work on Ubuntu, which uses “dash” (not to be confused with “daax”) and not “bash” as its defaut shell (sh) (!). It doesn’t support the “declare” builtin. I just noticed and updated my package. Here’s a new patch against 30_os-prober which works in all cases (but only makes sense if you don’t use updateGrub2).

--- 30_os-prober_alt    2012-10-25 03:40:25.601860984 -0700
+++ 30_os-prober        2012-10-11 00:22:10.460633650 -0700
@@ -112,7 +112,6 @@
   LONGNAME="`echo ${OS} | cut -d ':' -f 2 | tr '^' ' '`"
   LABEL="`echo ${OS} | cut -d ':' -f 3 | tr '^' ' '`"
   BOOT="`echo ${OS} | cut -d ':' -f 4`"
-  CLASS="`echo $LABEL | tr ":upper:]" ":lower:]"`"
 
   if  -z "${LONGNAME}" ] ; then
     LONGNAME="${LABEL}"
@@ -187,7 +186,7 @@
 
        if  "x$is_first_entry" = xtrue ]; then
             cat << EOF
-menuentry '$(echo "$OS" | grub_quote)' --class ${CLASS} --class gnu-linux --class gnu --class os \$menuentry_id_option 'osprober-gnulinux-simple-$boot_device_id' {
+menuentry '$(echo "$OS" | grub_quote)' --class gnu-linux --class gnu --class os \$menuentry_id_option 'osprober-gnulinux-simple-$boot_device_id' {
 EOF
            save_default_entry | sed -e "s/^/	/"
            printf '%s
' "${prepare_boot_cache}"
@@ -207,7 +206,7 @@
        fi
        title="${LLABEL} $onstr"
         cat << EOF
-       menuentry '$(echo "$title" | grub_quote)' --class ${CLASS} --class gnu-linux --class gnu --class os \$menuentry_id_option 'osprober-gnulinux-$LKERNEL-${recovery_params}-$boot_device_id' {
+       menuentry '$(echo "$title" | grub_quote)' --class gnu-linux --class gnu --class os \$menuentry_id_option 'osprober-gnulinux-$LKERNEL-${recovery_params}-$boot_device_id' {
 EOF
        save_default_entry | sed -e "s/^/		/"
        printf '%s
' "${prepare_boot_cache}" | sed -e "s/^/	/"

I have no idea if/how the icons and theme work under Ubuntu 12.04, which still uses Grub2 v 1.99. But I presume that it would work with the new 12.10 which just came out, since it certainly uses Grub2 v 2.00 (like the other distros). See these posts in the french forum on howto get it work on ArchLinux: