All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Add support for specifying the boot device by label
@ 2023-09-10  9:30 darkpenguin
  2023-09-10 21:12 ` Oskari Pirhonen
                   ` (2 more replies)
  0 siblings, 3 replies; 21+ messages in thread
From: darkpenguin @ 2023-09-10  9:30 UTC (permalink / raw)
  To: grub-devel

Specifying the boot device by its label rather than its UUID can be
pretty useful in various situations (e.g. multiple test VMs).

This might have to be adapted a little to meet the coding standards I'm
not familiar with. Please feel free to improve it in any way you want.

This patch works for me on an older version of grub2 (=2.06-13 in Debian
Bookworm), but it's rather trivial, and only touches two parts that are
otherwise untouched for ages.

- Specify "GRUB_DISABLE_LINUX_UUID=LABEL" in /etc/default/grub
- It will attempt to use a label instead of UUID
- If a device with the necessary label is not found in
/dev/disk/by-label/ , it falls back to using UUID
- If you just assigned new labels, run 'partprobe' to populate
/dev/disk/by-label/ properly

The decision to reuse GRUB_DISABLE_LINUX_UUID was because:
1) This is more of an addition on top of UUID rather than "disabling"
it, it still uses UUID internally, and it falls back to UUID
2) I could not come up with a better way to do it
3) I could not figure out how to source other variables from
/etc/defaults/grub and why not all of them are there. :)


---
diff --git a/util/grub-mkconfig_lib.in b/util/grub-mkconfig_lib.in
index 0895328..bd43bc0 100644
--- a/util/grub-mkconfig_lib.in
+++ b/util/grub-mkconfig_lib.in
@@ -158,14 +158,22 @@ prepare_grub_to_access_device ()
   fi
   if [ "x${GRUB_DISABLE_UUID}" != "xtrue" ] &&
fs_uuid="`"${grub_probe}" --device $@ --target=fs_uuid 2> /dev/null`" ; then
     hints="`"${grub_probe}" --device $@ --target=hints_string 2>
/dev/null`" || hints=
+
+    if [ "x${GRUB_DISABLE_LINUX_UUID}" = "xLABEL" ] \
+        && [ -b "/dev/disk/by-label/$(blkid -l -t UUID=${fs_uuid} -s
LABEL -o value)" ]; then
+      device="--label $(blkid -l -t UUID=${fs_uuid} -s LABEL -o value)"
+    else
+      device="--fs-uuid ${fs_uuid}"
+    fi
+
     if [ "x$hints" != x ]; then
       echo "if [ x\$feature_platform_search_hint = xy ]; then"
-      echo "  search --no-floppy --fs-uuid --set=root ${hints} ${fs_uuid}"
+      echo "  search --no-floppy --set=root ${hints} ${device}"
       echo "else"
-      echo "  search --no-floppy --fs-uuid --set=root ${fs_uuid}"
+      echo "  search --no-floppy --set=root ${device}"
       echo "fi"
     else
-      echo "search --no-floppy --fs-uuid --set=root ${fs_uuid}"
+      echo "search --no-floppy --set=root ${device}"
     fi
   fi
   IFS="$old_ifs"
diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in
index cc393be..d29a004 100644
--- a/util/grub.d/10_linux.in
+++ b/util/grub.d/10_linux.in
@@ -61,6 +61,9 @@ if ( [ "x${GRUB_DEVICE_UUID}" = "x" ] && [
"x${GRUB_DEVICE_PARTUUID}" = "x" ] )
 elif [ "x${GRUB_DEVICE_UUID}" = "x" ] \
     || [ "x${GRUB_DISABLE_LINUX_UUID}" = "xtrue" ]; then
   LINUX_ROOT_DEVICE=PARTUUID=${GRUB_DEVICE_PARTUUID}
+elif [ "x${GRUB_DISABLE_LINUX_UUID}" = "xLABEL" ] \
+    && [ -b "/dev/disk/by-label/$(blkid -l -t UUID=${GRUB_DEVICE_UUID}
-s LABEL -o value)" ]; then
+  LINUX_ROOT_DEVICE=LABEL="$(blkid -l -t UUID=${GRUB_DEVICE_UUID} -s
LABEL -o value)"
 else
   LINUX_ROOT_DEVICE=UUID=${GRUB_DEVICE_UUID}
 fi

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

^ permalink raw reply related	[flat|nested] 21+ messages in thread

end of thread, other threads:[~2023-09-27 20:34 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-09-10  9:30 [PATCH] Add support for specifying the boot device by label darkpenguin
2023-09-10 21:12 ` Oskari Pirhonen
2023-09-11  6:48   ` darkpenguin
2023-09-12  2:54     ` Oskari Pirhonen
2023-09-12  7:42       ` darkpenguin
2023-09-12 13:02         ` Nicholas Vinson
2023-09-12 15:10           ` darkpenguin
2023-09-10 21:20 ` Vladimir 'phcoder' Serbinenko
2023-09-11  6:28   ` darkpenguin
2023-09-26  7:28   ` darkpenguin
2023-09-27  6:51     ` darkpenguin
2023-09-27 10:16       ` Daniel Kiper
2023-09-27 11:05         ` darkpenguin
2023-09-27 15:22       ` Vladimir 'phcoder' Serbinenko
2023-09-27 15:42         ` darkpenguin
2023-09-27 20:33           ` Vladimir 'phcoder' Serbinenko
2023-09-11 10:44 ` Olaf Hering
2023-09-11 11:15   ` darkpenguin
2023-09-12 12:10     ` Nicholas Vinson
2023-09-12 14:17       ` darkpenguin
2023-09-12 19:06     ` Vladimir 'phcoder' Serbinenko

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.