简体   繁体   中英

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. I thought it's possible to do via initcalls but they're executed before kernel takes care about 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. See the source for `mounts_poll'

UPDATE [2]: I looked at RSBAC patches, RSBAC modifies prepare_namespace() function to make some actions after filesystem is mounted. It seems to be the easiest way.

Well, current Linux images are too big to fit the PC boot sector. Modern bootloaders like grub will mount an small filesystem in RAM before the real one.

To understand what is happening under the hood, you can open the disk image located under /boot. For example, in 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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