Page 1 of 1

Grub2 Advanced Options Folders(Workround Available)

Posted: Mon Dec 10, 2012 6:28 am
by viking777
As a result of buying a new pc with Uefi booting I was forced to abandon grub-legacy and use grub2 instead. I have always thought, and still think that grub-legacy is far superior, but I don't have that option any more so I have to live with grub2 like it or not.

One of the things that annoys me about grub2 (there are plenty but I wont go into that here) is the fact that I am no longer allowed to have a list of installed kernels in the grub menu as I did before, now I have to have one entry for every distro with all the other kernels hidden in a so called 'Advanced Options' folder. This is supposed to make the menu tidier, for me it just makes it infuriating :evil:

I have looked through all the /etc/default/grub options, tried grub-customizer (the 'Advanced Options' folders appear in its interface, but don't have the kernels listed, just 'placeholders' and if you delete either the folder itself or the placeholders everything disappears and you are then left only able to boot the current kernel - I have already had to reinstall grub2 twice because of that). Google doesn't help either, I just cant find a way to get rid of these annoying folders without deleting any of the kernels inside them.

Does anyone know how to do it??

Linux was so simple before it was simplified :?

Re: Grub2 Advanced Options Folders

Posted: Mon Dec 10, 2012 7:25 am
by zerozero
viking,
either that is a feature :lol: of grub-efi or a specific ubuntu implementation.
in my 2 comp i don't see that: one with grub 1.99-23, 7 distros and a couple of those with around 10 entries in grub; the other with grub 1.99-23.1, 3 distros and also several kernel listed.

as i don't use ubuntu's grubs it's hard to hunt for a diff but if you need any file(s) to compare ask :wink:

Re: Grub2 Advanced Options Folders

Posted: Mon Dec 10, 2012 12:48 pm
by viking777
Oh that is interesting, thanks for that zerozero, I will have to think about that for a while, maybe I should change to using another grub instead. Hmm? Given the problems I have already had with this machine and efi, I am not sure I am brave enough to try it :lol: .

Re: Grub2 Advanced Options Folders(Workround Available)

Posted: Wed Dec 12, 2012 9:32 am
by viking777
I know that zerozero pointed out that the problem I am having is specific to Ubuntu, but I thought I would detail the workround I have come up with just in case anyone is interested.

I have to say first of all that this is a poor workround (because it will get overwritten every time update-grub gets run) but the alternative would be to edit the code in /etc/grub.d/30_os-prober and that is beyond my level of knowledge.

So the poor man's alternative is this is to edit /boot/grub/grub.cfg. Open it in a root text editor and search for the word 'submenu' then comment out the line/lines like this:

Code: Select all

#submenu 'Advanced options for Linux Mint 14 Nadia (14)' $menuentry_id_option 'osprober-gnulinux-advanced-c9900ea5-
#c45d-49c9-a62c-0ab6f36bc3df' {
Be careful how you do it, the first time I tried it nothing would boot at all and I had to use parted magic to undo the edits. I am not even sure what I did, I guess I commented out one too many lines.

Re: Grub2 Advanced Options Folders(Workround Available)

Posted: Wed Dec 12, 2012 10:00 am
by zerozero
yeahh :shock: i think that is the safest way to go;
a quick diff between lmde's 30_os-prober and nadia's shows

Code: Select all

--- etc/grub.d/30_os-prober	2012-03-06 19:21:46.000000000 +0000
+++ media/4fb154f2-ab7c-4a26-b68f-8d4641e5445c/etc/grub.d/30_os-prober	2012-10-14 18:36:31.000000000 +0100
@@ -21,26 +21,96 @@
 exec_prefix="${prefix}"
 datarootdir="${prefix}/share"
 
+export TEXTDOMAIN=grub
+export TEXTDOMAINDIR="${datarootdir}/locale"
+
 . "${datarootdir}/grub/grub-mkconfig_lib"
 
+found_other_os=
+
+make_timeout () {
+  if [ "x${found_other_os}" = "x" ] ; then
+    if [ "x${1}" != "x" ] ; then
+      if [ "x${GRUB_HIDDEN_TIMEOUT_QUIET}" = "xtrue" ] ; then
+	verbose=
+      else
+	verbose=" --verbose"
+      fi
+
+      if [ "x${1}" = "x0" ] ; then
+	cat <<EOF
+if [ "x\${timeout}" != "x-1" ]; then
+  if keystatus; then
+    if keystatus --shift; then
+      set timeout=-1
+    else
+      set timeout=0
+    fi
+  else
+    if sleep$verbose --interruptible 3 ; then
+      set timeout=0
+    fi
+  fi
+fi
+EOF
+      else
+	cat << EOF
+if [ "x\${timeout}" != "x-1" ]; then
+  if sleep$verbose --interruptible ${GRUB_HIDDEN_TIMEOUT} ; then
+    set timeout=0
+  fi
+fi
+EOF
+      fi
+    fi
+  fi
+}
+
+adjust_timeout () {
+  if [ "x$GRUB_BUTTON_CMOS_ADDRESS" != "x" ]; then
+    cat <<EOF
+if cmostest $GRUB_BUTTON_CMOS_ADDRESS ; then
+EOF
+    make_timeout "${GRUB_HIDDEN_TIMEOUT_BUTTON}" "${GRUB_TIMEOUT_BUTTON}"
+    echo else
+    make_timeout "${GRUB_HIDDEN_TIMEOUT}" "${GRUB_TIMEOUT}"
+    echo fi
+  else
+    make_timeout "${GRUB_HIDDEN_TIMEOUT}" "${GRUB_TIMEOUT}"
+  fi
+}
+
 if [ "x${GRUB_DISABLE_OS_PROBER}" = "xtrue" ]; then
+  adjust_timeout
   exit 0
 fi
 
 if [ -z "`which os-prober 2> /dev/null`" -o -z "`which linux-boot-prober 2> /dev/null`" ] ; then
   # missing os-prober and/or linux-boot-prober
+  adjust_timeout
   exit 0
 fi
 
 OSPROBED="`os-prober | tr ' ' '^' | paste -s -d ' '`"
 if [ -z "${OSPROBED}" ] ; then
   # empty os-prober output, nothing doing
+  adjust_timeout
   exit 0
 fi
 
 osx_entry() {
+    found_other_os=1
+    if [ x$2 = x32 ]; then
+        # TRANSLATORS: it refers to kernel architecture (32-bit)
+	bitstr="$(gettext "(32-bit)")"
+    else
+        # TRANSLATORS: it refers to kernel architecture (64-bit)
+	bitstr="$(gettext "(64-bit)")"
+    fi
+    # TRANSLATORS: it refers on the OS residing on device %s
+    onstr="$(gettext_printf "(on %s)" "${DEVICE}")"
         cat << EOF
-menuentry "${LONGNAME} (${2}-bit) (on ${DEVICE})" --class osx --class darwin --class os {
+menuentry '$(echo "${LONGNAME} $bitstr $onstr" | grub_quote)' --class osx --class darwin --class os \$menuentry_id_option 'osprober-xnu-$2-$(grub_get_device_id "${DEVICE}")'  {
 EOF
 	save_default_entry | sed -e "s/^/\t/"
 	prepare_grub_to_access_device ${DEVICE} | sed -e "s/^/\t/"
@@ -57,11 +127,15 @@
            if [ -f /Extra/DSDT.aml ]; then
               acpi -e /Extra/DSDT.aml
            fi
-           $1 /mach_kernel boot-uuid=\${uuid} rd=*uuid
-           if [ /System/Library/Extensions.mkext -nt /System/Library/Extensions ]; then
-              xnu_mkext /System/Library/Extensions.mkext
+           if [ /kernelcache -nt /System/Library/Extensions ]; then
+              $1 /kernelcache boot-uuid=\${uuid} rd=*uuid
            else
-              xnu_kextdir /System/Library/Extensions
+              $1 /mach_kernel boot-uuid=\${uuid} rd=*uuid
+              if [ /System/Library/Extensions.mkext -nt /System/Library/Extensions ]; then
+                xnu_mkext /System/Library/Extensions.mkext
+              else
+                xnu_kextdir /System/Library/Extensions
+              fi
            fi
            if [ -f /Extra/Extensions.mkext ]; then
               xnu_mkext /Extra/Extensions.mkext
@@ -89,6 +163,10 @@
 EOF
 }
 
+used_osprober_linux_ids=
+
+wubi=
+
 for OS in ${OSPROBED} ; do
   DEVICE="`echo ${OS} | cut -d ':' -f 1`"
   LONGNAME="`echo ${OS} | cut -d ':' -f 2 | tr '^' ' '`"
@@ -99,13 +177,32 @@
     LONGNAME="${LABEL}"
   fi
 
-  echo "Found ${LONGNAME} on ${DEVICE}" >&2
+  gettext_printf "Found %s on %s\n" "${LONGNAME}" "${DEVICE}" >&2
 
   case ${BOOT} in
     chain)
 
+      case ${LONGNAME} in
+	Windows*)
+	  if [ -z "$wubi" ]; then
+	    if [ -x /usr/share/lupin-support/grub-mkimage ] && \
+	       /usr/share/lupin-support/grub-mkimage --test; then
+	      wubi=yes
+	    else
+	      wubi=no
+	    fi
+	  fi
+	  if [ "$wubi" = yes ]; then
+	    echo "Skipping ${LONGNAME} on Wubi system" >&2
+	    continue
+	  fi
+	  ;;
+      esac
+
+      found_other_os=1
+	  onstr="$(gettext_printf "(on %s)" "${DEVICE}")"
       cat << EOF
-menuentry "${LONGNAME} (on ${DEVICE})" --class windows --class os {
+menuentry '$(echo "${LONGNAME} $onstr" | grub_quote)' --class windows --class os \$menuentry_id_option 'osprober-chain-$(grub_get_device_id "${DEVICE}")' {
 EOF
       save_default_entry | sed -e "s/^/\t/"
       prepare_grub_to_access_device ${DEVICE} | sed -e "s/^/\t/"
@@ -128,6 +225,10 @@
     linux)
       LINUXPROBED="`linux-boot-prober ${DEVICE} 2> /dev/null | tr ' ' '^' | paste -s -d ' '`"
       prepare_boot_cache=
+      boot_device_id=
+      is_first_entry=true
+      title_correction_code=
+      OS="${LONGNAME}"
 
       for LINUX in ${LINUXPROBED} ; do
         LROOT="`echo ${LINUX} | cut -d ':' -f 1`"
@@ -146,35 +247,82 @@
 	  LINITRD="${LINITRD#/boot}"
 	fi
 
-        cat << EOF
-menuentry "${LLABEL} (on ${DEVICE})" --class gnu-linux --class gnu --class os {
-EOF
-	save_default_entry | sed -e "s/^/\t/"
 	if [ -z "${prepare_boot_cache}" ]; then
 	  prepare_boot_cache="$(prepare_grub_to_access_device ${LBOOT} | sed -e "s/^/\t/")"
+	  [ "${prepare_boot_cache}" ] || continue
 	fi
-	printf '%s\n' "${prepare_boot_cache}"
-	cat <<  EOF
+
+	found_other_os=1
+	onstr="$(gettext_printf "(on %s)" "${DEVICE}")"
+	recovery_params="$(echo "${LPARAMS}" | grep 'single\|recovery')" || true
+	counter=1
+	while echo "$used_osprober_linux_ids" | grep 'osprober-gnulinux-$LKERNEL-${recovery_params}-$counter-$boot_device_id' > /dev/null; do
+	    counter=$((counter+1));
+	done
+	if [ -z "$boot_device_id" ]; then
+	    boot_device_id="$(grub_get_device_id "${DEVICE}")"
+	fi
+	used_osprober_linux_ids="$used_osprober_linux_ids 'osprober-gnulinux-$LKERNEL-${recovery_params}-$counter-$boot_device_id'"
+
+	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' {
+EOF
+	    save_default_entry | sed -e "s/^/\t/"
+	    printf '%s\n' "${prepare_boot_cache}"
+	    cat <<  EOF
 	linux ${LKERNEL} ${LPARAMS}
 EOF
-        if [ -n "${LINITRD}" ] ; then
+            if [ -n "${LINITRD}" ] ; then
           cat << EOF
 	initrd ${LINITRD}
 EOF
-        fi
+            fi
         cat << EOF
 }
 EOF
+	    echo "submenu '$(gettext_printf "Advanced options for %s" "${OS}" | grub_quote)' \$menuentry_id_option 'osprober-gnulinux-advanced-$boot_device_id' {"
+	    is_first_entry=false
+	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' {
+EOF
+	save_default_entry | sed -e "s/^/\t\t/"
+	printf '%s\n' "${prepare_boot_cache}" | sed -e "s/^/\t/"
+	cat <<  EOF
+		linux ${LKERNEL} ${LPARAMS}
+EOF
+        if [ -n "${LINITRD}" ] ; then
+            cat << EOF
+		initrd ${LINITRD}
+EOF
+        fi
+        cat << EOF
+	}
+EOF
+	if [ x"$title" = x"$GRUB_ACTUAL_DEFAULT" ] || [ x"Previous Linux versions>$title" = x"$GRUB_ACTUAL_DEFAULT" ]; then
+	    replacement_title="$(echo "Advanced options for ${OS}" | sed 's,>,>>,g')>$(echo "$title" | sed 's,>,>>,g')"
+	    quoted="$(echo "$GRUB_ACTUAL_DEFAULT" | grub_quote)"
+	    title_correction_code="${title_correction_code}if [ \"x\$default\" = '$quoted' ]; then default='$(echo "$replacement_title" | grub_quote)'; fi;"
+	    grub_warn "$(gettext_printf "Please don't use old title \`%s' for GRUB_DEFAULT, use \`%s' (for versions before 2.00) or \`%s' (for 2.00 or later)" "$GRUB_ACTUAL_DEFAULT" "$replacement_title" "gnulinux-advanced-$boot_device_id>gnulinux-$version-$type-$boot_device_id")"
+	fi
       done
+      if [ x"$is_first_entry" != xtrue ]; then
+	  echo '}'
+      fi
+      echo "$title_correction_code"
     ;;
     macosx)
-      OSXUUID="`grub-probe --target=fs_uuid --device ${DEVICE} 2> /dev/null`"
+      OSXUUID="`${grub_probe} --target=fs_uuid --device ${DEVICE} 2> /dev/null`"
       osx_entry xnu_kernel 32
       osx_entry xnu_kernel64 64
     ;;
     hurd)
+      found_other_os=1
+      onstr="$(gettext_printf "(on %s)" "${DEVICE}")"
       cat << EOF
-menuentry "${LONGNAME} (on ${DEVICE})" --class hurd --class gnu --class os {
+menuentry '$(echo "${LONGNAME} $onstr" | grub_quote)' --class hurd --class gnu --class os \$menuentry_id_option 'osprober-gnuhurd-/boot/gnumach.gz-false-$(grub_get_device_id "${DEVICE}")' {
 EOF
       save_default_entry | sed -e "s/^/\t/"
       prepare_grub_to_access_device ${DEVICE} | sed -e "s/^/\t/"
@@ -198,7 +346,11 @@
 EOF
     ;;
     *)
-      echo "  ${LONGNAME} is not yet supported by grub-mkconfig." >&2
+      echo -n "  "
+      # TRANSLATORS: %s is replaced by OS name.
+      gettext_printf "%s is not yet supported by grub-mkconfig.\n" "${LONGNAME}" >&2
     ;;
   esac
 done
+
+adjust_timeout
most of the additions are related with these advanced options
viking777 wrote:Linux was so simple before it was simplified
:lol: :lol: