From: Lennart Poettering Date: Wed, 12 Feb 2025 21:42:10 +0000 (+0100) Subject: boot: when we detect that sd-boot is called as NBP, print friendly message X-Git-Tag: v258-rc1~1280^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fc8f0089bfd2850fe212756fcd63b107b9ef4266;p=thirdparty%2Fsystemd.git boot: when we detect that sd-boot is called as NBP, print friendly message Fixes: #11850 --- diff --git a/src/boot/boot.c b/src/boot/boot.c index 75f764bc4e1..6e55a659dd1 100644 --- a/src/boot/boot.c +++ b/src/boot/boot.c @@ -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;