Skip to contentSkip to conversation

Allow user to choose between path or fs-label instead of UUID

PATCH In review Pete Appleton 3 participants 10 messages Sep 16, 2012 – May 27, 2014

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Allow user to choose between path or fs-label instead of UUID

Hi all,

The file attached is intended to allow a Linux user to easily specify whether GRUB2 should use the traditional device path (/dev/sda1) or the filesystem label instead of the default UUID scheme. This functionality is currently supported by GRUB2 itself but the peripheral files (grub-mkconfig, 10-linux etc) don't directly support it, requiring the user to edit the distribution-supplied files on their installation with the potential for consequent upgrade conflicts.

This patch adds support for a new environment variable GRUB_DEVICE_IDENTIFICATION taking as value one of {uuid, label, path}; if not set or invalid then it defaults to uuid so that the current semantics are respected. If set to label then the 'search' clause and root=XXX kernel parameter are written using file system label syntax as opposed to the current single behaviour of device path if GRUB_DISABLE_LINUX_UUID=true

This patch was written after needing the functionality in my environment as I frequently move filesystems around a multi-spindle system (using the label to keep track of them) and seeing a few articles online advising various modifications to distribution supplied files; I hope that it is deemed useful enough to get incorporated into trunk to remove this minor niggle with a great product.

Thanks,

Pete Appleton

=== modified file 'docs/grub.texi'

docs/grub.texi +8 -0
@@ -1285,6 +1285,14 @@
 the Linux kernel, using a @samp{root=UUID=...} kernel parameter.  This is
 usually more reliable, but in some cases it may not be appropriate.  To
 disable the use of UUIDs, set this option to @samp{true}.
+@samp{GRUB_DEVICE_IDENTIFICATION} governs the scheme used instead of
+the UUID, either the file system label or the traditional device path
+
+@item GRUB_DEVICE_IDENTIFICATION
+Works in conjunction with GRUB_DISABLE_LINUX_UUID to determine how the root filesystem
+will be identified for the Linux kernel.  The default value is @samp{uuid}, which will use UUIDs. 
+Other alternatives are @samp{label} to use the file system label, or @samp{path} to use
+the traditional device path (@samp{/dev/sda1})
 
 @item GRUB_DISABLE_RECOVERY
 If this option is set to @samp{true}, disable the generation of recovery

=== modified file 'util/grub-mkconfig.in'

util/grub-mkconfig.in +9 -0
@@ -131,10 +131,12 @@
 # Device containing our userland.  Typically used for root= parameter.
 GRUB_DEVICE="`${grub_probe} --target=device /`"
 GRUB_DEVICE_UUID="`${grub_probe} --device ${GRUB_DEVICE} --target=fs_uuid 2> /dev/null`" || true
+GRUB_DEVICE_LABEL="`${grub_probe} --device ${GRUB_DEVICE} --target=fs_label 2> /dev/null`" || true
 
 # Device containing our /boot partition.  Usually the same as GRUB_DEVICE.
 GRUB_DEVICE_BOOT="`${grub_probe} --target=device /boot`"
 GRUB_DEVICE_BOOT_UUID="`${grub_probe} --device ${GRUB_DEVICE_BOOT} --target=fs_uuid 2> /dev/null`" || true
+GRUB_DEVICE_BOOT_LABEL="`${grub_probe} --device ${GRUB_DEVICE_BOOT} --target=fs_label 2> /dev/null`" || 
 
 # Filesystem for the device containing our userland.  Used for stuff like
 # choosing Hurd filesystem module.
@@ -170,13 +172,20 @@
 
 if [ "x${GRUB_ACTUAL_DEFAULT}" = "xsaved" ] ; then GRUB_ACTUAL_DEFAULT="`"${grub_editenv}" - list | sed -n '/^saved_entry=/ s,^saved_entry=,,p'`" ; fi
 
+# Default to UUID if GRUB_DEVICE_IDENTIFICATION is undefined or unrecognised
+if [ "x${GRUB_DEVICE_IDENTIFICATION}" = "x" ] ; then GRUB_DEVICE_IDENTIFICATION="uuid" ; fi
+if [ "${GRUB_DEVICE_IDENTIFICATION}" != "uuid" -a "${GRUB_DEVICE_IDENTIFICATION}" != "label" -a "${GRUB_DEVICE_IDENTIFICATION}" != "path" ] ; then
+    GRUB_DEVICE_IDENTIFICATION="uuid"
+fi
 
 # These are defined in this script, export them here so that user can
 # override them.
 export GRUB_DEVICE \
   GRUB_DEVICE_UUID \
+  GRUB_DEVICE_LABEL \
   GRUB_DEVICE_BOOT \
   GRUB_DEVICE_BOOT_UUID \
+  GRUB_DEVICE_BOOT_LABEL \
   GRUB_FS \
   GRUB_FONT \
   GRUB_PRELOAD_MODULES \

=== modified file 'util/grub-mkconfig_lib.in'

util/grub-mkconfig_lib.in +13 -5
@@ -146,22 +146,30 @@
       done
   fi
 
-  # If there's a filesystem UUID that GRUB is capable of identifying, use it;
+  # If there's a filesystem UUID or label that GRUB is capable of identifying, use it according to GRUB_DEVICE_IDENTIFICATION
   # otherwise set root as per value in device.map.
   fs_hint="`"${grub_probe}" --device "${device}" --target=compatibility_hint`"
   if [ "x$fs_hint" != x ]; then
     echo "set root='$fs_hint'"
   fi
-  if fs_uuid="`"${grub_probe}" --device "${device}" --target=fs_uuid 2> /dev/null`" ; then
+  if [ "x${GRUB_DEVICE_IDENTIFICATION}" = "xlabel" ] && fs_label="`"${grub_probe}" --device "${device}" --target=fs_label 2> /dev/null`" ; then
     hints="`"${grub_probe}" --device "${device}" --target=hints_string 2> /dev/null`" || hints=
     echo "if [ x\$feature_platform_search_hint = xy ]; then"
-    echo "  search --no-floppy --fs-uuid --set=root ${hints} ${fs_uuid}"
+    echo "  search --no-floppy --label --set=root ${hints} ${fs_label}"
     echo "else"
-    echo "  search --no-floppy --fs-uuid --set=root ${fs_uuid}"
+    echo "  search --no-floppy --label --set=root ${fs_label}"
     echo "fi"
+  else
+    if fs_uuid="`"${grub_probe}" --device "${device}" --target=fs_uuid 2> /dev/null`" ; then
+      hints="`"${grub_probe}" --device "${device}" --target=hints_string 2> /dev/null`" || hints=
+      echo "if [ x\$feature_platform_search_hint = xy ]; then"
+      echo "  search --no-floppy --fs-uuid --set=root ${hints} ${fs_uuid}"
+      echo "else"
+      echo "  search --no-floppy --fs-uuid --set=root ${fs_uuid}"
+      echo "fi"
+    fi
   fi
 }
-
 grub_get_device_id ()
 {
   device="$1"

=== modified file 'util/grub.d/10_linux.in'

util/grub.d/10_linux.in +21 -7
@@ -43,13 +43,27 @@
   ;;
 esac
 
-if [ "x${GRUB_DEVICE_UUID}" = "x" ] || [ "x${GRUB_DISABLE_LINUX_UUID}" = "xtrue" ] \
-    || ! test -e "/dev/disk/by-uuid/${GRUB_DEVICE_UUID}" \
-    || uses_abstraction "${GRUB_DEVICE}" lvm; then
-  LINUX_ROOT_DEVICE=${GRUB_DEVICE}
-else
-  LINUX_ROOT_DEVICE=UUID=${GRUB_DEVICE_UUID}
-fi
+case x"$GRUB_DEVICE_IDENTIFICATION" in
+    xpath)
+        LINUX_ROOT_DEVICE=${GRUB_DEVICE}
+        ;;
+    xlabel)
+        if [ "x${GRUB_DEVICE_LABEL}" = "x" ] \
+            || ! test -e "/dev/disk/by-label/${GRUB_DEVICE_LABEL}" \
+            || uses_abstraction "${GRUB_DEVICE}" lvm; then
+            LINUX_ROOT_DEVICE=${GRUB_DEVICE}
+        else
+            LINUX_ROOT_DEVICE=LABEL=\"${GRUB_DEVICE_LABEL}\"
+        fi;;
+    *)
+        if [ "x{GRUB_DEVICE_UUID}" = "x" ] \
+            || ! test -e "/dev/disk/by-uuid/${GRUB_DEVICE_UUID}" \
+            || uses_abstraction "${GRUB_DEVICE}" lvm; then
+            LINUX_ROOT_DEVICE=${GRUB_DEVICE}
+        else
+            LINUX_ROOT_DEVICE=UUID=${GRUB_DEVICE_UUID}
+        fi;;      
+esac
 
 GRUBFS="`${grub_probe} --device ${GRUB_DEVICE} --target=fs 2>/dev/null || true`"
 
