Merge pull request #28564 from YHNdnzj/gpt-auto-kill-more-duplicate
gpt-auto: don't mount ESP if there's an fstab entry for it
This commit is contained in:
@@ -574,10 +574,17 @@ static int add_partition_esp(DissectedPartition *p, bool has_xbootldr) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Check if there's an existing fstab entry for ESP. If so, we just skip the gpt-auto logic. */
|
||||
r = fstab_has_node(p->node);
|
||||
if (r < 0)
|
||||
return log_error_errno(r,
|
||||
"Failed to check if fstab entry for device '%s' exists: %m", p->node);
|
||||
if (r > 0)
|
||||
return 0;
|
||||
|
||||
/* If /boot/ is present, unused, and empty, we'll take that.
|
||||
* Otherwise, if /efi/ is unused and empty (or missing), we'll take that.
|
||||
* Otherwise, we do nothing.
|
||||
*/
|
||||
* Otherwise, we do nothing. */
|
||||
if (!has_xbootldr && slash_boot_exists()) {
|
||||
r = slash_boot_in_fstab();
|
||||
if (r < 0)
|
||||
@@ -590,16 +597,6 @@ static int add_partition_esp(DissectedPartition *p, bool has_xbootldr) {
|
||||
esp_path = "/boot";
|
||||
id = "boot";
|
||||
}
|
||||
} else {
|
||||
/* Check if the fstab entry for /boot/ is already the ESP. If so, we don't need to
|
||||
* check /efi/ or duplicate the mount there. */
|
||||
r = fstab_is_mount_point_full("/boot", p->node);
|
||||
if (r < 0)
|
||||
return log_error_errno(r,
|
||||
"Failed to check if fstab entry for /boot uses the same device as '%s': %m",
|
||||
p->node);
|
||||
if (r > 0)
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+10
-9
@@ -63,7 +63,7 @@ bool fstab_is_extrinsic(const char *mount, const char *opts) {
|
||||
return false;
|
||||
}
|
||||
|
||||
static int fstab_is_mount_point_of(const char *what_fstab, const char *path) {
|
||||
static int fstab_is_same_node(const char *what_fstab, const char *path) {
|
||||
_cleanup_free_ char *node = NULL;
|
||||
|
||||
assert(what_fstab);
|
||||
@@ -86,7 +86,7 @@ int fstab_is_mount_point_full(const char *where, const char *path) {
|
||||
_cleanup_endmntent_ FILE *f = NULL;
|
||||
int r;
|
||||
|
||||
assert(where);
|
||||
assert(where || path);
|
||||
|
||||
f = setmntent(fstab_path(), "re");
|
||||
if (!f)
|
||||
@@ -100,14 +100,15 @@ int fstab_is_mount_point_full(const char *where, const char *path) {
|
||||
if (!me)
|
||||
return errno != 0 ? -errno : false;
|
||||
|
||||
if (path_equal(where, me->mnt_dir)) {
|
||||
if (!path)
|
||||
return true;
|
||||
if (where && !path_equal(where, me->mnt_dir))
|
||||
continue;
|
||||
|
||||
r = fstab_is_mount_point_of(me->mnt_fsname, path);
|
||||
if (r > 0 || (r < 0 && !ERRNO_IS_DEVICE_ABSENT(r)))
|
||||
return r;
|
||||
}
|
||||
if (!path)
|
||||
return true;
|
||||
|
||||
r = fstab_is_same_node(me->mnt_fsname, path);
|
||||
if (r > 0 || (r < 0 && !ERRNO_IS_DEVICE_ABSENT(r)))
|
||||
return r;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
@@ -13,6 +13,9 @@ int fstab_is_mount_point_full(const char *where, const char *path);
|
||||
static inline int fstab_is_mount_point(const char *where) {
|
||||
return fstab_is_mount_point_full(where, NULL);
|
||||
}
|
||||
static inline int fstab_has_node(const char *path) {
|
||||
return fstab_is_mount_point_full(NULL, path);
|
||||
}
|
||||
|
||||
int fstab_filter_options(
|
||||
const char *opts,
|
||||
|
||||
Reference in New Issue
Block a user