]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
gpt-auto: Check for /boot before putting ESP there
authorAdrian Vovk <adrianvovk@gmail.com>
Thu, 2 Mar 2023 18:00:28 +0000 (13:00 -0500)
committerLuca Boccassi <luca.boccassi@gmail.com>
Mon, 6 Mar 2023 20:37:57 +0000 (20:37 +0000)
We prefer /efi as a mount point for the ESP, and use /boot as a fallback
if /efi doesn't exist. However, when root=tmpfs, neither /efi nor /boot
exist. gpt-auto should mount to /efi in this case, but it mounted to
/boot instead. This is because gpt-auto didn't check for the existence
of /boot. Here, we correct this

src/gpt-auto-generator/gpt-auto-generator.c

index 34f67b7fcbbb293932262c8d5e58285f99527c0d..a197ea9da60cc8250000351f10241c1c835893aa 100644 (file)
@@ -518,10 +518,15 @@ static int add_partition_esp(DissectedPartition *p, bool has_xbootldr) {
                 if (errno != ENOENT)
                         return log_error_errno(errno, "Failed to determine whether /efi exists: %m");
 
-                /* Use /boot as fallback, but only if there's no XBOOTLDR partition */
+                /* Use /boot as fallback, but only if there's no XBOOTLDR partition and /boot exists */
                 if (!has_xbootldr) {
-                        esp_path = "/boot";
-                        id = "boot";
+                        if (access("/boot", F_OK) < 0) {
+                                if (errno != ENOENT)
+                                        return log_error_errno(errno, "Failed to determine whether /boot exists: %m");
+                        } else {
+                                esp_path = "/boot";
+                                id = "boot";
+                        }
                 }
         }
         if (!esp_path)