使用initramfs最简单的方式,莫过于用已经做好的cpio.gz把kernel里面那个空的给换掉。这是2.6 kernel天生支持的,所以,你不用做什么特殊的设置。

kernel的config option里面有一项CONFIG_INITRAMFS_SOURCE(I.E. General setup—>Initramfs source file(s) in menuconfig)。这个选项指向放着内核打包initramfs需要的所有文件。默认情况下,这个选项是留空的,所以内核编译出来之后initramfs也就是空的,也就是前面提到的rootfs什么都不做的情形。

CONFIG_INITRAMFS_SOURCE 可以是一个绝对路径,也可以是一个从kernel’s top build dir(你敲入build或者是make的地方)开始的相对路径。而指向的目标可以有以下三种:一个已经做好的cpio.gz,或者一个已经为制作cpio.gz准备好所有内容的文件夹,或者是一个text的配置文件。第三种方式是最灵活的,我们先依次来介绍这三种方法。

1)使用一个已经做好的cpio.gz档案

If you already have your own initramfs_data.cpio.gz file (because you created it yourself, or saved the cpio.gz file produced by a previous kernel build), you can point CONFIG_INITRAMFS_SOURCE at it and the kernel build will autodetect the file type and link it into the resulting kernel image.

You can also leave CONFIG_INITRAMFS_SOURCE empty, and instead copy your cpio.gz file to usr/initramfs_data.cpio.gz in your kernel’s build directory. The kernel’s makefile won’t generate a new archive if it doesn’t need to.

Either way, if you build a kernel like this you can boot it without supplying an external initrd image, and it’ll still finish its boot by running your init program out of rootfs. This is packaging method #2, if you’d like to try it now.

2)指定给内核一个文件或者文件夹

If CONFIG_INITRAMFS_SOURCE points to a directory, the kernel will archive it up for you. This is a very easy way to create an initramfs archive, and is method #3.

Interestingly, the kernel build doesn’t use the standard cpio command to create initramfs archives. You don’t even need to have any cpio tools installed on your build system. Instead the kernel build (in usr/Makefile) generates a text file describing the directory with the script “gen_initramfs_list.sh”, and then feeds that descript to a program called “gen_init_cpio” (built from C source in the kernel’s usr directory), which create the cpio archive. This looks something like the following:

scripts/gen_initramfs_list.sh $CONFIG_INITRAMFS_SOURCE > usr/initramfs_list

usr/gen_init_cpio usr/initramfs_list > usr/initramfs_data.cpio

gzip usr/initramfs_data.cpio

To package up our hello world program, you could simply copy it into its own directory, name it “init”, point CONFIG_INITRAMFS_SOURCE at that directory, and rebuild the kernel. The resulting kernel should end its boot by printing “hello world”. And if you need to tweak the contents of that directory, rebuilding the kernel will re-package the contents of that directory if anything has changed.

The downside of this method is that it if your initramfs has device nodes, or cares about file ownership and permissions, you need to be able to create those things in a directory for it to copy. This is hard to do if you haven’t got root access, or are using a cross-compile environment like cygwin. That’s where the fourth and final method comes in.

3)使用configuration文件initramfs_list来告诉内核initramfs在哪里

This is the most flexible method. The kernel’s gen_initramfs_list.sh script creates a text description file listing the contents of initramfs, and gen_init_cpio uses this file to produce an archive. This file is a standard text file, easily editable, containing one line per file. Each line starts with a keyword indicating what type of entry it describes.

The config file to create our “hello world” initramfs only needs a single line:

file /init usr/hello 500 0 0

This takes the file “hello” and packages it so it shows up as /init in rootfs, with permissions 500, with uid and gid 0. It expects to find the source file “hello” in a “usr” subdirectory under the kernel’s build directory. (If you’re building the kernel in a different directory than the source directory, this path would be relative to the build directory, not the source directory.)

To try it yourself, copy “hello” into usr in the kernel’s build directory, copy the above configuration line to its own file, use “make menuconfig” to point CONFIG_INITRAMFS_SOURCE to that file, run the kernel build, and test boot the new kernel. Alternately, you can put the “hello” file in its own directory and use “scripts/gen_initramfs_list.sh dirname” to create a configuration file (where dirname is the path to your directory, from the kernel’s build directory). For large projects, you may want to generate a starting configuration with the script, and then customize it with any text editor.

This configuration file can also specify device nodes (with the “nod” keyword), directories (“dir”), symbolic links (“slink”), named FIFO pipes (“pipe”), and unix domain sockets (“sock”). Full documentation on this file’s format is available by running “usr/gen_init_cpio” (with no arguments) after a kernel build.

A more complicated example containing device nodes and symlinks could look like this:

dir /dev 755 0 0

nod /dev/console 644 0 0 c 5 1

nod /dev/loop0 644 0 0 b 7 0

dir /bin 755 1000 1000

slink /bin/sh busybox 777 0 0

file /bin/busybox initramfs/busybox 755 0 0

dir /proc 755 0 0

dir /sys 755 0 0

dir /mnt 755 0 0

file /init initramfs/init.sh 755 0 0

One significant advantage of the configuration file method is that any regular user can create one, specifying ownership and permissions and the creation of device nodes in initramfs, without any special permissions on the build system. Creating a cpio archive using the cpio command line tool, or pointing the kernel build at a directory, requires a directory that contains everything initramfs will contain. The configuration file method merely requires a few source files to get data from, and a description file.