#1 lore raw
Quoted 10 lines · Pete Appleton

Hi all,

The file attached is intended to allow a Linux user to easily specify whether GRUB2 should use the traditional device path (/dev/sda1) or the filesystem label instead of the default UUID scheme. This functionality is currently supported by GRUB2 itself but the peripheral files (grub-mkconfig, 10-linux etc) don't directly support it, requiring the user to edit the distribution-supplied files on their installation with the potential for consequent upgrade conflicts.

Quoted 7 lines

This patch adds support for a new environment variable GRUB_DEVICE_IDENTIFICATION taking as value one of {uuid, label, path}; if not set or invalid then it defaults to uuid so that the current semantics are respected. If set to label then the 'search' clause and root=XXX kernel parameter are written using file system label syntax as opposed to the current single behaviour of device path if GRUB_DISABLE_LINUX_UUID=true

In this patch the same option has effect on both how device is passed to kernel and how it's identified internally. These 2 parts should be kept separate.

Quoted 17 lines

This patch was written after needing the functionality in my environment as I frequently move filesystems around a multi-spindle system (using the label to keep track of them) and seeing a few articles online advising various modifications to distribution supplied files; I hope that it is deemed useful enough to get incorporated into trunk to remove this minor niggle with a great product.

Thanks,

Pete Appleton

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

Signature · 2 lines
Regards
Vladimir 'φ-coder/phcoder' Serbinenko
#2 lore raw
Quoted 20 lines · Vladimir 'φ-coder/phcoder' Serbinenko
Quoted 10 lines · Pete Appleton

Hi all,

The file attached is intended to allow a Linux user to easily specify whether GRUB2 should use the traditional device path (/dev/sda1) or the filesystem label instead of the default UUID scheme. This functionality is currently supported by GRUB2 itself but the peripheral files (grub-mkconfig, 10-linux etc) don't directly support it, requiring the user to edit the distribution-supplied files on their installation with the potential for consequent upgrade conflicts.

Quoted 7 lines

This patch adds support for a new environment variable GRUB_DEVICE_IDENTIFICATION taking as value one of {uuid, label, path}; if not set or invalid then it defaults to uuid so that the current semantics are respected. If set to label then the 'search' clause and root=XXX kernel parameter are written using file system label syntax as opposed to the current single behaviour of device path if GRUB_DISABLE_LINUX_UUID=true

Quoted 3 lines

In this patch the same option has effect on both how device is passed to kernel and how it's identified internally. These 2 parts should be kept separate.

Update attached which splits the option into GRUB_DEVICE_IDENTIFICATION (used by 10-linux for the root FS) and GRUB_SEARCH_METHOD, used by grub-mkconfig to generate the search clause.

Pete Appleton

=== modified file 'docs/grub.texi'

docs/grub.texi +13 -0
@@ -1285,6 +1285,19 @@
 the Linux kernel, using a @samp{root=UUID=...} kernel parameter.  This is
 usually more reliable, but in some cases it may not be appropriate.  To
 disable the use of UUIDs, set this option to @samp{true}.
+@samp{GRUB_DEVICE_IDENTIFICATION} governs the scheme used instead of
+the UUID, either the file system label or the traditional device path
+
+@item GRUB_DEVICE_IDENTIFICATION
+Works in conjunction with GRUB_DISABLE_LINUX_UUID to determine how the root filesystem
+will be identified for the Linux kernel.  The default value is @samp{uuid}, which will use UUIDs. 
+Other alternatives are @samp{label} to use the file system label, or @samp{path} to use
+the traditional device path (@samp{/dev/sda1})
+
+@item GRUB_SEARCH_METHOD
+Governs the method used to generate the search directive (as opposed to the Linux root filesysttem)
+using the same settings as @samp{GRUB_DEVICE_IDENTIFICATION}.  If unset or unrecognised
+then GRUB will default to searching by UUID
 
 @item GRUB_DISABLE_RECOVERY
 If this option is set to @samp{true}, disable the generation of recovery

=== modified file 'util/grub-mkconfig.in'

util/grub-mkconfig.in +16 -1
@@ -131,10 +131,12 @@
 # Device containing our userland.  Typically used for root= parameter.
 GRUB_DEVICE="`${grub_probe} --target=device /`"
 GRUB_DEVICE_UUID="`${grub_probe} --device ${GRUB_DEVICE} --target=fs_uuid 2> /dev/null`" || true
+GRUB_DEVICE_LABEL="`${grub_probe} --device ${GRUB_DEVICE} --target=fs_label 2> /dev/null`" || true
 
 # Device containing our /boot partition.  Usually the same as GRUB_DEVICE.
 GRUB_DEVICE_BOOT="`${grub_probe} --target=device /boot`"
 GRUB_DEVICE_BOOT_UUID="`${grub_probe} --device ${GRUB_DEVICE_BOOT} --target=fs_uuid 2> /dev/null`" || true
+GRUB_DEVICE_BOOT_LABEL="`${grub_probe} --device ${GRUB_DEVICE_BOOT} --target=fs_label 2> /dev/null`" || 
 
 # Filesystem for the device containing our userland.  Used for stuff like
 # choosing Hurd filesystem module.
@@ -170,13 +172,24 @@
 
 if [ "x${GRUB_ACTUAL_DEFAULT}" = "xsaved" ] ; then GRUB_ACTUAL_DEFAULT="`"${grub_editenv}" - list | sed -n '/^saved_entry=/ s,^saved_entry=,,p'`" ; fi
 
+# Default to UUID if GRUB_DEVICE_IDENTIFICATION is undefined or unrecognised
+if [ "x${GRUB_DEVICE_IDENTIFICATION}" = "x" ] ; then GRUB_DEVICE_IDENTIFICATION="uuid" ; fi
+if [ "${GRUB_DEVICE_IDENTIFICATION}" != "uuid" -a "${GRUB_DEVICE_IDENTIFICATION}" != "label" -a "${GRUB_DEVICE_IDENTIFICATION}" != "path" ] ; then
+    GRUB_DEVICE_IDENTIFICATION="uuid"
+fi
+if [ "x${GRUB_SEARCH_METHOD}" = "x" ] ; then GRUB_SEARCH_METHOD="uuid" ; fi
+if [ "${GRUB_SEARCH_METHOD}" != "uuid" -a "${GRUB_SEARCH_METHOD}" != "label" -a "${GRUB_SEARCH_METHOD}" != "path" ] ; then
+    GRUB_SEARCH_METHOD="uuid"
+fi
 
 # These are defined in this script, export them here so that user can
 # override them.
 export GRUB_DEVICE \
   GRUB_DEVICE_UUID \
+  GRUB_DEVICE_LABEL \
   GRUB_DEVICE_BOOT \
   GRUB_DEVICE_BOOT_UUID \
+  GRUB_DEVICE_BOOT_LABEL \
   GRUB_FS \
   GRUB_FONT \
   GRUB_PRELOAD_MODULES \
@@ -216,7 +229,9 @@
   GRUB_INIT_TUNE \
   GRUB_SAVEDEFAULT \
   GRUB_ENABLE_CRYPTODISK \
-  GRUB_BADRAM
+  GRUB_BADRAM \
+  GRUB_DEVICE_IDENTIFICATION \
+  GRUB_SEARCH_METHOD
 
 if test "x${grub_cfg}" != "x"; then
   rm -f "${grub_cfg}.new"

=== modified file 'util/grub-mkconfig_lib.in'

util/grub-mkconfig_lib.in +13 -5
@@ -146,22 +146,30 @@
       done
   fi
 
-  # If there's a filesystem UUID that GRUB is capable of identifying, use it;
+  # If there's a filesystem UUID or label that GRUB is capable of identifying, use it according to GRUB_SEARCH_METHOD
   # otherwise set root as per value in device.map.
   fs_hint="`"${grub_probe}" --device "${device}" --target=compatibility_hint`"
   if [ "x$fs_hint" != x ]; then
     echo "set root='$fs_hint'"
   fi
