[PATCH 2/8] init: mount devtmpfs before the root filesystem

From: Ismael Luceno

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


devtmpfs is mounted after the root filesystem, which leaves the root
mount with no /dev nodes to look devices up by. A filesystem that has
to open block devices other than the one it was given has nothing to
open them by, and without an initrd there is no userspace around to
create the nodes either.

Mount it on the initial root before the root filesystem is mounted, so
the root filesystem can resolve device paths. This is what lets a
multi-device btrfs root assemble itself with no initrd to run the
device scanner.

This mount is on the initial root and goes away with it at the pivot,
so the existing mount after mount_root() is kept: that is the one that
ends up in the new root.

This is only needed by the btrfs root device scan, so it is done only when
CONFIG_BTRFS_ROOT_SCAN is set; without it boot is unchanged.

Signed-off-by: Ismael Luceno <ismael@xxxxxxxxxxx>
Signed-off-by: Ismael Luceno <iluceno@xxxxxxx>
---
init/do_mounts.c | 14 ++++++++++++++
1 file changed, 14 insertions(+)

diff --git a/init/do_mounts.c b/init/do_mounts.c
index b088021b1546..febcc37f9128 100644
--- a/init/do_mounts.c
+++ b/init/do_mounts.c
@@ -480,6 +480,20 @@ #define CIFSROOT_RETRY_MAX 5

if (root_wait)
wait_for_root(saved_root_name);
+
+ /*
+ * Mount devtmpfs before the root filesystem, so that the filesystem
+ * mounting it can look devices up by path. A multi-device btrfs root
+ * needs this: it has to open its other devices to assemble the
+ * filesystem, and there is no userspace around to create the nodes.
+ *
+ * This one is on the initial root and goes away with it below; the
+ * mount after mount_root() is the one that sticks around. Only the
+ * btrfs root device scan needs it.
+ */
+ if (IS_ENABLED(CONFIG_BTRFS_ROOT_SCAN))
+ devtmpfs_mount();
+
mount_root(saved_root_name);
devtmpfs_mount();