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