All of lore.kernel.org
 help / color / mirror / Atom feed
From: stormbyte@gmail.com
To: grub-devel@gnu.org
Cc: "David C. Manuelda" <StormByte@gmail.com>
Subject: [PATCH] Introduce grub-mkconfig filesystem label support:
Date: Tue,  8 Oct 2024 14:58:26 +0200	[thread overview]
Message-ID: <20241008130045.22834-2-StormByte@gmail.com> (raw)
In-Reply-To: <20241008130045.22834-1-StormByte@gmail.com>

From: "David C. Manuelda" <StormByte@gmail.com>

This feature will allow grub-mkconfig to be able to identify root
filesystem via label kernel parameter (root=LABEL=xxxx). To enable
this feature, UUIDs and PARTUUIDs needs to be disabled (with
GRUB_DISABLE_LINUX_UUID and GRUB_DISABLE_LINUX_PARTUUID set to true)
and the newly introduced variable GRUB_DISABLE_LINUX_LABEL set to false.

GRUB_DEVICE_LABEL is also added to mkconfig can look for them.

To maintain compatibility with older kernels and existing configs
the default value for GRUB_DISABLE_LINUX_LABEL is true so unless
this value is changed the current functionality is not affected.

Signed-off-by: David C. Manuelda <StormByte@gmail.com>
---
 docs/grub.texi          |  7 +++++++
 util/grub-mkconfig.in   |  3 +++
 util/grub.d/10_linux.in | 29 +++++++++++++++++++++--------
 3 files changed, 31 insertions(+), 8 deletions(-)

diff --git a/docs/grub.texi b/docs/grub.texi
index 2ea6c56d1..4ecb708ae 100644
--- a/docs/grub.texi
+++ b/docs/grub.texi
@@ -1499,6 +1499,13 @@ Linux device names. When @samp{GRUB_DISABLE_LINUX_PARTUUID} is set to
 the MSDOS partition scheme) or newer.  This option defaults to @samp{true}.  To
 enable the use of partition UUIDs, set this option to @samp{false}.
 
+@item GRUB_DISABLE_LINUX_LABEL
+@command{grub-mkconfig} can pick labels to identify root filesystem to the Linux
+kernel via a @samp{root=LABEL=...} kernel parameter. To enable it disable both
+@samp{GRUB_DISABLE_LINUX_UUID} and @samp{GRUB_DISABLE_LINUX_PARTUUID} with
+a @samp{true} value and set this option to @samp{false}. To maintain compatibility
+with older kernels this option defaults to @samp{true}.
+
 @item GRUB_DISABLE_RECOVERY
 If this option is set to @samp{true}, disable the generation of recovery
 mode menu entries.
diff --git a/util/grub-mkconfig.in b/util/grub-mkconfig.in
index 32c480dae..28ad290e3 100644
--- a/util/grub-mkconfig.in
+++ b/util/grub-mkconfig.in
@@ -135,6 +135,7 @@ fi
 GRUB_DEVICE="`${grub_probe} --target=device /`"
 GRUB_DEVICE_UUID="`${grub_probe} --device ${GRUB_DEVICE} --target=fs_uuid 2> /dev/null`" || true
 GRUB_DEVICE_PARTUUID="`${grub_probe} --device ${GRUB_DEVICE} --target=partuuid 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`"
