我是在引导linux (版本4.14.13+),而不使用initrd/initramfs,并且我看到/sbin/modprobe在挂载根文件系统之前运行。我想知道这怎么可能。每当使用文件系统时,我都会将内核检测到printk,这也是我知道使用/sbin/modprobe的原因。
下面的链接包含我的引导的完整dmesg输出:dmesg输出
[ 3.175001] Used file system /sbin/modprobe!
[ 3.179080] Used file system /dev/console!
[ 3.844276] Used file system /dev/md0!
[ 3.899302] VFS: Mounted root (ext4 filesystem) on device 8:17.
[ 3.951578] devtmpfs: mounted
[ 3.987527] Used file system /bin/sh!发布于 2018-07-12 14:49:40
我不认为它成功地运行了/sbin/modprobe。但有件事让我很感兴趣。看起来,它试图在"devtmpfs:/dev/console“或”挂载根(ext4文件系统)“之前打开/dev/console,并且没有其他打开D2的尝试。但是我认为内核必须从某个文件系统中为init打开/dev/console (在您的例子中是/bin/sh).
看起来,如果您没有initramfs,内核就会创建一个非常简单的假的。如果我的跟踪是正确的,这就是为什么它可以在挂载真正的根文件系统之前打开/dev/console。
https://github.com/torvalds/linux/blob/v4.14/init/noinitramfs.c
/*
* Create a simple rootfs that is similar to the default initramfs
*/
static int __init default_rootfs(void)
{
int err;
err = sys_mkdir((const char __user __force *) "/dev", 0755);
if (err < 0)
goto out;
err = sys_mknod((const char __user __force *) "/dev/console",
S_IFCHR | S_IRUSR | S_IWUSR,
new_encode_dev(MKDEV(5, 1)));
if (err < 0)
goto out;
err = sys_mkdir((const char __user __force *) "/root", 0700);
if (err < 0)
goto out;
return 0;/root目录依赖于内核代码中的其他部分,以加载和转换到真正的root=文件系统。
引入此函数的提交说明,只有在编译出initrd和initramfs支持时才使用此特定函数。否则,“默认initramfs”将提供/dev/console和/root,如果在启动内核时没有传递特定的initramfs,并且没有指定要内置到内核的initramfs。
https://github.com/torvalds/linux/commit/c33df4eaaf41fd3e34837a6ae9a5f9970c393d9f
https://unix.stackexchange.com/questions/454511
复制相似问题