简单来说,(根文件系统)就是系统第一个mount的文件系统
Filesystem Handling
Like every traditional Unix system, Linux makes use of a system 's root filesystem : it is the filesystem that is directly mounted by the kernel during the booting phase and that holds the system initialization scripts and the most essential system program.
Other filesystems can be mounted either by the initialization scripts or directly by the users on directories of already mounted filesystems. Being a tree of directories every filesystem has its own root directory. The directory on which a filesystem is mounted is called the mount point. A mounted filesystem is a child of the mounted filesystem to which the mount point directory belongs. For instance, the /proc virtual filesystem is a child of the system 's root filesystem (and the system 's root filesystem is the parent of /proc). The root directory of a mounted filesystem hides the content of the mount point directory of the parent filesystem, as well as the whole subtree of the parent filesystem below the mount point.
转载自:http://www.91linux.com/html/article/go/20071206/8876.html
简单的来说,我认为根文件系统就是一种目录结构,那么根文件系统和普通的文件系统有什么区别呢?我认为根文件系统就是要包括Linux启动时所必须的目录和关键性的文件,例如Linux启动时都需要有init目录下的相关文件,在Linux挂载分区时Linux一定会找/etc/fstab这个挂载文件等,根文件系统中还包括了许多的应用程序bin目录等,任何包括这些Linux系统启动所必须的文件都可以成为根文件系统。
2 mount 根文件系统
linux启动时,经过一系列初始化之后,需要mount 根文件系统,为最后运行init进程等做准备,
mount 根文件系统有这么几种方式:
(1)文件系统已经存在于硬盘(或者类似的设备)的某个分区上了,kernel根据启动的命令行参数(root=/dev/xxx),直接进行mount。这里有一个问题,在root文件系统本身还不存在的情况下,kernel如何根据/dev/xxx来找到对应的设备呢?原来kernel通过直接解析设备的名称来获得设备的主、从设备号,然后就可以访问对应的设备驱动了。所以在init/main.c中有很长一串的root_dev_names,通过这个表就可以根据设备名称得到设备号。
(2)从软驱等比较慢的设备上装载根文件系统,如果kernel支持ramdisk,在装载root文件系统时,内核判断到需要从软盘(fdx)mount,就会自动把文件系统映象复制到ramdisk,一般对应设备ram0,然后在ram0上mount 根文件系统。 从源码看,如果kernel编译时没有支持ramdisk,而启动参数又root=/dev/fd0, 系统将直接在软盘上mount,除了速度比较慢,理论上是可行的(这个我没试过,不知道是不是样?)
(3)启动时用到initrd来mount根文件系统。一开始我被ramdisk和initrd这两个东西弄胡涂了,其实ramdisk只是在ram上实现的块设备,initrd可以说是启动过程中用到的一种机制。就是在装载linux之前,bootloader可以把一个比较小的根文件系统的映象装载在内存的某个指定位置,姑且把这段内存称为initrd,然后通过传递参数的方式告诉内核initrd的起始地址和大小(也可以把这些参数编译在内核中),在启动阶段就可以暂时的用initrd来mount根文件系统。initrd的最初的目的是为了把kernel的启动分成两个阶段:在kernel中保留最少最基本的启动代码,然后把对各种各样硬件设备的支持以模块的方式放在initrd中,这样就在启动过程中可以从initrd所mount的根文件系统中装载需要的模块。这样的一个好处就是在保持kernel不变的情况下,通过修改initrd中的内容就可以灵活的支持不同的硬件。在启动完成的最后阶段,根文件系统可以重新mount到其他设备上,但是也可以不再重新mount(很多嵌入式系统就是这样)。 initrd的具体实现过程是这样的:bootloader把根文件系统映象装载到内存指定位置,把相关参数传递给内核,内核启动时把initrd中的内容复制到ramdisk中(ram0),把initrd占用的内存释放掉,在ram0上mount根文件系统。从这个过程可以看出,内核需要对同时对ramdisk和initrd的支持。
二.嵌入式系统根文件系统的一种实现方法。对于kernel和根文件系统都存储在flash中的系统,一般可以利用linux启动的initrd的机制。具体的过程前面已经比较清楚了,还有一点就是在启动参数中传递root=/dev/ram0,这样使得用initrd进行mount的根文件系统不再切换,因为这个时候实际的设备就是ram0。还有就是initrd的起始地址参数为虚拟地址,需要和bootloader中用的物理地址对应。联系客服