initramfs的制作和使用

本文详细介绍了如何创建和使用initramfs,包括使用cpio和gzip工具来打包根文件系统,以及如何在QEMU中测试initramfs。此外,还展示了如何创建包含简单程序的外部initramfs,并通过initrd加载机制进行测试。
摘要由CSDN通过智能技术生成

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值