Skip to content

Commit

Permalink
rootfs: Fix support for rootfstype= when root= is given
Browse files Browse the repository at this point in the history
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.

This currently does not work when root= is provided since then
saved_root_name contains a string and rootfstype= is ignored. Therefore,
ramfs is currently always chosen when root= is provided.

The current behavior for rootfs's filesystem is:

   root=       | rootfstype= | chosen rootfs filesystem
   ------------+-------------+--------------------------
   unspecified | unspecified | tmpfs
   unspecified | tmpfs       | tmpfs
   unspecified | ramfs       | ramfs
    provided   | ignored     | ramfs

rootfstype= should be respected regardless whether root= is given,
as shown below:

   root=       | rootfstype= | chosen rootfs filesystem
   ------------+-------------+--------------------------
   unspecified | unspecified | tmpfs  (as before)
   unspecified | tmpfs       | tmpfs  (as before)
   unspecified | ramfs       | ramfs  (as before)
    provided   | unspecified | ramfs  (compatibility with before)
    provided   | tmpfs       | tmpfs  (new)
    provided   | ramfs       | ramfs  (new)

This table represents the new behavior.

Fixes: 6e19ede ("initmpfs: use initramfs if rootfstype= or root= specified")
Cc: <[email protected]>
Signed-off-by: Rob Landley <[email protected]>
Link: https://lore.kernel.org/lkml/[email protected]/
Reviewed-and-Tested-by: Mimi Zohar <[email protected]>
Signed-off-by: Stefan Berger <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Greg Kroah-Hartman <[email protected]>
  • Loading branch information
stefanberger authored and gregkh committed Dec 7, 2023
1 parent 96d1d57 commit 21528c6
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions init/do_mounts.c
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,10 @@ struct file_system_type rootfs_fs_type = {

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

0 comments on commit 21528c6

Please sign in to comment.