ac3a84
From e3dfedee10cb0c348d748bf438c76e5c3623ad69 Mon Sep 17 00:00:00 2001
ac3a84
From: Lennart Poettering <lennart@poettering.net>
ac3a84
Date: Mon, 21 Nov 2022 15:32:22 +0100
ac3a84
Subject: [PATCH] udev: make sure auto-root logic also works in UKIs booted
ac3a84
 from XBOOTLDR
ac3a84
MIME-Version: 1.0
ac3a84
Content-Type: text/plain; charset=UTF-8
ac3a84
Content-Transfer-Encoding: 8bit
ac3a84
ac3a84
If no root= switch is specified on the kernel command line we'll use the
ac3a84
root disk on which the partition the LoaderDevicePartUUID efi var is
ac3a84
located – as long as that partition is an ESP. Let's slightly liberalize
ac3a84
that and also allow it if that partition is an XBOOTLDR partition. This
ac3a84
ensures that UKIs spawned directly from XBOOTLDR work the same as those
ac3a84
from the ESP.
ac3a84
ac3a84
(Note that this makes no difference if sd-boot is in the mix, as in that
ac3a84
case LoaderDevicePartUUID is always set to the ESP, as that's where
ac3a84
sd-boot is located, and sd-boot will set the var first, sd-stub will
ac3a84
only set it later if it#s not set yet.)
ac3a84
ac3a84
(cherry picked from commit e4cb147a2e230a4a0b804c3e70f2692a5e2fd698)
ac3a84
ac3a84
Related: #2138081
ac3a84
---
ac3a84
 src/udev/udev-builtin-blkid.c | 27 +++++++++++++--------------
ac3a84
 1 file changed, 13 insertions(+), 14 deletions(-)
ac3a84
ac3a84
diff --git a/src/udev/udev-builtin-blkid.c b/src/udev/udev-builtin-blkid.c
ac3a84
index 92ea43eef0..9f5646ffdd 100644
ac3a84
--- a/src/udev/udev-builtin-blkid.c
ac3a84
+++ b/src/udev/udev-builtin-blkid.c
ac3a84
@@ -120,14 +120,14 @@ static int find_gpt_root(sd_device *dev, blkid_probe pr, bool test) {
ac3a84
 #if defined(SD_GPT_ROOT_NATIVE) && ENABLE_EFI
ac3a84
 
ac3a84
         _cleanup_free_ char *root_id = NULL, *root_label = NULL;
ac3a84
-        bool found_esp = false;
ac3a84
+        bool found_esp_or_xbootldr = false;
ac3a84
         int r;
ac3a84
 
ac3a84
         assert(pr);
ac3a84
 
ac3a84
-        /* Iterate through the partitions on this disk, and see if the
ac3a84
-         * EFI ESP we booted from is on it. If so, find the first root
ac3a84
-         * disk, and add a property indicating its partition UUID. */
ac3a84
+        /* Iterate through the partitions on this disk, and see if the UEFI ESP or XBOOTLDR partition we
ac3a84
+         * booted from is on it. If so, find the first root disk, and add a property indicating its partition
ac3a84
+         * UUID. */
ac3a84
 
ac3a84
         errno = 0;
ac3a84
         blkid_partlist pl = blkid_probe_get_partitions(pr);
ac3a84
@@ -157,21 +157,20 @@ static int find_gpt_root(sd_device *dev, blkid_probe pr, bool test) {
ac3a84
                 if (sd_id128_from_string(stype, &type) < 0)
ac3a84
                         continue;
ac3a84
 
ac3a84
-                if (sd_id128_equal(type, SD_GPT_ESP)) {
ac3a84
-                        sd_id128_t id, esp;
ac3a84
+                if (sd_id128_in_set(type, SD_GPT_ESP, SD_GPT_XBOOTLDR)) {
ac3a84
+                        sd_id128_t id, esp_or_xbootldr;
ac3a84
 
ac3a84
-                        /* We found an ESP, let's see if it matches
ac3a84
-                         * the ESP we booted from. */
ac3a84
+                        /* We found an ESP or XBOOTLDR, let's see if it matches the ESP/XBOOTLDR we booted from. */
ac3a84
 
ac3a84
                         if (sd_id128_from_string(sid, &id) < 0)
ac3a84
                                 continue;
ac3a84
 
ac3a84
-                        r = efi_loader_get_device_part_uuid(&esp;;
ac3a84
+                        r = efi_loader_get_device_part_uuid(&esp_or_xbootldr);
ac3a84
                         if (r < 0)
ac3a84
                                 return r;
ac3a84
 
ac3a84
-                        if (sd_id128_equal(id, esp))
ac3a84
-                                found_esp = true;
ac3a84
+                        if (sd_id128_equal(id, esp_or_xbootldr))
ac3a84
+                                found_esp_or_xbootldr = true;
ac3a84
 
ac3a84
                 } else if (sd_id128_equal(type, SD_GPT_ROOT_NATIVE)) {
ac3a84
                         unsigned long long flags;
ac3a84
@@ -195,9 +194,9 @@ static int find_gpt_root(sd_device *dev, blkid_probe pr, bool test) {
ac3a84
                 }
ac3a84
         }
ac3a84
 
ac3a84
-        /* We found the ESP on this disk, and also found a root
ac3a84
-         * partition, nice! Let's export its UUID */
ac3a84
-        if (found_esp && root_id)
ac3a84
+        /* We found the ESP/XBOOTLDR on this disk, and also found a root partition, nice! Let's export its
ac3a84
+         * UUID */
ac3a84
+        if (found_esp_or_xbootldr && root_id)
ac3a84
                 udev_builtin_add_property(dev, test, "ID_PART_GPT_AUTO_ROOT_UUID", root_id);
ac3a84
 #endif
ac3a84