简体   繁体   English

有没有办法等到根文件系统挂载?

[英]Is there a way to wait until root filesystem is mounted?

I have a statically linked code(not a module) in kernel that should launch kernel thread after root file system is mounted. 我在内核中有一个静态链接代码(不是模块),应该挂载根文件系统启动内核线程。 The problem is I don't know how to do this without modifying prepare_namespace() kernel function. 问题是我不知道如何在不修改prepare_namespace()内核函数的情况下执行此操作。 I thought it's possible to do via initcalls but they're executed before kernel takes care about rootfs. 我认为可以通过initcalls来做,但是在内核处理rootfs之前它们已经被执行了。 Does anyone know the best way to do this? 有谁知道最好的方法吗?

UPDATE [1]: @BenVoigit suggested the following solution in comments: Seems like you should open /proc/mounts and poll_wait on it. 更新[1]: @ BenVoigit在评论中提出了以下解决方案: 好像你应该在它上面打开/ proc / mounts和poll_wait。 See the source for `mounts_poll' 查看`mounts_poll'的来源

UPDATE [2]: I looked at RSBAC patches, RSBAC modifies prepare_namespace() function to make some actions after filesystem is mounted. 更新[2]:我查看了RSBAC补丁,RSBAC修改了prepare_namespace()函数,以便挂载文件系统执行一些操作。 It seems to be the easiest way. 这似乎是最简单的方法。

Well, current Linux images are too big to fit the PC boot sector. 那么,目前的Linux映像太大了,无法适应PC启动扇区。 Modern bootloaders like grub will mount an small filesystem in RAM before the real one. 像grub这样的现代引导程序会在真正的引导程序之前在RAM中安装一个小文件系统。

To understand what is happening under the hood, you can open the disk image located under /boot. 要了解底层发生的情况,可以打开位于/ boot下的磁盘映像。 For example, in Ubuntu: 例如,在Ubuntu中:

mkdir test
cd test
zcat /boot/initrd.img-2.6.35-24-generic > image.cpio
cpio -i < image.cpio
vim init

In the end, it's just a bunch of shell scripts - the simplicity is almost poetic. 最后,它只是一堆shell脚本 - 简单几乎是诗意的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM