在系统启动过程的最后阶段,linux内核在调用sys_mount挂载实际根文件系统之前,先调用了init_mount_tree()这个函数挂载了一个虚拟的根文件系统,这是一个基于内存的根文件系统,类似于ramfs文件系统,在挂载完这个“虚拟的”文件系统之后,建立了VFS根目录,也就是“/” 目录。然后才调用sys_mount()挂载真正的根文件系统(比如SD卡上的ext4),最后将它的挂载点移动到“/”目录,覆盖掉原先挂载的虚拟根文件系统。上面所说的真实根文件系统,指的是 有非易失性存储介质的文件系统。(比如硬盘,SD卡)
虚拟根文件系统,指的是掉电就消失的文件系统,比如linux真正第一个挂载的“根”,就是一个基于内存的根文件系统,它是虚拟的,没有对应外部非易失性存储介质。
Ramfs-rootfs-initramfs.txt
==========================================================
All 2.6 Linux kernels contain a gzipped "cpio" format archive, which is
extracted into rootfs when the kernel boots up. After extracting, the kernel
checks to see if rootfs contains a file "init", and if so it executes it as PID
1. If found, this init process is responsible for bringing the system the rest
of the way up, including locating and mounting the real root device (if any).
If rootfs does not contain an init program after the embedded cpio archive is
extracted into it, the kernel will fall through to the older code to locate and
mount a root partition, then exec some variant of /sbin/init out of that.
he initial RAM disk is necessary for booting linux system.
the RAM disk image is created by mkinitrd.
Why is it necessary?
because we try to avoid a classic problem: "which comes first the chicken or the egg". Think about it: how do you boot the root file system if it resides on a device that requires a module in the root file system to initialize? The answer is: by using the initrd with the required module in it that is available to the kernel before the root file system is mounted. Kernel will then be started after RAM disk image is loaded.