- 论坛徽章:
- 5
|
本帖最后由 T-Bagwell 于 2013-02-01 10:22 编辑
- [root@T-bagwell linux-2.6]# cat /proc/mounts
- rootfs / rootfs rw 0 0
- /proc /proc proc rw,relatime 0 0
- /sys /sys sysfs rw,relatime 0 0
- udev /dev devtmpfs rw,relatime,size=1020184k,nr_inodes=255046,mode=755 0 0
- devpts /dev/pts devpts rw,relatime,gid=5,mode=620,ptmxmode=000 0 0
- tmpfs /dev/shm tmpfs rw,relatime 0 0
- /dev/sda1 / ext4 rw,relatime,barrier=1,data=ordered 0 0
- /proc/bus/usb /proc/bus/usb usbfs rw,relatime 0 0
- none /proc/sys/fs/binfmt_misc binfmt_misc rw,relatime 0 0
- none /proc/fs/vmblock/mountPoint vmblock rw,relatime 0 0
- [root@T-bagwell linux-2.6]#
复制代码 rootfs在vfs_caches_init -> mnt_init -> init_rootfs里面搞定的
最终我们的/dev/blockdevice会挂在这个的节点下面
从start_kernel按照流程往下走
先过vfs_init,然后过rest_init
然后创建线程kernel_init
- kernel_thread(kernel_init, NULL, CLONE_FS | CLONE_SIGHAND);
复制代码 进去后
- 807 static int __ref kernel_init(void *unused)
- 808 {
- 809 kernel_init_freeable();
- 810 /* need to finish all async __init code before freeing the memory */
- 811 async_synchronize_full();
- 812 free_initmem();
- 813 mark_rodata_ro();
- 814 system_state = SYSTEM_RUNNING;
- 815 numa_default_policy();
- 816
- 817 flush_delayed_fput();
- 818
- 819 if (ramdisk_execute_command) {
- 820 if (!run_init_process(ramdisk_execute_command))
- 821 return 0;
- 822 printk(KERN_WARNING "Failed to execute %s\n",
- 823 ramdisk_execute_command);
- 824 }
- 825
- 826 /*
- 827 * We try each of these until one succeeds.
- 828 *
- 829 * The Bourne shell can be used instead of init if we are
- 830 * trying to recover a really broken machine.
- 831 */
- 832 if (execute_command) {
- 833 if (!run_init_process(execute_command))
- 834 return 0;
- 835 printk(KERN_WARNING "Failed to execute %s. Attempting "
- 836 "defaults...\n", execute_command);
- 837 }
- 838 if (!run_init_process("/sbin/init") ||
- 839 !run_init_process("/etc/init") ||
- 840 !run_init_process("/bin/init") ||
- 841 !run_init_process("/bin/sh"))
- 842 return 0;
- 843
- 844 panic("No init found. Try passing init= option to kernel. "
- 845 "See Linux Documentation/init.txt for guidance.");
- 846 }
复制代码 很明显了
rootfs的注册
- 259 static struct file_system_type ramfs_fs_type = {
- 260 .name = "ramfs",
- 261 .mount = ramfs_mount,
- 262 .kill_sb = ramfs_kill_sb,
- 263 };
- 264 static struct file_system_type rootfs_fs_type = {
- 265 .name = "rootfs",
- 266 .mount = rootfs_mount,
- 267 .kill_sb = kill_litter_super,
- 268 };
- 269
- 270 static int __init init_ramfs_fs(void)
- 271 {
- 272 return register_filesystem(&ramfs_fs_type);
- 273 }
- 274 module_init(init_ramfs_fs)
- 275
- 276 int __init init_rootfs(void)
- 277 {
- 278 int err;
- 279
- 280 err = bdi_init(&ramfs_backing_dev_info);
- 281 if (err)
- 282 return err;
- 283
- 284 err = register_filesystem(&rootfs_fs_type);
- 285 if (err)
- 286 bdi_destroy(&ramfs_backing_dev_info);
- 287
- 288 return err;
- 289 }
- "fs/ramfs/inode.c" 289L, 6876C
复制代码 挂载
- 2647 static void __init init_mount_tree(void)
- 2648 {
- 2649 struct vfsmount *mnt;
- 2650 struct mnt_namespace *ns;
- 2651 struct path root;
- 2652 struct file_system_type *type;
- 2653
- 2654 type = get_fs_type("rootfs");
- 2655 if (!type)
- 2656 panic("Can't find rootfs type");
- 2657 mnt = vfs_kern_mount(type, 0, "rootfs", NULL);
- 2658 put_filesystem(type);
- 2659 if (IS_ERR(mnt))
- 2660 panic("Can't create rootfs");
- 2661
- 2662 ns = create_mnt_ns(mnt);
- 2663 if (IS_ERR(ns))
- 2664 panic("Can't allocate initial namespace");
- 2665
- 2666 init_task.nsproxy->mnt_ns = ns;
- 2667 get_mnt_ns(ns);
- 2668
- 2669 root.mnt = mnt;
- 2670 root.dentry = mnt->mnt_root;
- 2671
- 2672 set_fs_pwd(current->fs, &root);
- 2673 set_fs_root(current->fs, &root);
- 2674 }
复制代码 |
|