void __init mnt_init(void)
{
init_rootfs();
=>int __init init_rootfs(void)
{
err = register_filesystem(&rootfs_fs_type);
static struct file_system_type rootfs_fs_type = {
.name = "rootfs",
.get_sb = rootfs_get_sb,
.kill_sb = kill_litter_super,
};
}
init_mount_tree();
=>static void __init init_mount_tree(void)
{
mnt = do_kern_mount("rootfs", 0, "rootfs", NULL);
=>struct vfsmount *do_kern_mount(const char *fstype, int flags, const char *name, void *data)
{
struct file_system_type *type = get_fs_type(fstype);
mnt = vfs_kern_mount(type, flags, name, data);
=>struct vfsmount *vfs_kern_mount(struct file_system_type *type, int flags, const char *name, void *data)
{
mnt = alloc_vfsmnt(name);
error = type->get_sb(type, flags, name, data, mnt);
=>static int rootfs_get_sb(struct file_system_type *fs_type,
int flags, const char *dev_name, void *data, struct vfsmount *mnt)
{
return get_sb_nodev(fs_type, flags|MS_NOUSER, data, ramfs_fill_super,
mnt);
=>int get_sb_nodev(struct file_system_type *fs_type,
int flags, void *data,
int (*fill_super)(struct super_block *, void *, int),
struct vfsmount *mnt)
{
error = fill_super(s, data, flags & MS_SILENT ? 1 : 0);
=>int ramfs_fill_super(struct super_block * sb, void * data, int silent)
{
fsi = kzalloc(sizeof(struct ramfs_fs_info), GFP_KERNEL);
sb->s_fs_info = fsi;
sb->s_maxbytes = MAX_LFS_FILESIZE;
sb->s_blocksize = PAGE_CACHE_SIZE;
sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
sb->s_magic = RAMFS_MAGIC;
sb->s_op = &ramfs_ops;
sb->s_time_gran = 1;
inode = ramfs_get_inode(sb, S_IFDIR | fsi->mount_opts.mode, 0);
root = d_alloc_root(inode);
sb->s_root = root;
return 0;
}
s->s_flags |= MS_ACTIVE;
simple_set_mnt(mnt, s);
return 0;
}
}
mnt->mnt_mountpoint = mnt->mnt_root;
mnt->mnt_parent = mnt;
return mnt;
}
}
ns = create_mnt_ns(mnt);
init_task.nsproxy->mnt_ns = ns;
get_mnt_ns(ns);
root.mnt = ns->root;
root.dentry = ns->root->mnt_root;
set_fs_pwd(current->fs, &root);
set_fs_root(current->fs, &root);
}
}
参考文章
为linux建立最小的根文件系统
https://www.cnblogs.com/cornsea/archive/2009/02/23/1396177.html
从linux启动到rootfs的挂载分析
https://blog.csdn.net/kevin_hcy/article/details/17663341
Initrd 流程分析(2.6 cpio rootfs)
https://blog.csdn.net/yishui8181/article/details/8013783
rootfs的挂载过程
https://blog.csdn.net/nancygreen/article/details/5027039
Linux内核rootfs的初始化过程
https://blog.csdn.net/crazycoder8848/article/details/79177228
ramdisk配置、解压、创建rootfs、启动简单分析
https://www.cnblogs.com/arnoldlu/p/10986583.html