-  if fs_uuid="`"${grub_probe}" --device "${device}" --target=fs_uuid 2> /dev/null`" ; then
+  if [ "x${GRUB_SEARCH_METHOD}" = "xlabel" ] && fs_label="`"${grub_probe}" --device "${device}" --target=fs_label 2> /dev/null`" ; then
     hints="`"${grub_probe}" --device "${device}" --target=hints_string 2> /dev/null`" || hints=
     echo "if [ x\$feature_platform_search_hint = xy ]; then"
-    echo "  search --no-floppy --fs-uuid --set=root ${hints} ${fs_uuid}"
+    echo "  search --no-floppy --label --set=root ${hints} ${fs_label}"
     echo "else"
-    echo "  search --no-floppy --fs-uuid --set=root ${fs_uuid}"
+    echo "  search --no-floppy --label --set=root ${fs_label}"
     echo "fi"
+  else
+    if fs_uuid="`"${grub_probe}" --device "${device}" --target=fs_uuid 2> /dev/null`" ; then
+      hints="`"${grub_probe}" --device "${device}" --target=hints_string 2> /dev/null`" || hints=
+      echo "if [ x\$feature_platform_search_hint = xy ]; then"
+      echo "  search --no-floppy --fs-uuid --set=root ${hints} ${fs_uuid}"
+      echo "else"
+      echo "  search --no-floppy --fs-uuid --set=root ${fs_uuid}"
+      echo "fi"
+    fi
   fi
 }
-
 grub_get_device_id ()
 {
   device="$1"

=== modified file 'util/grub.d/10_linux.in'

util/grub.d/10_linux.in +21 -7
@@ -43,13 +43,27 @@
   ;;
 esac
 
-if [ "x${GRUB_DEVICE_UUID}" = "x" ] || [ "x${GRUB_DISABLE_LINUX_UUID}" = "xtrue" ] \
-    || ! test -e "/dev/disk/by-uuid/${GRUB_DEVICE_UUID}" \
-    || uses_abstraction "${GRUB_DEVICE}" lvm; then
-  LINUX_ROOT_DEVICE=${GRUB_DEVICE}
-else
-  LINUX_ROOT_DEVICE=UUID=${GRUB_DEVICE_UUID}
-fi
+case x"$GRUB_DEVICE_IDENTIFICATION" in
+    xpath)
+        LINUX_ROOT_DEVICE=${GRUB_DEVICE}
+        ;;
+    xlabel)
+        if [ "x${GRUB_DEVICE_LABEL}" = "x" ] \
+            || ! test -e "/dev/disk/by-label/${GRUB_DEVICE_LABEL}" \
+            || uses_abstraction "${GRUB_DEVICE}" lvm; then
+            LINUX_ROOT_DEVICE=${GRUB_DEVICE}
+        else
+            LINUX_ROOT_DEVICE=LABEL=\"${GRUB_DEVICE_LABEL}\"
+        fi;;
+    *)
+        if [ "x{GRUB_DEVICE_UUID}" = "x" ] \
+            || ! test -e "/dev/disk/by-uuid/${GRUB_DEVICE_UUID}" \
+            || uses_abstraction "${GRUB_DEVICE}" lvm; then
+            LINUX_ROOT_DEVICE=${GRUB_DEVICE}
+        else
+            LINUX_ROOT_DEVICE=UUID=${GRUB_DEVICE_UUID}
+        fi;;      
+esac
 
 GRUBFS="`${grub_probe} --device ${GRUB_DEVICE} --target=fs 2>/dev/null || true`"
 
#3 lore raw
Quoted 22 lines · Pete Appleton
Quoted 20 lines · Vladimir 'φ-coder/phcoder' Serbinenko
Quoted 17 lines · Pete Appleton

Hi all,

The file attached is intended to allow a Linux user to easily specify whether GRUB2 should use the traditional device path (/dev/sda1) or the filesystem label instead of the default UUID scheme. This functionality is currently supported by GRUB2 itself but the peripheral files (grub-mkconfig, 10-linux etc) don't directly support it, requiring the user to edit the distribution-supplied files on their installation with the potential for consequent upgrade conflicts.

This patch adds support for a new environment variable GRUB_DEVICE_IDENTIFICATION taking as value one of {uuid, label, path}; if not set or invalid then it defaults to uuid so that the current semantics are respected. If set to label then the 'search' clause and root=XXX kernel parameter are written using file system label syntax as opposed to the current single behaviour of device path if GRUB_DISABLE_LINUX_UUID=true

Quoted 6 lines
Quoted 3 lines

In this patch the same option has effect on both how device is passed to kernel and how it's identified internally. These 2 parts should be kept separate.

Update attached which splits the option into GRUB_DEVICE_IDENTIFICATION (used by 10-linux for the root FS)

This is Linux-specific then, so it has to contain "LINUX" in its name.

Quoted 36 lines

and GRUB_SEARCH_METHOD, used by
grub-mkconfig to generate the search clause.

Pete Appleton

linux_fslabel_support.patch

=== modified file 'docs/grub.texi'

docs/grub.texi +13 -0
@@ -1285,6 +1285,19 @@
 the Linux kernel, using a @samp{root=UUID=...} kernel parameter.  This is
 usually more reliable, but in some cases it may not be appropriate.  To
 disable the use of UUIDs, set this option to @samp{true}.
+@samp{GRUB_DEVICE_IDENTIFICATION} governs the scheme used instead of
+the UUID, either the file system label or the traditional device path
+
+@item GRUB_DEVICE_IDENTIFICATION
+Works in conjunction with GRUB_DISABLE_LINUX_UUID to determine how the root filesystem
+will be identified for the Linux kernel.  The default value is @samp{uuid}, which will use UUIDs. 
+Other alternatives are @samp{label} to use the file system label, or @samp{path} to use
+the traditional device path (@samp{/dev/sda1})
+
+@item GRUB_SEARCH_METHOD
+Governs the method used to generate the search directive (as opposed to the Linux root filesysttem)
+using the same settings as @samp{GRUB_DEVICE_IDENTIFICATION}.  If unset or unrecognised
+then GRUB will default to searching by UUID
 
 @item GRUB_DISABLE_RECOVERY
 If this option is set to @samp{true}, disable the generation of recovery

=== modified file 'util/grub-mkconfig.in'

util/grub-mkconfig.in line 140

Quoted 10 lines
util/grub-mkconfig.in +2 -0
@@ -131,10 +131,12 @@
 # Device containing our userland.  Typically used for root= parameter.
 GRUB_DEVICE="`${grub_probe} --target=device /`"
 GRUB_DEVICE_UUID="`${grub_probe} --device ${GRUB_DEVICE} --target=fs_uuid 2> /dev/null`" || true
+GRUB_DEVICE_LABEL="`${grub_probe} --device ${GRUB_DEVICE} --target=fs_label 2> /dev/null`" || true
 
 # Device containing our /boot partition.  Usually the same as GRUB_DEVICE.
 GRUB_DEVICE_BOOT="`${grub_probe} --target=device /boot`"
 GRUB_DEVICE_BOOT_UUID="`${grub_probe} --device ${GRUB_DEVICE_BOOT} --target=fs_uuid 2> /dev/null`" || true
+GRUB_DEVICE_BOOT_LABEL="`${grub_probe} --device ${GRUB_DEVICE_BOOT} --target=fs_label 2> /dev/null`" || 
 

"true" was lost.
Also it doesn't seem that you use this variable anywhere.

Quoted 6 lines
util/grub-mkconfig.in +0 -0
 # Filesystem for the device containing our userland.  Used for stuff like
 # choosing Hurd filesystem module.
@@ -170,13 +172,24 @@
 
 if [ "x${GRUB_ACTUAL_DEFAULT}" = "xsaved" ] ; then GRUB_ACTUAL_DEFAULT="`"${grub_editenv}" - list | sed -n '/^saved_entry=/ s,^saved_entry=,,p'`" ; fi
 

util/grub-mkconfig.in line 184

