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了。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值