[RFC PATCH] rootfs: Use tmpfs for rootfs even if root= is given

From: Stefan Berger
Date: Tue Oct 31 2023 - 11:44:40 EST


rootfs currently does not use tmpfs if the root= boot option is passed
even though the documentation about rootfs (added in 6e19eded3684) in
Documentation/filesystems/ramfs-rootfs-initramfs.rst states:

If CONFIG_TMPFS is enabled, rootfs will use tmpfs instead of ramfs by
default. To force ramfs, add "rootfstype=ramfs" to the kernel command
line.

However, this currently does not work when root= is passed on the boot
command line since then saved_root_name contains a string and prevents
usage of tmpfs. Therefore, remove the check on saved_root_name to
enable tmpfs for rootfs.

Fixes: 6e19eded3684 ("initmpfs: use initramfs if rootfstype= or root= specified")
Signed-off-by: Stefan Berger <stefanb@xxxxxxxxxxxxx>
Cc: "Milton D. Miller II" <mdmii@xxxxxxxxxxx>
Cc: Rob Landley <rob@xxxxxxxxxxx>
Cc: Jeff Layton <jlayton@xxxxxxxxxx>
Cc: Jens Axboe <axboe@xxxxxxxxx>
Cc: Jim Cromie <jim.cromie@xxxxxxxxx>
Cc: Sam Ravnborg <sam@xxxxxxxxxxxx>
Cc: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>
Cc: "Eric W. Biederman" <ebiederm@xxxxxxxxxxxx>
Cc: Alexander Viro <viro@xxxxxxxxxxxxxxxxxx>
Cc: "H. Peter Anvin" <hpa@xxxxxxxxx>
Cc: Mimi Zohar <zohar@xxxxxxxxxxxxx>
---
init/do_mounts.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/init/do_mounts.c b/init/do_mounts.c
index 5dfd30b13f48..6567cf5807ee 100644
--- a/init/do_mounts.c
+++ b/init/do_mounts.c
@@ -510,7 +510,7 @@ struct file_system_type rootfs_fs_type = {

void __init init_rootfs(void)
{
- if (IS_ENABLED(CONFIG_TMPFS) && !saved_root_name[0] &&
+ if (IS_ENABLED(CONFIG_TMPFS) &&
(!root_fs_names || strstr(root_fs_names, "tmpfs")))
is_tmpfs = true;
}
--
2.40.1