Quoted 10 lines
util/grub-mkconfig.in +9 -0
+# Default to UUID if GRUB_DEVICE_IDENTIFICATION is undefined or unrecognised
+if [ "x${GRUB_DEVICE_IDENTIFICATION}" = "x" ] ; then GRUB_DEVICE_IDENTIFICATION="uuid" ; fi
+if [ "${GRUB_DEVICE_IDENTIFICATION}" != "uuid" -a "${GRUB_DEVICE_IDENTIFICATION}" != "label" -a "${GRUB_DEVICE_IDENTIFICATION}" != "path" ] ; then
+    GRUB_DEVICE_IDENTIFICATION="uuid"
+fi
+if [ "x${GRUB_SEARCH_METHOD}" = "x" ] ; then GRUB_SEARCH_METHOD="uuid" ; fi
+if [ "${GRUB_SEARCH_METHOD}" != "uuid" -a "${GRUB_SEARCH_METHOD}" != "label" -a "${GRUB_SEARCH_METHOD}" != "path" ] ; then
+    GRUB_SEARCH_METHOD="uuid"
+fi
 

case ... esac would be much more appropriate in this case.

Quoted 109 lines
util/grub-mkconfig.in +5 -1
 # These are defined in this script, export them here so that user can
 # override them.
 export GRUB_DEVICE \
   GRUB_DEVICE_UUID \
+  GRUB_DEVICE_LABEL \
   GRUB_DEVICE_BOOT \
   GRUB_DEVICE_BOOT_UUID \
+  GRUB_DEVICE_BOOT_LABEL \
   GRUB_FS \
   GRUB_FONT \
   GRUB_PRELOAD_MODULES \
@@ -216,7 +229,9 @@
   GRUB_INIT_TUNE \
   GRUB_SAVEDEFAULT \
   GRUB_ENABLE_CRYPTODISK \
-  GRUB_BADRAM
+  GRUB_BADRAM \
+  GRUB_DEVICE_IDENTIFICATION \
+  GRUB_SEARCH_METHOD
 
 if test "x${grub_cfg}" != "x"; then
   rm -f "${grub_cfg}.new"

=== modified file 'util/grub-mkconfig_lib.in'

util/grub-mkconfig_lib.in +13 -5
@@ -146,22 +146,30 @@
       done
   fi
 
-  # If there's a filesystem UUID that GRUB is capable of identifying, use it;
+  # If there's a filesystem UUID or label that GRUB is capable of identifying, use it according to GRUB_SEARCH_METHOD
   # otherwise set root as per value in device.map.
   fs_hint="`"${grub_probe}" --device "${device}" --target=compatibility_hint`"
   if [ "x$fs_hint" != x ]; then
     echo "set root='$fs_hint'"
   fi
-  if fs_uuid="`"${grub_probe}" --device "${device}" --target=fs_uuid 2> /dev/null`" ; then
+  if [ "x${GRUB_SEARCH_METHOD}" = "xlabel" ] && fs_label="`"${grub_probe}" --device "${device}" --target=fs_label 2> /dev/null`" ; then
     hints="`"${grub_probe}" --device "${device}" --target=hints_string 2> /dev/null`" || hints=
     echo "if [ x\$feature_platform_search_hint = xy ]; then"
-    echo "  search --no-floppy --fs-uuid --set=root ${hints} ${fs_uuid}"
+    echo "  search --no-floppy --label --set=root ${hints} ${fs_label}"
     echo "else"
-    echo "  search --no-floppy --fs-uuid --set=root ${fs_uuid}"
+    echo "  search --no-floppy --label --set=root ${fs_label}"
     echo "fi"
+  else
+    if fs_uuid="`"${grub_probe}" --device "${device}" --target=fs_uuid 2> /dev/null`" ; then
+      hints="`"${grub_probe}" --device "${device}" --target=hints_string 2> /dev/null`" || hints=
+      echo "if [ x\$feature_platform_search_hint = xy ]; then"
+      echo "  search --no-floppy --fs-uuid --set=root ${hints} ${fs_uuid}"
+      echo "else"
+      echo "  search --no-floppy --fs-uuid --set=root ${fs_uuid}"
+      echo "fi"
+    fi
   fi
 }
-
 grub_get_device_id ()
 {
   device="$1"

=== modified file 'util/grub.d/10_linux.in'

util/grub.d/10_linux.in +21 -7
@@ -43,13 +43,27 @@
   ;;
 esac
 
-if [ "x${GRUB_DEVICE_UUID}" = "x" ] || [ "x${GRUB_DISABLE_LINUX_UUID}" = "xtrue" ] \
-    || ! test -e "/dev/disk/by-uuid/${GRUB_DEVICE_UUID}" \
-    || uses_abstraction "${GRUB_DEVICE}" lvm; then
-  LINUX_ROOT_DEVICE=${GRUB_DEVICE}
-else
-  LINUX_ROOT_DEVICE=UUID=${GRUB_DEVICE_UUID}
-fi
+case x"$GRUB_DEVICE_IDENTIFICATION" in
+    xpath)
+        LINUX_ROOT_DEVICE=${GRUB_DEVICE}
+        ;;
+    xlabel)
+        if [ "x${GRUB_DEVICE_LABEL}" = "x" ] \
+            || ! test -e "/dev/disk/by-label/${GRUB_DEVICE_LABEL}" \
+            || uses_abstraction "${GRUB_DEVICE}" lvm; then
+            LINUX_ROOT_DEVICE=${GRUB_DEVICE}
+        else
+            LINUX_ROOT_DEVICE=LABEL=\"${GRUB_DEVICE_LABEL}\"
+        fi;;
+    *)
+        if [ "x{GRUB_DEVICE_UUID}" = "x" ] \
+            || ! test -e "/dev/disk/by-uuid/${GRUB_DEVICE_UUID}" \
+            || uses_abstraction "${GRUB_DEVICE}" lvm; then
+            LINUX_ROOT_DEVICE=${GRUB_DEVICE}
+        else
+            LINUX_ROOT_DEVICE=UUID=${GRUB_DEVICE_UUID}
+        fi;;      
+esac
 
 GRUBFS="`${grub_probe} --device ${GRUB_DEVICE} --target=fs 2>/dev/null || true`"
 

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

Signature · 2 lines
Regards
Vladimir 'φ-coder/phcoder' Serbinenko
#4 lore raw
Quoted 202 lines · Vladimir '?-coder/phcoder' Serbinenko
Quoted 20 lines · Pete Appleton
Quoted 19 lines · Vladimir '?-coder/phcoder' Serbinenko
Quoted 17 lines · Pete Appleton

Hi all,

The file attached is intended to allow a Linux user to easily specify whether GRUB2 should use the traditional device path (/dev/sda1) or the filesystem label instead of the default UUID scheme. This functionality is currently supported by GRUB2 itself but the peripheral files (grub-mkconfig, 10-linux etc) don't directly support it, requiring the user to edit the distribution-supplied files on their installation with the potential for consequent upgrade conflicts.

This patch adds support for a new environment variable GRUB_DEVICE_IDENTIFICATION taking as value one of {uuid, label, path}; if not set or invalid then it defaults to uuid so that the current semantics are respected. If set to label then the 'search' clause and root=XXX kernel parameter are written using file system label syntax as opposed to the current single behaviour of device path if GRUB_DISABLE_LINUX_UUID=true

Quoted 5 lines
Quoted 3 lines

In this patch the same option has effect on both how device is passed to kernel and how it's identified internally. These 2 parts should be kept separate.

Update attached which splits the option into GRUB_DEVICE_IDENTIFICATION (used by 10-linux for the root FS)

This is Linux-specific then, so it has to contain "LINUX" in its name.

Quoted 36 lines

and GRUB_SEARCH_METHOD, used by
grub-mkconfig to generate the search clause.

Pete Appleton

linux_fslabel_support.patch

=== modified file 'docs/grub.texi'

docs/grub.texi +13 -0
@@ -1285,6 +1285,19 @@
  the Linux kernel, using a @samp{root=UUID=...} kernel parameter.  This is
  usually more reliable, but in some cases it may not be appropriate.  To
  disable the use of UUIDs, set this option to @samp{true}.
+@samp{GRUB_DEVICE_IDENTIFICATION} governs the scheme used instead of
+the UUID, either the file system label or the traditional device path
+
+@item GRUB_DEVICE_IDENTIFICATION
+Works in conjunction with GRUB_DISABLE_LINUX_UUID to determine how the root filesystem
+will be identified for the Linux kernel.  The default value is @samp{uuid}, which will use UUIDs.
+Other alternatives are @samp{label} to use the file system label, or @samp{path} to use
+the traditional device path (@samp{/dev/sda1})
+
+@item GRUB_SEARCH_METHOD
+Governs the method used to generate the search directive (as opposed to the Linux root filesysttem)
+using the same settings as @samp{GRUB_DEVICE_IDENTIFICATION}.  If unset or unrecognised
+then GRUB will default to searching by UUID
 
  @item GRUB_DISABLE_RECOVERY
  If this option is set to @samp{true}, disable the generation of recovery

