免费注册 查看新帖 |

Chinaunix

广告
  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 897 | 回复: 0
打印 上一主题 下一主题

mount root filesystem的三种方式 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-03-28 11:44 |只看该作者 |倒序浏览

Linux Kernel 2.6.20[Documentation/early-userspace/Readme]

The kernel has currently 3 ways to mount the root filesystem:

a) all required device and filesystem drivers compiled into the kernel, no initrd.  init/main.c:init() will call prepare_namespace() to mount the final root filesystem, based on the root= option and optional init= to run some other init binary than listed at the end of init/main.c:init().

b) some device and filesystem drivers built as modules and stored in an initrd.  The initrd must contain a binary '/linuxrc' which is supposed to load these driver modules.  It is also possible to mount the final root filesystem via linuxrc and use the pivot_root syscall.  The initrd is mounted and executed via repare_namespace().

c) using initramfs.  The call to prepare_namespace() must be skipped. This means that a binary must do all the work.  Said binary can be stored into initramfs either via modifying usr/gen_init_cpio.c or via the new initrd format, an cpio archive.  It must be called "/init".  This binary is responsible to do all the things prepare_namespace() would do. To remain backwards compatibility, the /init binary will only run if it comes via an initramfs cpio archive.  If this is not the case, init/main.c:init() will run prepare_namespace() to mount the final root  and exec one of the predefined init binaries.

    其中,第一种方式已经用过了,比如直接在mtdblock3上挂载jffs2根文件系统。第二种方式要分为两种情况,一种是image-initrd,一种是cpio-initrd。在host上普遍采用cpio-initrd了,但是在嵌入式系统上还是采用image-initrd多。本来想探讨一下如何使用cpio-initrd,没有结果,暂时放弃。第三种方式实际上就是把fs作到kernel中,实际的映像就是kernel+fs了。不过第三种方式对小系统来说合适,一旦这个映像比较大,那么更多的时间会消耗在解压缩上,反而得不偿失了。

    下面介绍一下第三种方式。

    One method of doing this is to use the initramfs function in the kernel. The kernel expects the image to be a gzipped CPIO archive. In the kernel source there are tools to create the CPIO archive. First we must create a file list from our file system (presumedly this is just the root of your current NFS mount).

/!!Remember that you need a 'init' file in /. You can just link to /sbin/init

·进入内核源代码
$ cd /path_to_linux_source

·产生cpio的对应文件里表
# scripts/gen_initramfs_list.sh /path_to_fs_root/ > cpio_list
·Next create the CPIO archive
# usr/gen_init_cpio cpio_list > initramfs.cpio
·Gzip the CPIO archive
$ gzip initramfs.cpio
·Now copy initramfs.cpio.gz to usr/initramfs_data.cpio.gz, and run the normal kernel make. You will notice that uImage is much larger (size = kernel + fs).

    最后把uImage烧写到对应区域,引导启动即可。这时候就不需要烧写root filesystem了。

本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/21948/showart_510530.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP