diff --git a/docs/ENVIRONMENT.md b/docs/ENVIRONMENT.md index 654f7d25cf..3e61ea51e7 100644 --- a/docs/ENVIRONMENT.md +++ b/docs/ENVIRONMENT.md @@ -125,6 +125,12 @@ bootctl and other tools that access the EFI System Partition (ESP): is a FAT file system are turned off, as are checks that the path is located on a GPT partition with the correct type UUID. +* `$SYSTEMD_ESP_PATH=…` — override the path to the EFI System Partition. This + may be used to override ESP path auto detection, and redirect any accesses to + the ESP to the specified directory. Not that unlike with bootctl's --path= + switch only very superficial validation of the specified path is done when + this environment variable is used. + systemd itself: * `$SYSTEMD_ACTIVATION_UNIT` — set for all NSS and PAM module invocations that diff --git a/src/shared/bootspec.c b/src/shared/bootspec.c index df15b660ec..9ba6978962 100644 --- a/src/shared/bootspec.c +++ b/src/shared/bootspec.c @@ -16,6 +16,7 @@ #include "fd-util.h" #include "fileio.h" #include "parse-util.h" +#include "path-util.h" #include "stat-util.h" #include "string-util.h" #include "strv.h" @@ -590,6 +591,18 @@ int find_esp_and_warn( goto found; } + path = getenv("SYSTEMD_ESP_PATH"); + if (path) { + if (!path_is_valid(path) || !path_is_absolute(path)) { + log_error("$SYSTEMD_ESP_PATH does not refer to absolute path, refusing to use it: %s", path); + return -EINVAL; + } + + /* Note: when the user explicitly configured things with an env var we won't validate the mount + * point. After all we want this to be useful for testing. */ + goto found; + } + FOREACH_STRING(path, "/efi", "/boot", "/boot/efi") { r = verify_esp(path, true, unprivileged_mode, ret_part, ret_pstart, ret_psize, ret_uuid);