=== modified file 'util/grub-mkconfig.in'

util/grub-mkconfig.in line 140

Quoted 10 lines
util/grub-mkconfig.in +2 -0
@@ -131,10 +131,12 @@
  # Device containing our userland.  Typically used for root= parameter.
  GRUB_DEVICE="`${grub_probe} --target=device /`"
  GRUB_DEVICE_UUID="`${grub_probe} --device ${GRUB_DEVICE} --target=fs_uuid 2> /dev/null`" || true
+GRUB_DEVICE_LABEL="`${grub_probe} --device ${GRUB_DEVICE} --target=fs_label 2> /dev/null`" || true
 
  # Device containing our /boot partition.  Usually the same as GRUB_DEVICE.
  GRUB_DEVICE_BOOT="`${grub_probe} --target=device /boot`"
  GRUB_DEVICE_BOOT_UUID="`${grub_probe} --device ${GRUB_DEVICE_BOOT} --target=fs_uuid 2> /dev/null`" || true
+GRUB_DEVICE_BOOT_LABEL="`${grub_probe} --device ${GRUB_DEVICE_BOOT} --target=fs_label 2> /dev/null`" ||
 

"true" was lost.
Also it doesn't seem that you use this variable anywhere.

Quoted 6 lines
util/grub-mkconfig.in +0 -0
  # Filesystem for the device containing our userland.  Used for stuff like
  # choosing Hurd filesystem module.
@@ -170,13 +172,24 @@
 
  if [ "x${GRUB_ACTUAL_DEFAULT}" = "xsaved" ] ; then GRUB_ACTUAL_DEFAULT="`"${grub_editenv}" - list | sed -n '/^saved_entry=/ s,^saved_entry=,,p'`" ; fi
 

util/grub-mkconfig.in line 184

Quoted 10 lines
util/grub-mkconfig.in +9 -0
+# Default to UUID if GRUB_DEVICE_IDENTIFICATION is undefined or unrecognised
+if [ "x${GRUB_DEVICE_IDENTIFICATION}" = "x" ] ; then GRUB_DEVICE_IDENTIFICATION="uuid" ; fi
+if [ "${GRUB_DEVICE_IDENTIFICATION}" != "uuid" -a "${GRUB_DEVICE_IDENTIFICATION}" != "label" -a "${GRUB_DEVICE_IDENTIFICATION}" != "path" ] ; then
+    GRUB_DEVICE_IDENTIFICATION="uuid"
+fi
+if [ "x${GRUB_SEARCH_METHOD}" = "x" ] ; then GRUB_SEARCH_METHOD="uuid" ; fi
+if [ "${GRUB_SEARCH_METHOD}" != "uuid" -a "${GRUB_SEARCH_METHOD}" != "label" -a "${GRUB_SEARCH_METHOD}" != "path" ] ; then
+    GRUB_SEARCH_METHOD="uuid"
+fi
 

case ... esac would be much more appropriate in this case.

Quoted 105 lines
util/grub-mkconfig.in +5 -1
  # These are defined in this script, export them here so that user can
  # override them.
  export GRUB_DEVICE \
    GRUB_DEVICE_UUID \
+  GRUB_DEVICE_LABEL \
    GRUB_DEVICE_BOOT \
    GRUB_DEVICE_BOOT_UUID \
+  GRUB_DEVICE_BOOT_LABEL \
    GRUB_FS \
    GRUB_FONT \
    GRUB_PRELOAD_MODULES \
@@ -216,7 +229,9 @@
    GRUB_INIT_TUNE \
    GRUB_SAVEDEFAULT \
    GRUB_ENABLE_CRYPTODISK \
-  GRUB_BADRAM
+  GRUB_BADRAM \
+  GRUB_DEVICE_IDENTIFICATION \
+  GRUB_SEARCH_METHOD
 
  if test "x${grub_cfg}" != "x"; then
    rm -f "${grub_cfg}.new"

=== modified file 'util/grub-mkconfig_lib.in'

util/grub-mkconfig_lib.in +13 -5
@@ -146,22 +146,30 @@
        done
    fi
 
-  # If there's a filesystem UUID that GRUB is capable of identifying, use it;
+  # If there's a filesystem UUID or label that GRUB is capable of identifying, use it according to GRUB_SEARCH_METHOD
    # otherwise set root as per value in device.map.
    fs_hint="`"${grub_probe}" --device "${device}" --target=compatibility_hint`"
    if [ "x$fs_hint" != x ]; then
      echo "set root='$fs_hint'"
    fi
-  if fs_uuid="`"${grub_probe}" --device "${device}" --target=fs_uuid 2> /dev/null`" ; then
+  if [ "x${GRUB_SEARCH_METHOD}" = "xlabel" ] && fs_label="`"${grub_probe}" --device "${device}" --target=fs_label 2> /dev/null`" ; then
      hints="`"${grub_probe}" --device "${device}" --target=hints_string 2> /dev/null`" || hints=
      echo "if [ x\$feature_platform_search_hint = xy ]; then"
-    echo "  search --no-floppy --fs-uuid --set=root ${hints} ${fs_uuid}"
+    echo "  search --no-floppy --label --set=root ${hints} ${fs_label}"
      echo "else"
-    echo "  search --no-floppy --fs-uuid --set=root ${fs_uuid}"
+    echo "  search --no-floppy --label --set=root ${fs_label}"
      echo "fi"
+  else
+    if fs_uuid="`"${grub_probe}" --device "${device}" --target=fs_uuid 2> /dev/null`" ; then
+      hints="`"${grub_probe}" --device "${device}" --target=hints_string 2> /dev/null`" || hints=
+      echo "if [ x\$feature_platform_search_hint = xy ]; then"
+      echo "  search --no-floppy --fs-uuid --set=root ${hints} ${fs_uuid}"
+      echo "else"
+      echo "  search --no-floppy --fs-uuid --set=root ${fs_uuid}"
+      echo "fi"
+    fi
    fi
  }
-
  grub_get_device_id ()
  {
    device="$1"

=== modified file 'util/grub.d/10_linux.in'

util/grub.d/10_linux.in +21 -7
@@ -43,13 +43,27 @@
    ;;
  esac
 
-if [ "x${GRUB_DEVICE_UUID}" = "x" ] || [ "x${GRUB_DISABLE_LINUX_UUID}" = "xtrue" ] \
-    || ! test -e "/dev/disk/by-uuid/${GRUB_DEVICE_UUID}" \
-    || uses_abstraction "${GRUB_DEVICE}" lvm; then
-  LINUX_ROOT_DEVICE=${GRUB_DEVICE}
-else
-  LINUX_ROOT_DEVICE=UUID=${GRUB_DEVICE_UUID}
-fi
+case x"$GRUB_DEVICE_IDENTIFICATION" in
+    xpath)
+        LINUX_ROOT_DEVICE=${GRUB_DEVICE}
+        ;;
+    xlabel)
+        if [ "x${GRUB_DEVICE_LABEL}" = "x" ] \
+            || ! test -e "/dev/disk/by-label/${GRUB_DEVICE_LABEL}" \
+            || uses_abstraction "${GRUB_DEVICE}" lvm; then
+            LINUX_ROOT_DEVICE=${GRUB_DEVICE}
+        else
+            LINUX_ROOT_DEVICE=LABEL=\"${GRUB_DEVICE_LABEL}\"
+        fi;;
+    *)
+        if [ "x{GRUB_DEVICE_UUID}" = "x" ] \
+            || ! test -e "/dev/disk/by-uuid/${GRUB_DEVICE_UUID}" \
+            || uses_abstraction "${GRUB_DEVICE}" lvm; then
+            LINUX_ROOT_DEVICE=${GRUB_DEVICE}
+        else
+            LINUX_ROOT_DEVICE=UUID=${GRUB_DEVICE_UUID}
+        fi;;
+esac
 
  GRUBFS="`${grub_probe} --device ${GRUB_DEVICE} --target=fs 2>/dev/null || true`"
 
