2
votes

I am trying to understand how kernel mounting the filesystem. While checking the source, I have observed that do_mounts.c file having the source related to mounting (rootfs file system is registered inside init_rootfs()).

rootfs_mount() function was called by start_kernel() initially, I could not able to understand the usage of mount_nodev() inside rootfs_mount(). Could you please help me to understand the logic behind calling rootfs_mount() from start_kernel(), as it is not mounting any filesystem.

Actual filesystem mounting is initiated by calling mount_nfs_root() or mount_block_root() functions from kernel_init(), please tell me if my understanding is different.

1
Which kernel version did you check? - Armali
I was using 3.12 and 3.14 Linux kernel versions. - user3693586
I see no call to rootfs_mount() in start_kernel(). - Armali
I think it follows "start_kernel ----> vfs_caches_init ----> mnt_init ----> init_mount_tree ----> vfs_kern_mount ----> mount_fs ----> rootfs_mount". you can use dump_stack to check. - user3693586
That's right, here type->mount in mount_fs() is rootfs_mount (from rootfs_fs_type). - Armali

1 Answers

1
votes

I could not able to understand the usage of mount_nodev() inside rootfs_mount(). Could you please help me to understand the logic behind calling rootfs_mount() from start_kernel(), as it is not mounting any filesystem.

Well, mount_nodev() does not mean it is not mounting any filesystem, but rather (see VFS - The Linux Kernel Archives):

mount_nodev: mount a filesystem that is not backed by a device

(for example NFS). By the way, this is also reflected in /proc/filesystems.
rootfs_mount() in particular mounts the ramfs or tmpfs.

Addendum - This Linux Initialization HOWTO says about the call in start_kernel():

vfs_caches_init(mempages)

(in linux/fs/dcache.c)

Call kmem_cache_create() to create slab caches for buffer_head, names_cache, filp, and for CONFIG_QUOTA, dquot.

Call dcache_init() to create the dentry_cache and dentry_hashtable.