学习啦>学习电脑>操作系统>Linux教程>

如何将initramfs打包进内核

时间: 若木635 分享

  将initramfs打包进内核

  如果我们有一个已经做好的cpio格式的initramfs,可以在内核编译时直接编译进内核。

  在将init程序打包进内核中,我们在内核配置参数中的initramfs sources配置项下输入构建initramfs的目录路径。

  其实我们也可以直接输出现成的initramfs的文件名,这样在内核编译时,就可以把它编译进内核了。

  使用这种方法,有两点需要注意:

  (1)cpio文件不能压缩。一般作为initrd的cpio文件都经过了压缩,所以编译前需要先把压缩过的文件解压。

  (2)cpio文件的后缀名必须是 .cpio。内核编译通过 .cpio的后缀名来识别此文件是cpio打包文件,而其他文件后缀名则会被认为是initramfs构建的描述文件(关于描述文件,下面后详细说明)。

  用描述文件构建initramfs

  用内核编译工具构建initramfs的第三种方法是使用描述文件。

  在内核配置参数中的initramfs sources配置项下可以输入initramfs构建描述文件的文件名,内核编译工具根据描述文件完成initramfs的构建。

  描述文件的语法格式的说明如下:

  # a comment

  file

  dir

  nod

  slink

  pipe

  sock

  name of the file/dir/nod/etc in the archive

  location of the file in the current filesystem

  link target

  mode/permissions of the file

  user id (0=root)

  group id (0=root)

  device type (b=block, c=character)

  major number of nod

  minor number of nod

  例子: 我们用描述文件的方式,构建将init程序打包进内核中的hello world的initramfs。

  hello-init.desp:

  dir /dev 0755 0 0

  nod /dev/console 0600 0 0 c 5 1

  file /init /home/wyk/initramfs-test/hello_static 0755 0 0

  在内核配置项initramfs sources中指定描述文件hello-init.desp,编译内核时就会生成hello world的initramfs,运行效果与第一节用指定构建目录的方法构建的initramfs的完全相同。

如何将initramfs打包进内核

将initramfs打包进内核 如果我们有一个已经做好的cpio格式的initramfs,可以在内核编译时直接编译进内核。 在将init程序打包进内核中,我们在内核配置参数中的initramfs sources配置项下输入构建initramfs的目录路径。 其实我们也可以直
推荐度:
点击下载文档文档为doc格式
75407