Quoted 12 lines
Quoted 4 lines

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

Attached version addresses these issues:

GRUB_DEVICE_IDENTIFICATION renamed to LINUX_DEVICE_IDENTIFICATION GRUB_DEVICE_LABEL renamed to LINUX_DEVICE_LABEL as also Linux specific GRUB_DEVICE_BOOT_LABEL removed completely as unused (was added
purely for symmetry)
if statements replaced by case

Pete Appleton

=== modified file 'docs/grub.texi'

docs/grub.texi +13 -0
@@ -1285,6 +1285,19 @@
 the Linux kernel, using a @samp{root=UUID=...} kernel parameter.  This is
 usually more reliable, but in some cases it may not be appropriate.  To
 disable the use of UUIDs, set this option to @samp{true}.
+@samp{LINUX_DEVICE_IDENTIFICATION} governs the scheme used instead of
+the UUID, either the file system label or the traditional device path
+
+@item LINUX_DEVICE_IDENTIFICATION
+Works in conjunction with GRUB_DISABLE_LINUX_UUID to determine how the root filesystem
+will be identified for the Linux kernel.  The default value is @samp{uuid}, which will use UUIDs. 
+Other alternatives are @samp{label} to use the file system label, or @samp{path} to use
+the traditional device path (@samp{/dev/sda1})
+
+@item GRUB_SEARCH_METHOD
+Governs the method used to generate the search directive (as opposed to the Linux root filesysttem)
+using the same settings as @samp{LINUX_DEVICE_IDENTIFICATION}.  If unset or unrecognised
+then GRUB will default to searching by UUID
 
 @item GRUB_DISABLE_RECOVERY
 If this option is set to @samp{true}, disable the generation of recovery

=== modified file 'util/grub-mkconfig.in'

util/grub-mkconfig.in +12 -1
@@ -131,6 +131,7 @@
 # Device containing our userland.  Typically used for root= parameter.
 GRUB_DEVICE="`${grub_probe} --target=device /`"
 GRUB_DEVICE_UUID="`${grub_probe} --device ${GRUB_DEVICE} --target=fs_uuid 2> /dev/null`" || true
+LINUX_DEVICE_LABEL="`${grub_probe} --device ${GRUB_DEVICE} --target=fs_label 2> /dev/null`" || true
 
 # Device containing our /boot partition.  Usually the same as GRUB_DEVICE.
 GRUB_DEVICE_BOOT="`${grub_probe} --target=device /boot`"
@@ -170,11 +171,19 @@
 
 if [ "x${GRUB_ACTUAL_DEFAULT}" = "xsaved" ] ; then GRUB_ACTUAL_DEFAULT="`"${grub_editenv}" - list | sed -n '/^saved_entry=/ s,^saved_entry=,,p'`" ; fi
 
+# Default to UUID if LINUX_DEVICE_IDENTIFICATION is undefined or unrecognised
+case "x${LINUX_DEVICE_IDENTIFICATION}" in
+    xuuid) ;;
+    xlabel) ;;
+    xpath)) ;;
+    *) LINUX_DEVICE_IDENTIFCATION = uuid ;;
+esac
 
 # These are defined in this script, export them here so that user can
 # override them.
 export GRUB_DEVICE \
   GRUB_DEVICE_UUID \
+  LINUX_DEVICE_LABEL \
   GRUB_DEVICE_BOOT \
   GRUB_DEVICE_BOOT_UUID \
   GRUB_FS \
@@ -216,7 +225,9 @@
   GRUB_INIT_TUNE \
   GRUB_SAVEDEFAULT \
   GRUB_ENABLE_CRYPTODISK \
-  GRUB_BADRAM
+  GRUB_BADRAM \
+  LINUX_DEVICE_IDENTIFICATION \
+  GRUB_SEARCH_METHOD
 
 if test "x${grub_cfg}" != "x"; then
   rm -f "${grub_cfg}.new"

=== modified file 'util/grub-mkconfig_lib.in'

util/grub-mkconfig_lib.in +13 -5
@@ -146,22 +146,30 @@
       done
   fi
 
-  # If there's a filesystem UUID that GRUB is capable of identifying, use it;
+  # If there's a filesystem UUID or label that GRUB is capable of identifying, use it according to GRUB_SEARCH_METHOD
   # otherwise set root as per value in device.map.
   fs_hint="`"${grub_probe}" --device "${device}" --target=compatibility_hint`"
   if [ "x$fs_hint" != x ]; then
     echo "set root='$fs_hint'"
   fi
-  if fs_uuid="`"${grub_probe}" --device "${device}" --target=fs_uuid 2> /dev/null`" ; then
+  if [ "x${GRUB_SEARCH_METHOD}" = "xlabel" ] && fs_label="`"${grub_probe}" --device "${device}" --target=fs_label 2> /dev/null`" ; then
     hints="`"${grub_probe}" --device "${device}" --target=hints_string 2> /dev/null`" || hints=
     echo "if [ x\$feature_platform_search_hint = xy ]; then"
-    echo "  search --no-floppy --fs-uuid --set=root ${hints} ${fs_uuid}"
+    echo "  search --no-floppy --label --set=root ${hints} ${fs_label}"
     echo "else"
-    echo "  search --no-floppy --fs-uuid --set=root ${fs_uuid}"
+    echo "  search --no-floppy --label --set=root ${fs_label}"
     echo "fi"
+  else
+    if fs_uuid="`"${grub_probe}" --device "${device}" --target=fs_uuid 2> /dev/null`" ; then
+      hints="`"${grub_probe}" --device "${device}" --target=hints_string 2> /dev/null`" || hints=
+      echo "if [ x\$feature_platform_search_hint = xy ]; then"
+      echo "  search --no-floppy --fs-uuid --set=root ${hints} ${fs_uuid}"
+      echo "else"
+      echo "  search --no-floppy --fs-uuid --set=root ${fs_uuid}"
+      echo "fi"
+    fi
   fi
 }
-
 grub_get_device_id ()
 {
   device="$1"

=== modified file 'util/grub.d/10_linux.in'

util/grub.d/10_linux.in +21 -7
@@ -43,13 +43,27 @@
   ;;
 esac
 
-if [ "x${GRUB_DEVICE_UUID}" = "x" ] || [ "x${GRUB_DISABLE_LINUX_UUID}" = "xtrue" ] \
-    || ! test -e "/dev/disk/by-uuid/${GRUB_DEVICE_UUID}" \
-    || uses_abstraction "${GRUB_DEVICE}" lvm; then
-  LINUX_ROOT_DEVICE=${GRUB_DEVICE}
-else
-  LINUX_ROOT_DEVICE=UUID=${GRUB_DEVICE_UUID}
-fi
+case x"$LINUX_DEVICE_IDENTIFICATION" in
+    xpath)
+        LINUX_ROOT_DEVICE=${GRUB_DEVICE}
+        ;;
+    xlabel)
+        if [ "x${LINUX_DEVICE_LABEL}" = "x" ] \
+            || ! test -e "/dev/disk/by-label/${GRUB_DEVICE_LABEL}" \
+            || uses_abstraction "${GRUB_DEVICE}" lvm; then
+            LINUX_ROOT_DEVICE=${GRUB_DEVICE}
+        else
+            LINUX_ROOT_DEVICE=LABEL=\"${LINUX_DEVICE_LABEL}\"
+        fi;;
+    *)
+        if [ "x{GRUB_DEVICE_UUID}" = "x" ] \
+            || ! test -e "/dev/disk/by-uuid/${GRUB_DEVICE_UUID}" \
+            || uses_abstraction "${GRUB_DEVICE}" lvm; then
+            LINUX_ROOT_DEVICE=${GRUB_DEVICE}
+        else
+            LINUX_ROOT_DEVICE=UUID=${GRUB_DEVICE_UUID}
+        fi;;      
+esac
 
 GRUBFS="`${grub_probe} --device ${GRUB_DEVICE} --target=fs 2>/dev/null || true`"
 
#5 lore raw
Quoted 5 lines · Pete Appleton

GRUB_DEVICE_IDENTIFICATION renamed to LINUX_DEVICE_IDENTIFICATION GRUB_DEVICE_LABEL renamed to LINUX_DEVICE_LABEL as also Linux specific GRUB_DEVICE_BOOT_LABEL removed completely as unused (was added
purely for symmetry)
if statements replaced by case

