1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
3 #include <linux/magic.h>
9 #include "alloc-util.h"
10 #include "blkid-util.h"
11 #include "chase-symlinks.h"
12 #include "device-util.h"
13 #include "devnum-util.h"
15 #include "errno-util.h"
18 #include "parse-util.h"
19 #include "path-util.h"
20 #include "stat-util.h"
21 #include "string-util.h"
24 typedef enum VerifyESPFlags
{
25 VERIFY_ESP_SEARCHING
= 1 << 0, /* Downgrade various "not found" logs to debug level */
26 VERIFY_ESP_UNPRIVILEGED_MODE
= 1 << 1, /* Call into udev rather than blkid */
27 VERIFY_ESP_RELAX_CHECKS
= 1 << 2, /* Do not validate ESP partition */
30 static int verify_esp_blkid(
36 sd_id128_t
*ret_uuid
) {
38 sd_id128_t uuid
= SD_ID128_NULL
;
39 uint64_t pstart
= 0, psize
= 0;
43 _cleanup_(blkid_free_probep
) blkid_probe b
= NULL
;
44 _cleanup_free_
char *node
= NULL
;
48 r
= device_path_make_major_minor(S_IFBLK
, devid
, &node
);
50 return log_error_errno(r
, "Failed to format major/minor device path: %m");
53 b
= blkid_new_probe_from_filename(node
);
55 return log_error_errno(errno
?: SYNTHETIC_ERRNO(ENOMEM
), "Failed to open file system \"%s\": %m", node
);
57 blkid_probe_enable_superblocks(b
, 1);
58 blkid_probe_set_superblocks_flags(b
, BLKID_SUBLKS_TYPE
);
59 blkid_probe_enable_partitions(b
, 1);
60 blkid_probe_set_partitions_flags(b
, BLKID_PARTS_ENTRY_DETAILS
);
63 r
= blkid_do_safeprobe(b
);
65 return log_error_errno(SYNTHETIC_ERRNO(ENODEV
), "File system \"%s\" is ambiguous.", node
);
67 return log_error_errno(SYNTHETIC_ERRNO(ENODEV
), "File system \"%s\" does not contain a label.", node
);
69 return log_error_errno(errno
?: SYNTHETIC_ERRNO(EIO
), "Failed to probe file system \"%s\": %m", node
);
71 r
= blkid_probe_lookup_value(b
, "TYPE", &v
, NULL
);
73 return log_full_errno(searching
? LOG_DEBUG
: LOG_ERR
,
74 SYNTHETIC_ERRNO(searching
? EADDRNOTAVAIL
: ENODEV
),
75 "No filesystem found on \"%s\": %m", node
);
76 if (!streq(v
, "vfat"))
77 return log_full_errno(searching
? LOG_DEBUG
: LOG_ERR
,
78 SYNTHETIC_ERRNO(searching
? EADDRNOTAVAIL
: ENODEV
),
79 "File system \"%s\" is not FAT.", node
);
81 r
= blkid_probe_lookup_value(b
, "PART_ENTRY_SCHEME", &v
, NULL
);
83 return log_full_errno(searching
? LOG_DEBUG
: LOG_ERR
,
84 SYNTHETIC_ERRNO(searching
? EADDRNOTAVAIL
: ENODEV
),
85 "File system \"%s\" is not located on a partitioned block device.", node
);
87 return log_full_errno(searching
? LOG_DEBUG
: LOG_ERR
,
88 SYNTHETIC_ERRNO(searching
? EADDRNOTAVAIL
: ENODEV
),
89 "File system \"%s\" is not on a GPT partition table.", node
);
92 r
= blkid_probe_lookup_value(b
, "PART_ENTRY_TYPE", &v
, NULL
);
94 return log_error_errno(errno
?: EIO
, "Failed to probe partition type UUID of \"%s\": %m", node
);
95 if (sd_id128_string_equal(v
, GPT_ESP
) <= 0)
96 return log_full_errno(searching
? LOG_DEBUG
: LOG_ERR
,
97 SYNTHETIC_ERRNO(searching
? EADDRNOTAVAIL
: ENODEV
),
98 "File system \"%s\" has wrong type for an EFI System Partition (ESP).", node
);
101 r
= blkid_probe_lookup_value(b
, "PART_ENTRY_UUID", &v
, NULL
);
103 return log_error_errno(errno
?: SYNTHETIC_ERRNO(EIO
), "Failed to probe partition entry UUID of \"%s\": %m", node
);
104 r
= sd_id128_from_string(v
, &uuid
);
106 return log_error_errno(r
, "Partition \"%s\" has invalid UUID \"%s\".", node
, v
);
109 r
= blkid_probe_lookup_value(b
, "PART_ENTRY_NUMBER", &v
, NULL
);
111 return log_error_errno(errno
?: SYNTHETIC_ERRNO(EIO
), "Failed to probe partition number of \"%s\": %m", node
);
112 r
= safe_atou32(v
, &part
);
114 return log_error_errno(r
, "Failed to parse PART_ENTRY_NUMBER field.");
117 r
= blkid_probe_lookup_value(b
, "PART_ENTRY_OFFSET", &v
, NULL
);
119 return log_error_errno(errno
?: SYNTHETIC_ERRNO(EIO
), "Failed to probe partition offset of \"%s\": %m", node
);
120 r
= safe_atou64(v
, &pstart
);
122 return log_error_errno(r
, "Failed to parse PART_ENTRY_OFFSET field.");
125 r
= blkid_probe_lookup_value(b
, "PART_ENTRY_SIZE", &v
, NULL
);
127 return log_error_errno(errno
?: SYNTHETIC_ERRNO(EIO
), "Failed to probe partition size of \"%s\": %m", node
);
128 r
= safe_atou64(v
, &psize
);
130 return log_error_errno(r
, "Failed to parse PART_ENTRY_SIZE field.");
136 *ret_pstart
= pstart
;
145 static int verify_esp_udev(
149 uint64_t *ret_pstart
,
151 sd_id128_t
*ret_uuid
) {
153 _cleanup_(sd_device_unrefp
) sd_device
*d
= NULL
;
154 _cleanup_free_
char *node
= NULL
;
155 sd_id128_t uuid
= SD_ID128_NULL
;
156 uint64_t pstart
= 0, psize
= 0;
161 r
= device_path_make_major_minor(S_IFBLK
, devid
, &node
);
163 return log_error_errno(r
, "Failed to format major/minor device path: %m");
165 r
= sd_device_new_from_devnum(&d
, 'b', devid
);
167 return log_error_errno(r
, "Failed to get device from device number: %m");
169 r
= sd_device_get_property_value(d
, "ID_FS_TYPE", &v
);
171 return log_error_errno(r
, "Failed to get device property: %m");
172 if (!streq(v
, "vfat"))
173 return log_full_errno(searching
? LOG_DEBUG
: LOG_ERR
,
174 SYNTHETIC_ERRNO(searching
? EADDRNOTAVAIL
: ENODEV
),
175 "File system \"%s\" is not FAT.", node
);
177 r
= sd_device_get_property_value(d
, "ID_PART_ENTRY_SCHEME", &v
);
179 return log_error_errno(r
, "Failed to get device property: %m");
180 if (!streq(v
, "gpt"))
181 return log_full_errno(searching
? LOG_DEBUG
: LOG_ERR
,
182 SYNTHETIC_ERRNO(searching
? EADDRNOTAVAIL
: ENODEV
),
183 "File system \"%s\" is not on a GPT partition table.", node
);
185 r
= sd_device_get_property_value(d
, "ID_PART_ENTRY_TYPE", &v
);
187 return log_error_errno(r
, "Failed to get device property: %m");
188 if (sd_id128_string_equal(v
, GPT_ESP
) <= 0)
189 return log_full_errno(searching
? LOG_DEBUG
: LOG_ERR
,
190 SYNTHETIC_ERRNO(searching
? EADDRNOTAVAIL
: ENODEV
),
191 "File system \"%s\" has wrong type for an EFI System Partition (ESP).", node
);
193 r
= sd_device_get_property_value(d
, "ID_PART_ENTRY_UUID", &v
);
195 return log_error_errno(r
, "Failed to get device property: %m");
196 r
= sd_id128_from_string(v
, &uuid
);
198 return log_error_errno(r
, "Partition \"%s\" has invalid UUID \"%s\".", node
, v
);
200 r
= sd_device_get_property_value(d
, "ID_PART_ENTRY_NUMBER", &v
);
202 return log_error_errno(r
, "Failed to get device property: %m");
203 r
= safe_atou32(v
, &part
);
205 return log_error_errno(r
, "Failed to parse PART_ENTRY_NUMBER field.");
207 r
= sd_device_get_property_value(d
, "ID_PART_ENTRY_OFFSET", &v
);
209 return log_error_errno(r
, "Failed to get device property: %m");
210 r
= safe_atou64(v
, &pstart
);
212 return log_error_errno(r
, "Failed to parse PART_ENTRY_OFFSET field.");
214 r
= sd_device_get_property_value(d
, "ID_PART_ENTRY_SIZE", &v
);
216 return log_error_errno(r
, "Failed to get device property: %m");
217 r
= safe_atou64(v
, &psize
);
219 return log_error_errno(r
, "Failed to parse PART_ENTRY_SIZE field.");
224 *ret_pstart
= pstart
;
233 static int verify_fsroot_dir(
236 bool unprivileged_mode
,
240 const char *t2
, *trigger
;
246 /* So, the ESP and XBOOTLDR partition are commonly located on an autofs mount. stat() on the
247 * directory won't trigger it, if it is not mounted yet. Let's hence explicitly trigger it here,
248 * before stat()ing */
249 trigger
= strjoina(path
, "/trigger"); /* Filename doesn't matter... */
250 (void) access(trigger
, F_OK
);
252 if (stat(path
, &st
) < 0)
253 return log_full_errno((searching
&& errno
== ENOENT
) ||
254 (unprivileged_mode
&& errno
== EACCES
) ? LOG_DEBUG
: LOG_ERR
, errno
,
255 "Failed to determine block device node of \"%s\": %m", path
);
257 if (major(st
.st_dev
) == 0)
258 return log_full_errno(searching
? LOG_DEBUG
: LOG_ERR
,
259 SYNTHETIC_ERRNO(searching
? EADDRNOTAVAIL
: ENODEV
),
260 "Block device node of \"%s\" is invalid.", path
);
262 if (path_equal(path
, "/")) {
263 /* Let's assume that the root directory of the OS is always the root of its file system
264 * (which technically doesn't have to be the case, but it's close enough, and it's not easy
265 * to be fully correct for it, since we can't look further up than the root dir easily.) */
267 *ret_dev
= st
.st_dev
;
272 t2
= strjoina(path
, "/..");
273 if (stat(t2
, &st2
) < 0) {
277 _cleanup_free_
char *parent
= NULL
;
279 /* If going via ".." didn't work due to EACCESS, then let's determine the parent path
280 * directly instead. It's not as good, due to symlinks and such, but we can't do
281 * anything better here. */
283 parent
= dirname_malloc(path
);
287 r
= RET_NERRNO(stat(parent
, &st2
));
291 return log_full_errno(unprivileged_mode
&& r
== -EACCES
? LOG_DEBUG
: LOG_ERR
, r
,
292 "Failed to determine block device node of parent of \"%s\": %m", path
);
295 if (st
.st_dev
== st2
.st_dev
)
296 return log_full_errno(searching
? LOG_DEBUG
: LOG_ERR
,
297 SYNTHETIC_ERRNO(searching
? EADDRNOTAVAIL
: ENODEV
),
298 "Directory \"%s\" is not the root of the file system.", path
);
301 *ret_dev
= st
.st_dev
;
306 static int verify_esp(
309 uint64_t *ret_pstart
,
311 sd_id128_t
*ret_uuid
,
313 VerifyESPFlags flags
) {
315 bool relax_checks
, searching
= FLAGS_SET(flags
, VERIFY_ESP_SEARCHING
),
316 unprivileged_mode
= FLAGS_SET(flags
, VERIFY_ESP_UNPRIVILEGED_MODE
);
322 /* This logs about all errors, except:
324 * -ENOENT → if 'searching' is set, and the dir doesn't exist
325 * -EADDRNOTAVAIL → if 'searching' is set, and the dir doesn't look like an ESP
326 * -EACESS → if 'unprivileged_mode' is set, and we have trouble accessing the thing
329 relax_checks
= getenv_bool("SYSTEMD_RELAX_ESP_CHECKS") > 0 || FLAGS_SET(flags
, VERIFY_ESP_RELAX_CHECKS
);
331 /* Non-root user can only check the status, so if an error occurred in the following, it does not cause any
332 * issues. Let's also, silence the error messages. */
337 if (statfs(p
, &sfs
) < 0)
338 /* If we are searching for the mount point, don't generate a log message if we can't find the path */
339 return log_full_errno((searching
&& errno
== ENOENT
) ||
340 (unprivileged_mode
&& errno
== EACCES
) ? LOG_DEBUG
: LOG_ERR
, errno
,
341 "Failed to check file system type of \"%s\": %m", p
);
343 if (!F_TYPE_EQUAL(sfs
.f_type
, MSDOS_SUPER_MAGIC
))
344 return log_full_errno(searching
? LOG_DEBUG
: LOG_ERR
,
345 SYNTHETIC_ERRNO(searching
? EADDRNOTAVAIL
: ENODEV
),
346 "File system \"%s\" is not a FAT EFI System Partition (ESP) file system.", p
);
349 r
= verify_fsroot_dir(p
, searching
, unprivileged_mode
, &devid
);
353 /* In a container we don't have access to block devices, skip this part of the verification, we trust
354 * the container manager set everything up correctly on its own. */
355 if (detect_container() > 0 || relax_checks
)
358 /* If we are unprivileged we ask udev for the metadata about the partition. If we are privileged we
359 * use blkid instead. Why? Because this code is called from 'bootctl' which is pretty much an
360 * emergency recovery tool that should also work when udev isn't up (i.e. from the emergency shell),
361 * however blkid can't work if we have no privileges to access block devices directly, which is why
362 * we use udev in that case. */
363 if (unprivileged_mode
)
364 r
= verify_esp_udev(devid
, searching
, ret_part
, ret_pstart
, ret_psize
, ret_uuid
);
366 r
= verify_esp_blkid(devid
, searching
, ret_part
, ret_pstart
, ret_psize
, ret_uuid
);
383 *ret_uuid
= SD_ID128_NULL
;
390 int find_esp_and_warn(
393 bool unprivileged_mode
,
396 uint64_t *ret_pstart
,
398 sd_id128_t
*ret_uuid
,
401 VerifyESPFlags flags
= (unprivileged_mode
? VERIFY_ESP_UNPRIVILEGED_MODE
: 0) |
402 (root
? VERIFY_ESP_RELAX_CHECKS
: 0);
403 _cleanup_free_
char *p
= NULL
;
406 /* This logs about all errors except:
408 * -ENOKEY → when we can't find the partition
409 * -EACCESS → when unprivileged_mode is true, and we can't access something
413 r
= chase_symlinks(path
, root
, CHASE_PREFIX_ROOT
, &p
, NULL
);
415 return log_error_errno(r
,
416 "Failed to resolve path %s%s%s: %m",
418 root
? " under directory " : "",
421 r
= verify_esp(p
, ret_part
, ret_pstart
, ret_psize
, ret_uuid
, ret_devid
, flags
);
428 path
= getenv("SYSTEMD_ESP_PATH");
432 r
= chase_symlinks(path
, root
, CHASE_PREFIX_ROOT
, &p
, NULL
);
434 return log_error_errno(r
,
435 "Failed to resolve path %s%s%s: %m",
437 root
? " under directory " : "",
440 if (!path_is_valid(p
) || !path_is_absolute(p
))
441 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
),
442 "$SYSTEMD_ESP_PATH does not refer to absolute path, refusing to use it: %s",
445 /* Note: when the user explicitly configured things with an env var we won't validate the
446 * path beyond checking it refers to a directory. After all we want this to be useful for
449 if (stat(p
, &st
) < 0)
450 return log_error_errno(errno
, "Failed to stat '%s': %m", p
);
451 if (!S_ISDIR(st
.st_mode
))
452 return log_error_errno(SYNTHETIC_ERRNO(ENOTDIR
), "ESP path '%s' is not a directory.", p
);
461 *ret_uuid
= SD_ID128_NULL
;
463 *ret_devid
= st
.st_dev
;
468 FOREACH_STRING(dir
, "/efi", "/boot", "/boot/efi") {
469 r
= chase_symlinks(dir
, root
, CHASE_PREFIX_ROOT
, &p
, NULL
);
473 return log_error_errno(r
,
474 "Failed to resolve path %s%s%s: %m",
476 root
? " under directory " : "",
479 r
= verify_esp(p
, ret_part
, ret_pstart
, ret_psize
, ret_uuid
, ret_devid
,
480 flags
| VERIFY_ESP_SEARCHING
);
483 if (!IN_SET(r
, -ENOENT
, -EADDRNOTAVAIL
)) /* This one is not it */
489 /* No logging here */
494 *ret_path
= TAKE_PTR(p
);
499 static int verify_xbootldr_blkid(
502 sd_id128_t
*ret_uuid
) {
504 sd_id128_t uuid
= SD_ID128_NULL
;
507 _cleanup_(blkid_free_probep
) blkid_probe b
= NULL
;
508 _cleanup_free_
char *node
= NULL
;
509 const char *type
, *v
;
512 r
= device_path_make_major_minor(S_IFBLK
, devid
, &node
);
514 return log_error_errno(r
, "Failed to format block device path for %u:%u: %m",
515 major(devid
), minor(devid
));
518 b
= blkid_new_probe_from_filename(node
);
520 return log_error_errno(errno
?: SYNTHETIC_ERRNO(ENOMEM
), "%s: Failed to create blkid probe: %m", node
);
522 blkid_probe_enable_partitions(b
, 1);
523 blkid_probe_set_partitions_flags(b
, BLKID_PARTS_ENTRY_DETAILS
);
526 r
= blkid_do_safeprobe(b
);
528 return log_error_errno(SYNTHETIC_ERRNO(ENODEV
), "%s: File system is ambiguous.", node
);
530 return log_error_errno(SYNTHETIC_ERRNO(ENODEV
), "%s: File system does not contain a label.", node
);
532 return log_error_errno(errno
?: SYNTHETIC_ERRNO(EIO
), "%s: Failed to probe file system: %m", node
);
535 r
= blkid_probe_lookup_value(b
, "PART_ENTRY_SCHEME", &type
, NULL
);
537 return log_error_errno(errno
?: SYNTHETIC_ERRNO(EIO
), "%s: Failed to probe PART_ENTRY_SCHEME: %m", node
);
538 if (streq(type
, "gpt")) {
541 r
= blkid_probe_lookup_value(b
, "PART_ENTRY_TYPE", &v
, NULL
);
543 return log_error_errno(errno
?: SYNTHETIC_ERRNO(EIO
), "%s: Failed to probe PART_ENTRY_TYPE: %m", node
);
544 if (sd_id128_string_equal(v
, GPT_XBOOTLDR
) <= 0)
545 return log_full_errno(searching
? LOG_DEBUG
: LOG_ERR
,
546 searching
? SYNTHETIC_ERRNO(EADDRNOTAVAIL
) : SYNTHETIC_ERRNO(ENODEV
),
547 "%s: Partitition has wrong PART_ENTRY_TYPE=%s for XBOOTLDR partition.", node
, v
);
550 r
= blkid_probe_lookup_value(b
, "PART_ENTRY_UUID", &v
, NULL
);
552 return log_error_errno(errno
?: SYNTHETIC_ERRNO(EIO
), "%s: Failed to probe PART_ENTRY_UUID: %m", node
);
553 r
= sd_id128_from_string(v
, &uuid
);
555 return log_error_errno(r
, "%s: Partition has invalid UUID PART_ENTRY_TYPE=%s: %m", node
, v
);
557 } else if (streq(type
, "dos")) {
560 r
= blkid_probe_lookup_value(b
, "PART_ENTRY_TYPE", &v
, NULL
);
562 return log_error_errno(errno
?: SYNTHETIC_ERRNO(EIO
), "%s: Failed to probe PART_ENTRY_TYPE: %m", node
);
563 if (!streq(v
, "0xea"))
564 return log_full_errno(searching
? LOG_DEBUG
: LOG_ERR
,
565 searching
? SYNTHETIC_ERRNO(EADDRNOTAVAIL
) : SYNTHETIC_ERRNO(ENODEV
),
566 "%s: Wrong PART_ENTRY_TYPE=%s for XBOOTLDR partition.", node
, v
);
569 return log_full_errno(searching
? LOG_DEBUG
: LOG_ERR
,
570 searching
? SYNTHETIC_ERRNO(EADDRNOTAVAIL
) : SYNTHETIC_ERRNO(ENODEV
),
571 "%s: Not on a GPT or DOS partition table (PART_ENTRY_SCHEME=%s).", node
, type
);
580 static int verify_xbootldr_udev(
583 sd_id128_t
*ret_uuid
) {
585 _cleanup_(sd_device_unrefp
) sd_device
*d
= NULL
;
586 _cleanup_free_
char *node
= NULL
;
587 sd_id128_t uuid
= SD_ID128_NULL
;
588 const char *type
, *v
;
591 r
= device_path_make_major_minor(S_IFBLK
, devid
, &node
);
593 return log_error_errno(r
, "Failed to format block device path for %u:%u: %m",
594 major(devid
), minor(devid
));
596 r
= sd_device_new_from_devnum(&d
, 'b', devid
);
598 return log_error_errno(r
, "%s: Failed to get block device: %m", node
);
600 r
= sd_device_get_property_value(d
, "ID_PART_ENTRY_SCHEME", &type
);
602 return log_device_error_errno(d
, r
, "Failed to query ID_PART_ENTRY_SCHEME: %m");
604 if (streq(type
, "gpt")) {
606 r
= sd_device_get_property_value(d
, "ID_PART_ENTRY_TYPE", &v
);
608 return log_device_error_errno(d
, r
, "Failed to query ID_PART_ENTRY_TYPE: %m");
610 r
= sd_id128_string_equal(v
, GPT_XBOOTLDR
);
612 return log_device_error_errno(d
, r
, "Failed to parse ID_PART_ENTRY_TYPE=%s: %m", v
);
614 return log_device_full_errno(
616 searching
? LOG_DEBUG
: LOG_ERR
,
617 searching
? SYNTHETIC_ERRNO(EADDRNOTAVAIL
) : SYNTHETIC_ERRNO(ENODEV
),
618 "Partition has wrong ID_PART_ENTRY_TYPE=%s for XBOOTLDR partition.", v
);
620 r
= sd_device_get_property_value(d
, "ID_PART_ENTRY_UUID", &v
);
622 return log_device_error_errno(d
, r
, "Failed to query ID_PART_ENTRY_UUID: %m");
623 r
= sd_id128_from_string(v
, &uuid
);
625 return log_device_error_errno(d
, r
, "Partition has invalid UUID ID_PART_ENTRY_TYPE=%s: %m", v
);
627 } else if (streq(type
, "dos")) {
629 r
= sd_device_get_property_value(d
, "ID_PART_ENTRY_TYPE", &v
);
631 return log_device_error_errno(d
, r
, "Failed to query ID_PART_ENTRY_TYPE: %m");
632 if (!streq(v
, "0xea"))
633 return log_device_full_errno(
635 searching
? LOG_DEBUG
: LOG_ERR
,
636 searching
? SYNTHETIC_ERRNO(EADDRNOTAVAIL
) : SYNTHETIC_ERRNO(ENODEV
),
637 "Wrong ID_PART_ENTRY_TYPE=%s for XBOOTLDR partition.", v
);
640 return log_device_full_errno(
642 searching
? LOG_DEBUG
: LOG_ERR
,
643 searching
? SYNTHETIC_ERRNO(EADDRNOTAVAIL
) : SYNTHETIC_ERRNO(ENODEV
),
644 "Not on a GPT or DOS partition table (ID_PART_ENTRY_SCHEME=%s).", type
);
652 static int verify_xbootldr(
655 bool unprivileged_mode
,
656 sd_id128_t
*ret_uuid
,
665 relax_checks
= getenv_bool("SYSTEMD_RELAX_XBOOTLDR_CHECKS") > 0;
667 r
= verify_fsroot_dir(p
, searching
, unprivileged_mode
, &devid
);
671 if (detect_container() > 0 || relax_checks
)
674 if (unprivileged_mode
)
675 r
= verify_xbootldr_udev(devid
, searching
, ret_uuid
);
677 r
= verify_xbootldr_blkid(devid
, searching
, ret_uuid
);
688 *ret_uuid
= SD_ID128_NULL
;
695 int find_xbootldr_and_warn(
698 bool unprivileged_mode
,
700 sd_id128_t
*ret_uuid
,
703 _cleanup_free_
char *p
= NULL
;
706 /* Similar to find_esp_and_warn(), but finds the XBOOTLDR partition. Returns the same errors. */
709 r
= chase_symlinks(path
, root
, CHASE_PREFIX_ROOT
, &p
, NULL
);
711 return log_error_errno(r
,
712 "Failed to resolve path %s%s%s: %m",
714 root
? " under directory " : "",
717 r
= verify_xbootldr(p
, /* searching= */ false, unprivileged_mode
, ret_uuid
, ret_devid
);
724 path
= getenv("SYSTEMD_XBOOTLDR_PATH");
728 r
= chase_symlinks(path
, root
, CHASE_PREFIX_ROOT
, &p
, NULL
);
730 return log_error_errno(r
,
731 "Failed to resolve path %s%s%s: %m",
733 root
? " under directory " : "",
736 if (!path_is_valid(p
) || !path_is_absolute(p
))
737 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
),
738 "$SYSTEMD_XBOOTLDR_PATH does not refer to absolute path, refusing to use it: %s",
741 if (stat(p
, &st
) < 0)
742 return log_error_errno(errno
, "Failed to stat '%s': %m", p
);
743 if (!S_ISDIR(st
.st_mode
))
744 return log_error_errno(SYNTHETIC_ERRNO(ENOTDIR
), "XBOOTLDR path '%s' is not a directory.", p
);
747 *ret_uuid
= SD_ID128_NULL
;
749 *ret_devid
= st
.st_dev
;
754 r
= chase_symlinks("/boot", root
, CHASE_PREFIX_ROOT
, &p
, NULL
);
758 return log_error_errno(r
,
759 "Failed to resolve path /boot%s%s: %m",
760 root
? " under directory " : "",
763 r
= verify_xbootldr(p
, true, unprivileged_mode
, ret_uuid
, ret_devid
);
766 if (!IN_SET(r
, -ENOENT
, -EADDRNOTAVAIL
)) /* This one is not it */
773 *ret_path
= TAKE_PTR(p
);