ITEEDU

用描述文件构建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的完全相同。