7

I just read that in certain situations you should also protect access to your GRUB2 menu by setting a password and may be refining acces by adding --unrestricted or --users as arguments to menuentries und submenus.

I read the corresponding pages in the Ubuntu Community Documentation and the Arch Wiki. So, I created /etc/grub.d/01_security, stored usernames and passwords in there, made the file executable and ran update-grub. This is working as intended, every action in the menu prompts for username and password, but I also want to modify the automatically generated entries to either restrict them to certain users (via --users) or make them available for everyone, but not editable by everyone (via --unrestricted).

I was able to find the proper lines in 10_linux and edit them accordingly, however I'd love to see an easier solution. Perhaps an option like GRUB_DISABLE_RECOVERY="true" or GRUB_DISABLE_OS_PROBER=true in /etc/default/grub for easy (re)configuration (for linux and os-prober generated entries).

Here's a diff from my 13.10 installation:

$ diff /etc/grub.d/10_linux /etc/grub.d/10_linux_bak
123c123
<       echo "menuentry '$(echo "$title" | grub_quote)' ${CLASS} --unrestriced \$menuentry_id_option 'gnulinux-$version-$type-$boot_device_id' {" | sed "s/^$
---
>       echo "menuentry '$(echo "$title" | grub_quote)' ${CLASS} \$menuentry_id_option 'gnulinux-$version-$type-$boot_device_id' {" | sed "s/^/$submenu_inde$
125c125
<       echo "menuentry '$(echo "$os" | grub_quote)' ${CLASS} --unrestricted \$menuentry_id_option 'gnulinux-simple-$boot_device_id' {" | sed "s/^/$submenu_$
---
>       echo "menuentry '$(echo "$os" | grub_quote)' ${CLASS} \$menuentry_id_option 'gnulinux-simple-$boot_device_id' {" | sed "s/^/$submenu_indentation/"
323c323
<     echo "submenu --unrestricted '$(gettext_printf "Advanced options for %s" "${OS}" | grub_quote)' \$menuentry_id_option 'gnulinux-advanced-$boot_device_$
---
>     echo "submenu '$(gettext_printf "Advanced options for %s" "${OS}" | grub_quote)' \$menuentry_id_option 'gnulinux-advanced-$boot_device_id' {"

tl;dr: I'd love the see a simple solution for GRUB2 entries that cannot be modified without a password or are limited to certain users. (Yes, GRUB_DISABLE_RECOVERY="true" is active.)

5
  • isnt this the same as this (or at least mine and jorges answer are applicable) ? askubuntu.com/questions/76987/…
    – fossfreedom
    Oct 13, 2013 at 7:48
  • What you want is establish rules for what each user wants to do? Like ACL?
    – Braiam
    Oct 13, 2013 at 12:23
  • 1
    @Braiam No, not that complicated. Just one general variable in /etc/default/grub and (may be individual ones for linux and os-prober entries). Example: root, user1 and user2 exists, GRUB_SECURITY_LINUX="--users user1" and GRUB_SECURITY_OSPROBER="--unrestricted". This should add these parameters to the corresponding entries and thus, if I understood correctly, generate a configuration where user1 and root would be able to boot the Ubuntu installation, everyone can boot os-prober generated entries and only root can edit them. Basically "read that variable and do x". Simple bash code.
    – LiveWireBT
    Oct 13, 2013 at 13:03
  • 1
    Basically I'd like to see a simple solution that can be included in Ubuntu by default. I don't want to make and maintain customized copies of 10_linux and 30_os-prober.
    – LiveWireBT
    Oct 13, 2013 at 13:08
  • "Security" my not be the proper description he, it's more like adding customized parameters.
    – LiveWireBT
    Oct 13, 2013 at 13:19

1 Answer 1

1

Okay I found that variables in /etc/default/grub are read and exported by grub-mkconfig in /usr/sbin/. The following patch is what I had in mind and hopefully complies with quality requirements and coding standards for the files modified. Patch for 30_os-prober should be similar and hopefully follows tomorrow.

