Skip to content

Commit f9259be

Browse files
Christoph HellwigAl Viro
Christoph Hellwig
authored and
Al Viro
committed
init: allow mounting arbitrary non-blockdevice filesystems as root
Currently the only non-blockdevice filesystems that can be used as the initial root filesystem are NFS and CIFS, which use the magic "root=/dev/nfs" and "root=/dev/cifs" syntax that requires the root device file system details to come from filesystem specific kernel command line options. Add a little bit of new code that allows to just pass arbitrary string mount options to any non-blockdevice filesystems so that it can be mounted as the root file system. For example a virtiofs root file system can be mounted using the following syntax: "root=myfs rootfstype=virtiofs rw" Based on an earlier patch from Vivek Goyal <[email protected]>. Signed-off-by: Christoph Hellwig <[email protected]> Signed-off-by: Al Viro <[email protected]>
1 parent e24d12b commit f9259be

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

init/do_mounts.c

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,45 @@ static int __init mount_cifs_root(void)
534534
}
535535
#endif
536536

537+
static bool __init fs_is_nodev(char *fstype)
538+
{
539+
struct file_system_type *fs = get_fs_type(fstype);
540+
bool ret = false;
541+
542+
if (fs) {
543+
ret = !(fs->fs_flags & FS_REQUIRES_DEV);
544+
put_filesystem(fs);
545+
}
546+
547+
return ret;
548+
}
549+
550+
static int __init mount_nodev_root(void)
551+
{
552+
char *fs_names, *fstype;
553+
int err = -EINVAL;
554+
555+
fs_names = (void *)__get_free_page(GFP_KERNEL);
556+
if (!fs_names)
557+
return -EINVAL;
558+
split_fs_names(fs_names, root_fs_names);
559+
560+
for (fstype = fs_names; *fstype; fstype += strlen(fstype) + 1) {
561+
if (!fs_is_nodev(fstype))
562+
continue;
563+
err = do_mount_root(root_device_name, fstype, root_mountflags,
564+
root_mount_data);
565+
if (!err)
566+
break;
567+
if (err != -EACCES && err != -EINVAL)
568+
panic("VFS: Unable to mount root \"%s\" (%s), err=%d\n",
569+
root_device_name, fstype, err);
570+
}
571+
572+
free_page((unsigned long)fs_names);
573+
return err;
574+
}
575+
537576
void __init mount_root(void)
538577
{
539578
#ifdef CONFIG_ROOT_NFS
@@ -550,6 +589,10 @@ void __init mount_root(void)
550589
return;
551590
}
552591
#endif
592+
if (ROOT_DEV == 0 && root_device_name && root_fs_names) {
593+
if (mount_nodev_root() == 0)
594+
return;
595+
}
553596
#ifdef CONFIG_BLOCK
554597
{
555598
int err = create_dev("/dev/root", ROOT_DEV);

0 commit comments

Comments
 (0)