initramfs的制作和使用
cd rootfs
find . | cpio -H newc -ov --owner root:root > ../initramfs
cd ..
gzip initramfs.gz
或者下面方法
cd rootfs
find . | cpio -o -H newc | gzip -3 > ../initrd.gz
或者下面写法
cat > hello.c << EOF
#include <stdio.h>
#include <unistd.h>
int main(int argc, char *argv[])
{
printf("Hello world!\n");
sleep(999999999);
}
EOF
gcc -static hello.c -o init
echo init | cpio -o -H newc | gzip > test.cpio.gz
# Testing external initramfs using the initrd loading mechanism.
qemu -kernel /boot/vmlinuz -initrd test.cpio.gz /dev/zero
解压initrd
查看文件信息
# file initrd.gz
输出信息 initrd: gzip compressed data
指gzip压缩格式
解压命令
gzip -d initrd.gz
查看文件信息
# file initrd
输出信息 initrd: ASCII cpio archive (SVR4 with no CRC)
指cpio归档格式
解开cpio归档
cpio -idmv < initrd
会在当前目录展开initrd内所有内容
参考链接:
https://blog.csdn.net/lixiangminghate/article/details/50719379
https://blog.csdn.net/lixiangminghate/article/details/55224412
https://blog.csdn.net/song_lee/article/details/106027410
https://blog.csdn.net/rikeyone/article/details/88389756
https://www.kernel.org/doc/html/latest/filesystems/ramfs-rootfs-initramfs.html