As explained above the variables should be defined in /etc/default/grub like so GRUB_PWRESTRICTION_LINUX="--users user1" or so GRUB_PWRESTRICTION_LINUX="--unrestricted".

I'm looking forward to your feedback.

--- /usr/sbin/grub-mkconfig-orig    2013-10-19 11:22:56.653129020 +0200
+++ /usr/sbin/grub-mkconfig 2013-10-19 11:49:34.961392887 +0200
@@ -230,6 +230,12 @@
   GRUB_ENABLE_CRYPTODISK \
   GRUB_BADRAM \
   GRUB_RECORDFAIL_TIMEOUT
+  GRUB_PWRESTRICTION_LINUX \
+  GRUB_PWRESTRICTION_OS_PROBER_LINUX \
+  GRUB_PWRESTRICTION_OS_PROBER_WINDOWS \
+  GRUB_PWRESTRICTION_OS_PROBER_MACOSX \
+  GRUB_PWRESTRICTION_OS_PROBER_EFI \
+  GRUB_PWRESTRICTION_OS_PROBER_HURD

 if test "x${grub_cfg}" != "x"; then
   rm -f "${grub_cfg}.new"
--- /etc/grub.d/10_linux-orig   2013-10-19 23:28:50.195071600 +0200
+++ /etc/grub.d/10_linux    2013-10-19 23:40:17.429375336 +0200
@@ -120,9 +120,17 @@
      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
-      echo "menuentry '$(echo "$title" | grub_quote)' ${CLASS} \$menuentry_id_option 'gnulinux-$version-$type-$boot_device_id' {" | sed "s/^/$submenu_indentation/"
+      if [ x"${GRUB_PWRESTRICTION_LINUX}" != x ]; then
+        echo "menuentry '$(echo "$title" | grub_quote)' ${CLASS} "${GRUB_PWRESTRICTION_LINUX}" \$menuentry_id_option 'gnulinux-$version-$type-$boot_device_id' {" | sed "s/^/$submenu_indentation/"
+      else
+        echo "menuentry '$(echo "$title" | grub_quote)' ${CLASS} \$menuentry_id_option 'gnulinux-$version-$type-$boot_device_id' {" | sed "s/^/$submenu_indentation/"
+      fi
   else
-      echo "menuentry '$(echo "$os" | grub_quote)' ${CLASS} \$menuentry_id_option 'gnulinux-simple-$boot_device_id' {" | sed "s/^/$submenu_indentation/"
+      if [ x"${GRUB_PWRESTRICTION_LINUX}" != x ]; then
+        echo "menuentry '$(echo "$os" | grub_quote)' ${CLASS} "${GRUB_PWRESTRICTION_LINUX}" \$menuentry_id_option 'gnulinux-simple-$boot_device_id' {" | sed "s/^/$submenu_indentation/"
+      else
+        echo "menuentry '$(echo "$os" | grub_quote)' ${CLASS} \$menuentry_id_option 'gnulinux-simple-$boot_device_id' {" | sed "s/^/$submenu_indentation/"
+      fi
   fi      
   echo "recordfail" | sed "s/^/$submenu_indentation/"
   if [ x$type != xrecovery ] ; then
@@ -320,7 +328,11 @@
    boot_device_id="$(grub_get_device_id "${GRUB_DEVICE}")"
     fi
     # TRANSLATORS: %s is replaced with an OS name
-    echo "submenu '$(gettext_printf "Advanced options for %s" "${OS}" | grub_quote)' \$menuentry_id_option 'gnulinux-advanced-$boot_device_id' {"
+    if [ x"${GRUB_PWRESTRICTION_LINUX}" != x ]; then
+      echo "submenu '$(gettext_printf "Advanced options for %s" "${OS}" | grub_quote)' "${GRUB_PWRESTRICTION_LINUX}" \$menuentry_id_option 'gnulinux-advanced-$boot_device_id' {"
+    else
+      echo "submenu '$(gettext_printf "Advanced options for %s" "${OS}" | grub_quote)' \$menuentry_id_option 'gnulinux-advanced-$boot_device_id' {"
+    fi
   fi

   linux_entry "${OS}" "${version}" advanced \

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .