博客首页 注册 建议与交流 排行榜 加入友情链接
推荐 投诉 搜索: 帮助

CalmArrow

【打好基础】全力以赴,顺其自然【每天进步一点点】
  piaoxiang.cublog.cn

关于作者
姓名:CalmArrow(lqm)
职业:硕士在读
位置:山东济南
研究:嵌入式系统设计
联系:calmarrow@gmail.com

信仰:
    1、永远保持积极向上(积极的心态,积极的思考,积极的行动),享受生活给予的一切!
    2、做正确的事,正确的做事;用心去做,做到最好!
    3、如果你觉得不幸福,那么请你把幸福的门槛降低一些,不要把幸福拒之门外。。。

方向:
    在嵌入式系统设计中感兴趣的方向有:ARM、Linux、网络通信

目标:
    软硬结合,打好基础,提高学习能力,完善知识体系,建立核心优势。

方法:
    理论与实践相结合
    深度与广度相结合
    理解与记忆相结合

说明:
    本Blog仅供学习之用,转载文章如涉及版权,请通知。原创作品如转载,请注明出处。
|| << >> ||
我的分类


mount root filesystem的三种方式
 
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了。

发表于: 2008-03-28,修改于: 2008-03-28 13:34,已浏览620次,有评论0条 推荐 投诉


网友评论
 发表评论