Linux-specific vars aren't exempted from the need to be in GRUB_* namespace.

Signature · 2 lines
Regards
Vladimir 'φ-coder/phcoder' Serbinenko
#6 lore raw
Quoted 8 lines · Vladimir 'φ-coder/phcoder' Serbinenko
Quoted 5 lines · Pete Appleton

GRUB_DEVICE_IDENTIFICATION renamed to LINUX_DEVICE_IDENTIFICATION GRUB_DEVICE_LABEL renamed to LINUX_DEVICE_LABEL as also Linux specific GRUB_DEVICE_BOOT_LABEL removed completely as unused (was added
purely for symmetry)
if statements replaced by case

Linux-specific vars aren't exempted from the need to be in GRUB_* namespace.

Renamed LINUX_DEVICE_IDENTIFICATION to GRUB_DEVICE_IDENTIFICATION_LINUX Renamed LINUX_DEVICE_LABEL to GRUB_DEVICE_LABEL_LINUX

Regards,

Pete Appleton

=== modified file 'docs/grub.texi'

docs/grub.texi +13 -0
@@ -1285,6 +1285,19 @@
 the Linux kernel, using a @samp{root=UUID=...} kernel parameter.  This is
 usually more reliable, but in some cases it may not be appropriate.  To
 disable the use of UUIDs, set this option to @samp{true}.
+@samp{GRUB_DEVICE_IDENTIFICATION_LINUX} governs the scheme used instead of
+the UUID, either the file system label or the traditional device path
+
+@item GRUB_DEVICE_IDENTIFICATION_LINUX
+Works in conjunction with GRUB_DISABLE_LINUX_UUID to determine how the root filesystem
+will be identified for the Linux kernel.  The default value is @samp{uuid}, which will use UUIDs. 
+Other alternatives are @samp{label} to use the file system label, or @samp{path} to use
+the traditional device path (@samp{/dev/sda1})
+
+@item GRUB_SEARCH_METHOD
+Governs the method used to generate the search directive (as opposed to the Linux root filesysttem)
+using the same settings as @samp{GRUB_DEVICE_IDENTIFICATION_LINUX}.  If unset or unrecognised
+then GRUB will default to searching by UUID
 
 @item GRUB_DISABLE_RECOVERY
 If this option is set to @samp{true}, disable the generation of recovery

=== modified file 'util/grub-mkconfig.in'

util/grub-mkconfig.in +12 -1
@@ -131,6 +131,7 @@
 # Device containing our userland.  Typically used for root= parameter.
 GRUB_DEVICE="`${grub_probe} --target=device /`"
 GRUB_DEVICE_UUID="`${grub_probe} --device ${GRUB_DEVICE} --target=fs_uuid 2> /dev/null`" || true
+GRUB_DEVICE_LABEL_LINUX="`${grub_probe} --device ${GRUB_DEVICE} --target=fs_label 2> /dev/null`" || true
 
 # Device containing our /boot partition.  Usually the same as GRUB_DEVICE.
 GRUB_DEVICE_BOOT="`${grub_probe} --target=device /boot`"
@@ -170,11 +171,19 @@
 
 if [ "x${GRUB_ACTUAL_DEFAULT}" = "xsaved" ] ; then GRUB_ACTUAL_DEFAULT="`"${grub_editenv}" - list | sed -n '/^saved_entry=/ s,^saved_entry=,,p'`" ; fi
 
+# Default to UUID if GRUB_DEVICE_IDENTIFICATION_LINUX is undefined or unrecognised
+case "x${GRUB_DEVICE_IDENTIFICATION_LINUX}" in
+    xuuid) ;;
+    xlabel) ;;
+    xpath)) ;;
+    *) LINUX_DEVICE_IDENTIFCATION = uuid ;;
+esac
 
 # These are defined in this script, export them here so that user can
 # override them.
 export GRUB_DEVICE \
   GRUB_DEVICE_UUID \
+  GRUB_DEVICE_LABEL_LINUX \
   GRUB_DEVICE_BOOT \
   GRUB_DEVICE_BOOT_UUID \
   GRUB_FS \
@@ -216,7 +225,9 @@
   GRUB_INIT_TUNE \
   GRUB_SAVEDEFAULT \
   GRUB_ENABLE_CRYPTODISK \
-  GRUB_BADRAM
+  GRUB_BADRAM \
+  GRUB_DEVICE_IDENTIFICATION_LINUX \
+  GRUB_SEARCH_METHOD
 
 if test "x${grub_cfg}" != "x"; then
   rm -f "${grub_cfg}.new"

=== modified file 'util/grub-mkconfig_lib.in'

util/grub-mkconfig_lib.in +13 -5
@@ -146,22 +146,30 @@
       done
   fi
 
-  # If there's a filesystem UUID that GRUB is capable of identifying, use it;
+  # If there's a filesystem UUID or label that GRUB is capable of identifying, use it according to GRUB_SEARCH_METHOD
   # otherwise set root as per value in device.map.
   fs_hint="`"${grub_probe}" --device "${device}" --target=compatibility_hint`"
   if [ "x$fs_hint" != x ]; then
     echo "set root='$fs_hint'"
   fi
-  if fs_uuid="`"${grub_probe}" --device "${device}" --target=fs_uuid 2> /dev/null`" ; then
+  if [ "x${GRUB_SEARCH_METHOD}" = "xlabel" ] && fs_label="`"${grub_probe}" --device "${device}" --target=fs_label 2> /dev/null`" ; then
     hints="`"${grub_probe}" --device "${device}" --target=hints_string 2> /dev/null`" || hints=
     echo "if [ x\$feature_platform_search_hint = xy ]; then"
-    echo "  search --no-floppy --fs-uuid --set=root ${hints} ${fs_uuid}"
+    echo "  search --no-floppy --label --set=root ${hints} ${fs_label}"
     echo "else"
-    echo "  search --no-floppy --fs-uuid --set=root ${fs_uuid}"
+    echo "  search --no-floppy --label --set=root ${fs_label}"
     echo "fi"
+  else
+    if fs_uuid="`"${grub_probe}" --device "${device}" --target=fs_uuid 2> /dev/null`" ; then
+      hints="`"${grub_probe}" --device "${device}" --target=hints_string 2> /dev/null`" || hints=
+      echo "if [ x\$feature_platform_search_hint = xy ]; then"
+      echo "  search --no-floppy --fs-uuid --set=root ${hints} ${fs_uuid}"
+      echo "else"
+      echo "  search --no-floppy --fs-uuid --set=root ${fs_uuid}"
+      echo "fi"
+    fi
   fi
 }
-
 grub_get_device_id ()
 {
   device="$1"

=== modified file 'util/grub.d/10_linux.in'

util/grub.d/10_linux.in +21 -7
@@ -43,13 +43,27 @@
   ;;
 esac
 
-if [ "x${GRUB_DEVICE_UUID}" = "x" ] || [ "x${GRUB_DISABLE_LINUX_UUID}" = "xtrue" ] \
-    || ! test -e "/dev/disk/by-uuid/${GRUB_DEVICE_UUID}" \
-    || uses_abstraction "${GRUB_DEVICE}" lvm; then
-  LINUX_ROOT_DEVICE=${GRUB_DEVICE}
-else
-  LINUX_ROOT_DEVICE=UUID=${GRUB_DEVICE_UUID}
-fi
+case x"$GRUB_DEVICE_IDENTIFICATION_LINUX" in
+    xpath)
+        LINUX_ROOT_DEVICE=${GRUB_DEVICE}
+        ;;
+    xlabel)
+        if [ "x${GRUB_DEVICE_LABEL_LINUX}" = "x" ] \
+            || ! test -e "/dev/disk/by-label/${GRUB_DEVICE_LABEL}" \
+            || uses_abstraction "${GRUB_DEVICE}" lvm; then
+            LINUX_ROOT_DEVICE=${GRUB_DEVICE}
+        else
+            LINUX_ROOT_DEVICE=LABEL=\"${GRUB_DEVICE_LABEL_LINUX}\"
+        fi;;
+    *)
+        if [ "x{GRUB_DEVICE_UUID}" = "x" ] \
+            || ! test -e "/dev/disk/by-uuid/${GRUB_DEVICE_UUID}" \
+            || uses_abstraction "${GRUB_DEVICE}" lvm; then
+            LINUX_ROOT_DEVICE=${GRUB_DEVICE}
+        else
+            LINUX_ROOT_DEVICE=UUID=${GRUB_DEVICE_UUID}
+        fi;;      
+esac
 
 GRUBFS="`${grub_probe} --device ${GRUB_DEVICE} --target=fs 2>/dev/null || true`"
 
