[PATCH 7/8] init: let a filesystem resolve a root device by UUID or label

From: Ismael Luceno

Date: Mon Nov 16 2026 - 17:43:54 EST


root= takes PARTUUID= and PARTLABEL=, both of which come from the
partition table, and so can be resolved by the block layer alone.
UUID= and LABEL= name the filesystem, and a filesystem UUID and label
live in its superblock. Nothing outside the filesystem can recognise
one, so without this a "root=UUID=..." is taken for a device name,
fails to resolve, and — because that failure is indistinguishable
from a bad device name — takes rootwait down with it on the way past.

Let each registered filesystem look for its own UUID or label, and ask
them in turn until one claims the value. Filesystems that do not
implement it cost nothing, so this is inert for every filesystem that
has no use for it.

The lookup opens and reads devices, so it can sleep; take a module
reference for as long as the filesystem is in use, as the comment on
file_systems describes.

Signed-off-by: Ismael Luceno <ismael@xxxxxxxxxxx>
Signed-off-by: Ismael Luceno <iluceno@xxxxxxx>
---
fs/filesystems.c | 37 +++++++++++++++++++++++++++++++++++++
include/linux/fs.h | 10 ++++++++++
init/do_mounts.c | 19 +++++++++++++++++++
3 files changed, 66 insertions(+)

diff --git a/fs/filesystems.c b/fs/filesystems.c
index 3083d904df9b..13e509e027d6 100644
--- a/fs/filesystems.c
+++ b/fs/filesystems.c
@@ -240,6 +240,43 @@ SYSCALL_DEFINE3(sysfs, int, option, unsigned long, arg1, unsigned long, arg2)
return count;
}

+/**
+ * find_dev_by_fs_spec - find the block device holding a filesystem by UUID or label
+ * @key: what @value is, "UUID" or "LABEL"
+ * @value: the filesystem UUID, or its label
+ *
+ * A filesystem UUID and label live in the superblock rather than in the
+ * partition metadata, so unlike PARTUUID= and PARTLABEL= they cannot be
+ * resolved from the partition table: the filesystem that knows them has to be
+ * asked. Offer the value to each registered filesystem until one claims it.
+ *
+ * Return the dev_t found, or 0 if no filesystem recognised it.
+ */
+dev_t find_dev_by_fs_spec(const char *key, const char *value)
+{
+ struct file_system_type *p;
+ dev_t dev = 0;
+
+ guard(rcu)();
+ hlist_for_each_entry_rcu(p, &file_systems, list) {
+ if (!(p->fs_flags & FS_REQUIRES_DEV) || !p->find_by_spec)
+ continue;
+ /*
+ * The lookup reads devices and so may sleep; hold a module
+ * reference for as long as we use p, as the comment on
+ * file_systems above describes.
+ */
+ if (!try_module_get(p->owner))
+ continue;
+ if (p->find_by_spec(key, value, &dev) && dev)
+ break;
+ module_put(p->owner);
+ }
+
+ return dev;
+}
+EXPORT_SYMBOL_GPL(find_dev_by_fs_spec);
+
#ifdef CONFIG_PROC_FS
static void invalidate_filesystems_string(void)
{
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 5b3a100aba77..9267ae28dc36 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -2308,6 +2308,15 @@ #define FS_USERNS_DELEGATABLE 1024 /* Can be mounted inside userns from outside
#define FS_DISALLOW_NOTIFY 2048 /* No fsnotify marks on its objects */
#define FS_RENAME_DOES_D_MOVE 32768 /* FS will handle d_move() during rename() internally. */
int (*init_fs_context)(struct fs_context *);
+ /*
+ * Look for the block device holding the filesystem that @key
+ * identifies as @value, for "root=UUID=" and "root=LABEL=". Both live
+ * in the superblock rather than in the partition metadata, so unlike
+ * PARTUUID= and PARTLABEL= it is the filesystem that has to recognise
+ * them. @key is "UUID" or "LABEL". Set *dev and return 0 on a
+ * match, or return an error if there is none.
+ */
+ int (*find_by_spec)(const char *key, const char *value, dev_t *dev);
const struct fs_parameter_spec *parameters;
void (*kill_sb) (struct super_block *);
struct module *owner;
@@ -3579,6 +3588,7 @@ #define DEFINE_SIMPLE_ATTRIBUTE_SIGNED(__fops, __get, __set, __fmt) \
size_t len, loff_t *ppos);

int __init list_bdev_fs_names(char *buf, size_t size);
+dev_t find_dev_by_fs_spec(const char *key, const char *value);

#define __FMODE_EXEC ((__force int) FMODE_EXEC)

diff --git a/init/do_mounts.c b/init/do_mounts.c
index f1dcb18201eb..3845b1e67f46 100644
--- a/init/do_mounts.c
+++ b/init/do_mounts.c
@@ -453,6 +453,25 @@ #define CIFSROOT_RETRY_MAX 5
return Root_NFS;
if (strcmp(root_device_name, "/dev/cifs") == 0)
return Root_CIFS;
+
+ /*
+ * A filesystem UUID or label is in the superblock, not in the
+ * partition table, so it is the filesystem that has to recognise it.
+ * Try that before early_lookup_bdev(), which would take "UUID=..." for
+ * a device name and fail.
+ */
+ if (!strncmp(root_device_name, "UUID=", 5)) {
+ dev = find_dev_by_fs_spec("UUID", root_device_name + 5);
+ if (dev)
+ return dev;
+ return 0;
+ }
+ if (!strncmp(root_device_name, "LABEL=", 6)) {
+ dev = find_dev_by_fs_spec("LABEL", root_device_name + 6);
+ if (dev)
+ return dev;
+ return 0;
+ }
if (strcmp(root_device_name, "/dev/ram") == 0)
return Root_RAM0;