]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
boot: when we detect that sd-boot is called as NBP, print friendly message
authorLennart Poettering <lennart@poettering.net>
Wed, 12 Feb 2025 21:42:10 +0000 (22:42 +0100)
committerLennart Poettering <lennart@poettering.net>
Fri, 21 Feb 2025 09:04:15 +0000 (10:04 +0100)
Fixes: #11850
src/boot/boot.c

index 75f764bc4e1185eea177df628cc1862a7a67304d..6e55a659dd1ebfcb60ddb7340633955ec712e41b 100644 (file)
@@ -3118,21 +3118,34 @@ static EFI_STATUS run(EFI_HANDLE image) {
 
         init_usec = time_usec();
 
-        /* Ask Shim to leave its protocol around, so that the stub can use it to validate PEs.
-         * By default, Shim uninstalls its protocol when calling StartImage(). */
-        shim_retain_protocol();
-
         err = BS->HandleProtocol(image, MAKE_GUID_PTR(EFI_LOADED_IMAGE_PROTOCOL), (void **) &loaded_image);
         if (err != EFI_SUCCESS)
                 return log_error_status(err, "Error getting a LoadedImageProtocol handle: %m");
 
+        err = discover_root_dir(loaded_image, &root_dir);
+        if (err != EFI_SUCCESS) {
+                log_error_status(err, "Unable to open root directory: %m");
+
+                /* If opening the root directory fails this typically means someone is trying to boot our
+                 * systemd-boot EFI PE binary as network boot NBP. That cannot work however, since we
+                 * wouldn't find any menu entries. Provide a helpful message what to try instead. */
+
+                if (err == EFI_UNSUPPORTED)
+                        log_info("| Note that invoking systemd-boot directly as UEFI network boot NBP is not\n"
+                                 "| supported. Instead of booting the systemd-boot PE binary (i.e. an .efi file)\n"
+                                 "| via the network, use an EFI GPT disk image (i.e. a file with .img suffix)\n"
+                                 "| containing systemd-boot instead.");
+
+                return err;
+        }
+
+        /* Ask Shim to leave its protocol around, so that the stub can use it to validate PEs.
+         * By default, Shim uninstalls its protocol when calling StartImage(). */
+        shim_retain_protocol();
+
         export_common_variables(loaded_image);
         export_loader_variables(loaded_image, init_usec);
 
-        err = discover_root_dir(loaded_image, &root_dir);
-        if (err != EFI_SUCCESS)
-                return log_error_status(err, "Unable to open root directory: %m");
-
         (void) load_drivers(image, loaded_image, root_dir);
 
         _cleanup_free_ char16_t *loaded_image_path = NULL;