二十八、用描述文件构建initramfs
用内核编译工具构建initramfs的第三种方法是使用描述文件。在内核配置参数中的initramfs sources配置项下可以输入
initramfs构建描述文件的文件名,内核编译工具根据描述文件完成initramfs的构建。
描述文件的语法格式的说明如下:
# a comment
file <name> <location> <mode> <uid> <gid>
dir <name> <mode> <uid> <gid>
nod <name> <mode> <uid> <gid> <dev_type> <maj> <min>
slink <name> <target> <mode> <uid> <gid>
pipe <name> <mode> <uid> <gid>
sock <name> <mode> <uid> <gid>
<name> name of the file/dir/nod/etc in the archive
<location> location of the file in the current filesystem
<target> link target
<mode> mode/permissions of the file
<uid> user id (0=root)
<gid> group id (0=root)
<dev_type> device type (b=block, c=character)
<maj> major number of nod
<min> minor number of nod
例子:
我们用描述文件的方式,构建第一节中的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 sources配置项可以指定多个目录或描述文件,内核会汇集这些目录或文件生成一个
initramfs。但从我的试验来看,initramfs sources只接受单一的目录名或文件名,输出多个目录名或文件名(之间用空格分隔),
内核编译时就会出错。也许是我的方法有误,还望读者指正。
---下节预告---
前面编译busybox时,都是连接到了glibc库。但是glibc库比较大,而且busybox不能静态连接(有资料讲可以通过修改busybox
源码来静态连接glibc),在initramfs容量受限或需要静态连接的情况下,使用uclibc库可能是个很好的选择。在initramfs中如
何使用uclibc库,这就需要看看下一个step:
精通initramfs构建step by step (十):uclibc