This also comes in handy cross-compiling from other environments such as cygwin, where the local filesystem may not even be capable of reproducing everything initramfs should have in it.

stm32可以移植linux系统吗,如何在STM32上移植Linux?超详细的实操经验分享相关推荐

  1. stm32移植paho_如何在STM32上移植Linux?超详细的实操经验分享

    原标题:如何在STM32上移植Linux?超详细的实操经验分享 刚从硬件跳槽为嵌软时,没有任何一丝的准备.一入职,领导就交代了一项特难的任务--在stm32上移植linux! 瞬间我就懵了,没办法硬着 ...

  2. 对接第三方系统实操经验分享

    对接第三方系统实操经验分享 前言 为使得指示性更强,有以下名词说明 A系统:是指要发起对接的我方系统,可以理解成 Client B系统:是要对接的第三方系统,可以理解成 Server 对接第三方的特殊 ...

  3. Linux 系统基础 — 用户和组(吐血总结,超详细,看这一篇就够了!dog)

    Linux 用户和组 Linux中用户和组的相关文件 /etc/passwd /etc/shadow /etc/group Linux用户 Linux中的组 用户操作 useradd的更多使用方式 p ...

  4. 如何在GitHub上克隆项目(超详细的图文并解)

    首先了解一下什么是GitHub 官方定义GitHub为是一个面向开源及私有软件项目的托管平台,因为只支持Git作为唯一的版本库格式进行托管,故名GitHub.很多小伙伴在学习的过程中可以在此平台找到很 ...

  5. 嵌入式Linux内核和文件系统,在IXP435上移植嵌入式Linux内核和根文件系统

    简要介绍如何在IXP435上移植嵌入式Linux内核和根文件系统 1.安装交叉编译工具 为什么要先安装交叉编译工具?由于我们的Linux操作系统是安装在嵌入式处理器平台上的,需要在主机上编译出开发板需 ...

  6. linux卸载kodi,如何在Ubuntu上安装Kodi 18 Beta

    Kodi的Beta版周期很长.很棒,因为它有助于将错误排除在生产版本之外,而且还可以保留数月的新功能.值得庆幸的是,Kodi开发人员提供了可供测试和使用的"unstable"软件包 ...

  7. Linux系统没有home分区,我的linux系统home分区挂不上了

    我的linux系统home分区挂不上了 (2011-08-29 05:26:55) 标签: 杂谈 我的linux系统home分区挂不上了我的linux系统是redhat 8,home分区挂不上了,当我 ...

  8. linux的增强文件夹,在linux系统中安装virtualbox增强功能(增强包)的详细步骤是什么...

    在linux系统中安装virtualbox增强功能(增强包)的详细步骤是什么 1. 点击菜单栏 设备 –> 分配光驱 –> 选择一个虚拟光盘,找到VirtualBox安装目录下的`VBox ...

  9. Linux系统详解 第五篇:Linux的安装-4:Fedora 16的安装

    Linux系统详解 第五篇:Linux的安装-4:Fedora 16的安装 前言: 本系列文章取材广泛,有来自于互联网的,有来自教科书的,有来自自己的笔记的,也有来自自己对Linux的经验积累的.此系 ...

最新文章

  1. java触发_怎么样让JAVA 设置一秒钟触发一个事件
  2. 谈谈我们在用的Scrum看板工具!
  3. python进程、线程的学习心得
  4. 图像轮廓提取关键函数
  5. Web MVC Rest 处理流程分析
  6. 基于springboot2.x集成缓存注解及设置过期时间
  7. 安装ORACLE 11。2.0.3 配置GRID执行脚本信息记录
  8. nullnull使用PL/SQL获取创建用户的语句
  9. 万万没想到,JVM内存结构的面试题可以问的这么难?
  10. 【腾讯出品】2019互联网行业趋势报告
  11. 玩转 SpringBoot 2 之整合 JWT 上篇
  12. Q129:PBRT-V3,均匀介质的采样(15.2.1章节)
  13. Matlab基于主分量的人脸重建显示
  14. matlab画线段加箭头
  15. 搜索引擎优化SEO专业术语总结(新手篇)
  16. (转)sqlserver 数据恢复方法
  17. 使用Jekyll搭建免费的个人博客详细教程
  18. php 无限子站cms,PHP整理CMS无限层级目录(毗邻目录模式)
  19. Excel打开csv文件乱码问题的解决办法
  20. 田野调查手记·浮山篇(六)

热门文章

  1. java8 stringbuilder_有了Java8的“+”真的可以不要StringBuilder了吗
  2. java获取作用域的值_Java-springMVC框架:springMVC取参数值、把值放入作用域方法
  3. linux 行尾加字符串,linux – cat in expect脚本在字符串结尾添加新行
  4. 数据库系统工程师5天修炼_程序员逆袭之路,5年IT人生从电脑装机到技术大神,人生不认输...
  5. python编写赛车_python udp 协议发送接收秒速赛车平台搭建数据
  6. 远程协助计算机是灰色的,服务器远程协助是灰色的
  7. python安装pyqt5 qml_用 PyQt5 和 QML 做了个小工具,,感觉 PyQt 和 QML 的交互比较繁琐...
  8. java vm art_Android虚拟机art流程:JavaVM 和 JNIEnv 的初始化 - 神农笔记
  9. html中如何多列布局,CSS3 多列布局
  10. php安装文件怎么打开文件_我的php文件怎么打开_如何打开php文件的办法