Linux initramfs说明 inux文件系统初始化过程(3)---加载initrd(上) linux文件系统初始化过程(4)---加载initrd(中) linux文件系统初始化过程(3)---加载initrd(上)

1.前言

最近在尝试对手头的开发板进行移植,此处记录initramfs挂载的基本流程,记录一下,以备后查。分析时是基于linux3.4.2

2. rootfs的挂载

start_kernel->

  vfs_caches_init(num_physpages);

    mnt_init(unsigned long mempages)

      init_rootfs

        register_filesystem(&rootfs_fs_type)

      init_mount_tree

        do_kern_mount

          mount_fs

            type->mount

        set_fs_pwd

        set_fs_root

      

1. 在vfs_caches_init中会完成VFS的构建,并将rootfs挂载到VFS上,VFS与rootfs有一种水乳交融的关系,rootfs为VFS提供了根目录,而rootfs又作为第一个文件系统挂载到VFS;

2. do_kern_mount 会分配vfsmnt, vfsmnt是对挂载点的描述,它连接了挂载点和待挂载文件系统;

3. type->mount调用的就是rootfs的mount也就是rootfs_mount,rootfs_mount中会创建superblock, 并通过ramfs_fill_super创建出根inode和根dentry,最后完成rootfs挂载,实际上就是将创建的

vfsmnt的挂载点mnt_mountpoint指向新创建的根dentry,挂载的根目录mnt_root也为根dentry。注意实际的文件系统挂载时两者未必一样。

4.set_fs_pwd设置进程的当前路径,set_fs_root设置进程的根路径为根目录

经过如上几个步骤就完成了VFS根目录的创建,搭建起VFS的雏形

3.释放initramfs到rootfs 

start_kernel->

  vfs_caches_init(num_physpages);

  rest_init->

    kernel_thread(kernel_init, NULL, CLONE_FS | CLONE_SIGHAND)

      kernel_init

        do_basic_setup

          do_initcalls

            populate_rootfs

              unpack_to_rootfs

1.populate_rootfs通过调用unpack_to_rootfs 会将initramfs的cpio镜像释放到上一节创建的rootfs中

2.cpio的格式可以参考inux文件系统初始化过程(3)---加载initrd(上)

3.释放过程是通过在rootfs中创建目录,普通文件,链接文件,挂载sysfs, proc等文件系统,使得VFS变成枝繁叶茂的大树

释放过程可参考linux文件系统初始化过程(4)---加载initrd(中)

 参考文档

https://www.ibm.com/developerworks/cn/linux/l-k26initrd/

https://www.ibm.com/developerworks/cn/linux/l-vfs/

https://blog.csdn.net/nancygreen/article/details/5027039

https://blog.csdn.net/ooonebook/article/details/52624481

https://blog.csdn.net/scotthuang1989/article/details/43603233  Linux Filesystem: 关于vfsmount的理解

https://blog.csdn.net/yiyeguzhou100/article/details/78426292 initramfs的加载过程(从uboot到kernel)

https://blog.csdn.net/ooonebook/article/details/52624481 [rootfs] InitRamdisk & InitRamfs 介绍和使用

http://www.cnblogs.com/wuchanming/p/3769736.html linux文件系统初始化过程(3)---加载initrd(上)

猜你喜欢

转载自www.cnblogs.com/smartjourneys/p/9566974.html