#7 lore raw

Apologies, please ignore previous patch file which had a replacement missed out.

Regards,

Pete Appleton

=== modified file 'docs/grub.texi'

docs/grub.texi +13 -0
@@ -1285,6 +1285,19 @@
 the Linux kernel, using a @samp{root=UUID=...} kernel parameter.  This is
 usually more reliable, but in some cases it may not be appropriate.  To
 disable the use of UUIDs, set this option to @samp{true}.
+@samp{GRUB_DEVICE_IDENTIFICATION_LINUX} governs the scheme used instead of
+the UUID, either the file system label or the traditional device path
+
+@item GRUB_DEVICE_IDENTIFICATION_LINUX
+Works in conjunction with GRUB_DISABLE_LINUX_UUID to determine how the root filesystem
+will be identified for the Linux kernel.  The default value is @samp{uuid}, which will use UUIDs. 
+Other alternatives are @samp{label} to use the file system label, or @samp{path} to use
+the traditional device path (@samp{/dev/sda1})
+
+@item GRUB_SEARCH_METHOD
+Governs the method used to generate the search directive (as opposed to the Linux root filesysttem)
+using the same settings as @samp{GRUB_DEVICE_IDENTIFICATION_LINUX}.  If unset or unrecognised
+then GRUB will default to searching by UUID
 
 @item GRUB_DISABLE_RECOVERY
 If this option is set to @samp{true}, disable the generation of recovery

=== modified file 'util/grub-mkconfig.in'

util/grub-mkconfig.in +12 -1
@@ -131,6 +131,7 @@
 # Device containing our userland.  Typically used for root= parameter.
 GRUB_DEVICE="`${grub_probe} --target=device /`"
 GRUB_DEVICE_UUID="`${grub_probe} --device ${GRUB_DEVICE} --target=fs_uuid 2> /dev/null`" || true
+GRUB_DEVICE_LABEL_LINUX="`${grub_probe} --device ${GRUB_DEVICE} --target=fs_label 2> /dev/null`" || true
 
 # Device containing our /boot partition.  Usually the same as GRUB_DEVICE.
 GRUB_DEVICE_BOOT="`${grub_probe} --target=device /boot`"
@@ -170,11 +171,19 @@
 
 if [ "x${GRUB_ACTUAL_DEFAULT}" = "xsaved" ] ; then GRUB_ACTUAL_DEFAULT="`"${grub_editenv}" - list | sed -n '/^saved_entry=/ s,^saved_entry=,,p'`" ; fi
 
+# Default to UUID if GRUB_DEVICE_IDENTIFICATION_LINUX is undefined or unrecognised
+case "x${GRUB_DEVICE_IDENTIFICATION_LINUX}" in
+    xuuid) ;;
+    xlabel) ;;
+    xpath)) ;;
+    *) GRUB_DEVICE_IDENTIFICATION_LINUX = uuid ;;
+esac
 
 # These are defined in this script, export them here so that user can
 # override them.
 export GRUB_DEVICE \
   GRUB_DEVICE_UUID \
+  GRUB_DEVICE_LABEL_LINUX \
   GRUB_DEVICE_BOOT \
   GRUB_DEVICE_BOOT_UUID \
   GRUB_FS \
@@ -216,7 +225,9 @@
   GRUB_INIT_TUNE \
   GRUB_SAVEDEFAULT \
   GRUB_ENABLE_CRYPTODISK \
-  GRUB_BADRAM
+  GRUB_BADRAM \
+  GRUB_DEVICE_IDENTIFICATION_LINUX \
+  GRUB_SEARCH_METHOD
 
 if test "x${grub_cfg}" != "x"; then
   rm -f "${grub_cfg}.new"

=== modified file 'util/grub-mkconfig_lib.in'

util/grub-mkconfig_lib.in +13 -5
@@ -146,22 +146,30 @@
       done
   fi
 
-  # If there's a filesystem UUID that GRUB is capable of identifying, use it;
+  # If there's a filesystem UUID or label that GRUB is capable of identifying, use it according to GRUB_SEARCH_METHOD
   # otherwise set root as per value in device.map.
   fs_hint="`"${grub_probe}" --device "${device}" --target=compatibility_hint`"
   if [ "x$fs_hint" != x ]; then
     echo "set root='$fs_hint'"
   fi
-  if fs_uuid="`"${grub_probe}" --device "${device}" --target=fs_uuid 2> /dev/null`" ; then
+  if [ "x${GRUB_SEARCH_METHOD}" = "xlabel" ] && fs_label="`"${grub_probe}" --device "${device}" --target=fs_label 2> /dev/null`" ; then
     hints="`"${grub_probe}" --device "${device}" --target=hints_string 2> /dev/null`" || hints=
     echo "if [ x\$feature_platform_search_hint = xy ]; then"
-    echo "  search --no-floppy --fs-uuid --set=root ${hints} ${fs_uuid}"
+    echo "  search --no-floppy --label --set=root ${hints} ${fs_label}"
     echo "else"
-    echo "  search --no-floppy --fs-uuid --set=root ${fs_uuid}"
+    echo "  search --no-floppy --label --set=root ${fs_label}"
     echo "fi"
+  else
+    if fs_uuid="`"${grub_probe}" --device "${device}" --target=fs_uuid 2> /dev/null`" ; then
+      hints="`"${grub_probe}" --device "${device}" --target=hints_string 2> /dev/null`" || hints=
+      echo "if [ x\$feature_platform_search_hint = xy ]; then"
+      echo "  search --no-floppy --fs-uuid --set=root ${hints} ${fs_uuid}"
+      echo "else"
+      echo "  search --no-floppy --fs-uuid --set=root ${fs_uuid}"
+      echo "fi"
+    fi
   fi
 }
-
 grub_get_device_id ()
 {
   device="$1"

=== modified file 'util/grub.d/10_linux.in'

util/grub.d/10_linux.in +21 -7
@@ -43,13 +43,27 @@
   ;;
 esac
 
-if [ "x${GRUB_DEVICE_UUID}" = "x" ] || [ "x${GRUB_DISABLE_LINUX_UUID}" = "xtrue" ] \
-    || ! test -e "/dev/disk/by-uuid/${GRUB_DEVICE_UUID}" \
-    || uses_abstraction "${GRUB_DEVICE}" lvm; then
-  LINUX_ROOT_DEVICE=${GRUB_DEVICE}
-else
-  LINUX_ROOT_DEVICE=UUID=${GRUB_DEVICE_UUID}
-fi
+case x"$GRUB_DEVICE_IDENTIFICATION_LINUX" in
+    xpath)
+        LINUX_ROOT_DEVICE=${GRUB_DEVICE}
+        ;;
+    xlabel)
+        if [ "x${GRUB_DEVICE_LABEL_LINUX}" = "x" ] \
+            || ! test -e "/dev/disk/by-label/${GRUB_DEVICE_LABEL}" \
+            || uses_abstraction "${GRUB_DEVICE}" lvm; then
+            LINUX_ROOT_DEVICE=${GRUB_DEVICE}
+        else
+            LINUX_ROOT_DEVICE=LABEL=\"${GRUB_DEVICE_LABEL_LINUX}\"
+        fi;;
+    *)
+        if [ "x{GRUB_DEVICE_UUID}" = "x" ] \
+            || ! test -e "/dev/disk/by-uuid/${GRUB_DEVICE_UUID}" \
+            || uses_abstraction "${GRUB_DEVICE}" lvm; then
+            LINUX_ROOT_DEVICE=${GRUB_DEVICE}
+        else
+            LINUX_ROOT_DEVICE=UUID=${GRUB_DEVICE_UUID}
+        fi;;      
+esac
 
 GRUBFS="`${grub_probe} --device ${GRUB_DEVICE} --target=fs 2>/dev/null || true`"
 
#8 lore raw

Hello everybody,

any progress on this? I'm waiting for this feature already more than one and half year, but the patch wasn't included yet. Could you please incorporate it to the upstream branch ASAP?

Thanks

-- Jan Pacner

#9 lore raw

Anyone interested?

The patch is quite short and doesn't break anything. Is there anything I can do to fasten the process of incorporation?

Kind regards,

-- Jan Pacner