zoukankan      html  css  js  c++  java
  • linux kernel文件系统启动部分

      现在的kernel里,有个叫做ramfs的文件系统,会把initrd(或者ramdisk,为惯性叫法)里的东西挂载到early-rootfs里(即rootfs,是ramfs的一个特殊实例),执行一些在kenrel里很难执行的操作,这样简化了kernel,方便了调试。随后可以根据需要用switch root过程删掉现在的rootfs,把真正的根文件系统挂载起来。

           早期kernel里的这个机制叫做ram disk,但这个机制比较慢,弊端比较多,所以kernel里被ramfs给替代了,但实体文件还叫initrd,而非initramfs。initramfs是在kernel后边附加一个cpio格式的image,initrd是一个独立于kernel的cpio image。

           tmpfs是ramfs的衍生物,可以将文件写入swap中,ramfs不可以;tmpfs有大小限制。tmpfs位于mm/shmem.c中,而非fs下

          在start_kernel函数里,和文件系统相关的启动流程如下:

          start_kernel——>vfs_caches_init_early————vfs_caches_init———————— rest_init——>kernel_init————>kernel_init_freeable                                                                                                                                                                                                

                                                |                                     |                                                                                            |

                                    dcache_init_early                kmem_cache_create                                                               do_basic_setup————>shmem_init(tmpfs初始化)

                                                 |                                     |                                                                                           |

                                    inode_init_early                       dcache_init                                      sys_open((const char __user *) "/dev/console", O_RDWR, 0)(标准输入文件描述符)

                                                                                       |                                                                                            |

                                                                                  inode_init                                                                         (void) sys_dup(0);

                                                                                       |                                                                                             |

                                                                                  files_init                                                                            (void) sys_dup(0);

                                                                                       |                                                                                             |

                                                                                  mnt_init                                                                                /  存在/init?                                                          

                                                                                       |                                                                                    Y                   N

                                                                             bdev_cache_init                                                                       /                        

                                                                                       |                                              执行/init,没有根文件系统了                            prepare_namespace

                                                                                chrdev_init                                        (initramfs,安卓目前采用的)                                          |

                                                                                                                                                                                                               initrd_load

                                                                                                                                                                                                                     |

                                                                                                                                                                                              mount_root(下边的流程挂载真正根文件系统)

                                                                                                                                                                                                                     |

                                                                                                                                                                                                          devtmpfs_mount("dev")

                                                                                                                                                                                                                     |

                                                                                                                                                                                              sys_mount(".", "/", NULL, MS_MOVE, NULL)

                                                                                                                                                                                                                      |

                                                                                                                                                                                                              sys_chroot(".")

    start_kernel
         |
         |
         V
    vfs_caches_init_early-------------------->dcache_init_early
                                                    |
                                                    |
                                              inode_init_early
  • 相关阅读:
    自动发送邮件功能
    工作中常用的Android系统ADB命令收集
    商城系统必须知道的【订单、优惠金额、退货、实际营收】解释
    商城系统项目必须知道的专业数据指标
    接口加密思路
    Selenium使用Chrome模拟手机浏览器方法解析
    PHP上传图片基本代码示例
    iframe子页面获取父页面的点击事件
    javascript实现网页倒计时效果
    Crontab常用命令总结
  • 原文地址:https://www.cnblogs.com/cascle/p/5822727.html
Copyright © 2011-2022 走看看