@@ -202,6 +203,7 @@ if [ "x${GRUB_ACTUAL_DEFAULT}" = "xsaved" ] ; then GRUB_ACTUAL_DEFAULT="`"${grub
 export GRUB_DEVICE \
   GRUB_DEVICE_UUID \
   GRUB_DEVICE_PARTUUID \
+  GRUB_DEVICE_LABEL \
   GRUB_DEVICE_BOOT \
   GRUB_DEVICE_BOOT_UUID \
   GRUB_DISABLE_OS_PROBER \
@@ -244,6 +246,7 @@ export GRUB_DEFAULT \
   GRUB_DISABLE_UUID \
   GRUB_DISABLE_LINUX_UUID \
   GRUB_DISABLE_LINUX_PARTUUID \
+  GRUB_DISABLE_LINUX_LABEL \
   GRUB_DISABLE_RECOVERY \
   GRUB_VIDEO_BACKEND \
   GRUB_GFXMODE \
diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in
index cc393be7e..bc14056f2 100644
--- a/util/grub.d/10_linux.in
+++ b/util/grub.d/10_linux.in
@@ -45,24 +45,37 @@ esac
 
 : ${GRUB_CMDLINE_LINUX_RECOVERY:=single}
 
-# Default to disabling partition uuid support to maintian compatibility with
+# Default to disabling partition uuid support to maintain compatibility with
 # older kernels.
 : ${GRUB_DISABLE_LINUX_PARTUUID=true}
 
+# Default to disabling partition label support to maintain compatibility with
+# older kernels.
+: ${GRUB_DISABLE_LINUX_LABEL=true}
+
 # btrfs may reside on multiple devices. We cannot pass them as value of root= parameter
 # and mounting btrfs requires user space scanning, so force UUID in this case.
-if ( [ "x${GRUB_DEVICE_UUID}" = "x" ] && [ "x${GRUB_DEVICE_PARTUUID}" = "x" ] ) \
+if ( [ "x${GRUB_DEVICE_UUID}" = "x" ] && [ "x${GRUB_DEVICE_PARTUUID}" = "x" ] && [ "x${GRUB_DEVICE_LABEL}" = "x" ] ) \
     || ( [ "x${GRUB_DISABLE_LINUX_UUID}" = "xtrue" ] \
-	&& [ "x${GRUB_DISABLE_LINUX_PARTUUID}" = "xtrue" ] ) \
+	&& [ "x${GRUB_DISABLE_LINUX_PARTUUID}" = "xtrue" ] \
+    && [ "x${GRUB_DISABLE_LINUX_LABEL}" = "xtrue" ] ) \
     || ( ! test -e "/dev/disk/by-uuid/${GRUB_DEVICE_UUID}" \
-	&& ! test -e "/dev/disk/by-partuuid/${GRUB_DEVICE_PARTUUID}" ) \
+	&& ! test -e "/dev/disk/by-partuuid/${GRUB_DEVICE_PARTUUID}" \
+	&& ! test -e "/dev/disk/by-label/${GRUB_DEVICE_LABEL}" ) \
     || ( test -e "${GRUB_DEVICE}" && uses_abstraction "${GRUB_DEVICE}" lvm ); then
   LINUX_ROOT_DEVICE=${GRUB_DEVICE}
-elif [ "x${GRUB_DEVICE_UUID}" = "x" ] \
-    || [ "x${GRUB_DISABLE_LINUX_UUID}" = "xtrue" ]; then
-  LINUX_ROOT_DEVICE=PARTUUID=${GRUB_DEVICE_PARTUUID}
 else
-  LINUX_ROOT_DEVICE=UUID=${GRUB_DEVICE_UUID}
+  if ( [ "x${GRUB_DEVICE_UUID}" = "x" ] \
+      || [ "x${GRUB_DISABLE_LINUX_UUID}" = "xtrue" ] ); then
+    if ( [ "x${GRUB_DEVICE_PARTUUID}" = "x" ] \
+      || [ "x${GRUB_DISABLE_LINUX_PARTUUID}" = "xtrue" ] ); then
+      LINUX_ROOT_DEVICE=LABEL=${GRUB_DEVICE_LABEL}
+    else
+      LINUX_ROOT_DEVICE=PARTUUID=${GRUB_DEVICE_PARTUUID}
+    fi
+  else
+      LINUX_ROOT_DEVICE=UUID=${GRUB_DEVICE_UUID}
+  fi
 fi
 
 case x"$GRUB_FS" in
-- 
2.46.2


_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel

  reply	other threads:[~2024-10-08 13:03 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-08 12:58 [PATCH] Introduce grub-mkconfig filesystem label support stormbyte
2024-10-08 12:58 ` stormbyte [this message]
  -- strict thread matches above, loose matches on Subject: below --
2024-10-08 12:42 [PATCH UPDATED] " David C. Manuelda
2024-10-08 12:42 ` [PATCH] Introduce grub-mkconfig filesystem label support: David C. Manuelda
2024-10-08 12:19 stormbyte

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20241008130045.22834-2-StormByte@gmail.com \
    --to=stormbyte@gmail.com \
    --cc=grub-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.