对Linux Kernel有兴趣的朋友进来讨论下

ChenQi 发布于 2012/09/14 15:27
阅读 1K+
收藏 4

我们知道,在Linux系统启动过程中,会有一个rootfs先被加载到ramdisk中,执行一些用户空间操作(这个rootfs,有时被称为early user space或者temporary root file system,之后会被pivot,被真正的root file system所取代。)

这样做的原因是为了解决那个“先鸡后蛋,先蛋后鸡”的问题:如果root文件系统不被加载,那么我们无法注册其所在的实际硬件(比如某个block device);如果某个block device不被注册,我们就无法加载在它上面的root文件系统。所以,就出现了rootfs,启动时加载到ramdisk中,执行早期用户空间操作。

我的问题是:目前较新版本的kernel中(2.6.32以后),kernel就引入了devtmpfs这个实现后,这个最初的rootfs是否还有必要呢?

以下是devtmpfs这个feature在merge进kernel时的一段话:

With the kernel populated /dev, existing initramfs or kernel-mount
bootup logic can be optimized to be more efficient, and not to require a
full coldplug run, which is currently needed to bootstrap the inital
/dev directory content, before continuing bringing up the rest of
the system. There will be no missed events to replay, because /dev is
available before the first kernel device is registered with the core.

 参见:http://lwn.net/Articles/330985/

按照以上这段话的意思,在devtmpfs实现后,就不会再有那个“鸡蛋”问题了。那么初始时的rootfs是否还有必要呢?

有没有哪位朋友对这方面有所了解的?

 

加载中
0
中山野鬼
中山野鬼
这方面我所了解的也是皮毛,不敢发出意见,不过站个坑,点支烟,蹲候言论,以借鉴学习。哈。
景愿
景愿
按照以往经验,如果某个评论超过三整行后,野鬼就会放下手里的烟,然后插入讨论之
mrbigq
mrbigq
呵呵
0
ChenQi
ChenQi

引用来自“中山野鬼”的答案

这方面我所了解的也是皮毛,不敢发出意见,不过站个坑,点支烟,蹲候言论,以借鉴学习。哈。
奥义:人工置顶之术!!!
0
理工男海哥
理工男海哥
楼主, rootfs是linux文件系统,在linux中,一切皆文件。没有了文件,哪来的系统?
ChenQi
ChenQi
那个是real root file system,通常存在于硬盘或者网络上。我说的rootfs是kernel初始化早期加载在ramdisk中的rootfs。
0
RoamerLuan
RoamerLuan

抄了一段话 大家随意看看哈 

see below:

---------------------------------------------------------

ramfs and tmpfs:
----------------

One downside of ramfs is you can keep writing data into it until you fill
up all memory, and the VM can't free it because the VM thinks that files
should get written to backing store (rather than swap space), but ramfs hasn't
got any backing store.  Because of this, only root (or a trusted user) should
be allowed write access to a ramfs mount.

A ramfs derivative called tmpfs was created to add size limits, and the ability
to write the data to swap space.  Normal users can be allowed write access to
tmpfs mounts.  See Documentation/filesystems/tmpfs.txt for more information.

What is rootfs?
---------------

Rootfs is a special instance of ramfs (or tmpfs, if that's enabled), which is
always present in 2.6 systems.  You can't unmount rootfs for approximately the
same reason you can't kill the init process; rather than having special code
to check for and handle an empty list, it's smaller and simpler for the kernel
to just make sure certain lists can't become empty.

Most systems just mount another filesystem over rootfs and ignore it.  The
amount of space an empty instance of ramfs takes up is tiny.

0
ChenQi
ChenQi

引用来自“RoamerLuan”的答案

抄了一段话 大家随意看看哈 

see below:

---------------------------------------------------------

ramfs and tmpfs:
----------------

One downside of ramfs is you can keep writing data into it until you fill
up all memory, and the VM can't free it because the VM thinks that files
should get written to backing store (rather than swap space), but ramfs hasn't
got any backing store.  Because of this, only root (or a trusted user) should
be allowed write access to a ramfs mount.

A ramfs derivative called tmpfs was created to add size limits, and the ability
to write the data to swap space.  Normal users can be allowed write access to
tmpfs mounts.  See Documentation/filesystems/tmpfs.txt for more information.

What is rootfs?
---------------

Rootfs is a special instance of ramfs (or tmpfs, if that's enabled), which is
always present in 2.6 systems.  You can't unmount rootfs for approximately the
same reason you can't kill the init process; rather than having special code
to check for and handle an empty list, it's smaller and simpler for the kernel
to just make sure certain lists can't become empty.

Most systems just mount another filesystem over rootfs and ignore it.  The
amount of space an empty instance of ramfs takes up is tiny.

恩。 是kernel doc中的ramfs-rootfs-and-initramfs。说实话,我自己没怎么看懂这个doc。

尤其是这段话:

You can't unmount rootfs for approximately the
same reason you can't kill the init process; rather than having special code
to check for and handle an empty list, it's smaller and simpler for the kernel
to just make sure certain lists can't become empty.

 它所指的certain lists是什么?

 

 

0
凉风微软
凉风微软

临时根文件系统...

0
汉克斯
汉克斯

@ChenQi @中山野鬼 

我这人比较懒,我就简单说下吧。KERNEL在加载之前从FLASH的0X00000000拷贝引导程序(如UBOOT,NANDBOOT,BAREBOX等)到RAM开始执行,boot程序自己会创建一个最初的,也是最简单的cramfs,里面有对FLASH的分块,硬件设备初始化(如:初始化网卡设置MAC地址等),打开watchdog等动作后,拷贝内核镜像到指定块一般是0x0080000000的地址(这个地址可根据你的硬件修改),创建文件系统,创建devfs(现在一般用udev),加载驱动,运行initd,开始运行LINUX,然后就是你的“鸡和蛋的问题”了。

0
alexchen
alexchen
rootfs必须得有的,就像我们吃饭一样,必须先有碗去盛饭,如果没有加载rootfs实际的根文件系统在内存中是一片混乱.
0
tsuibin
tsuibin

引用来自“汉克斯”的答案

@ChenQi @中山野鬼 

我这人比较懒,我就简单说下吧。KERNEL在加载之前从FLASH的0X00000000拷贝引导程序(如UBOOT,NANDBOOT,BAREBOX等)到RAM开始执行,boot程序自己会创建一个最初的,也是最简单的cramfs,里面有对FLASH的分块,硬件设备初始化(如:初始化网卡设置MAC地址等),打开watchdog等动作后,拷贝内核镜像到指定块一般是0x0080000000的地址(这个地址可根据你的硬件修改),创建文件系统,创建devfs(现在一般用udev),加载驱动,运行initd,开始运行LINUX,然后就是你的“鸡和蛋的问题”了。

是的,我做的系统也差不多先从0x0读bootloader,bootloader起来之后再从0x8000加载内核,内核加载后,才开始挂文件系统,在没执行内核之前,只是在bootloader里面实现几种文件系统和最基本的flash驱动
返回顶部
顶部