2.6以前的版本采用的是ext2格式的initrd,2.6及以后是cpio包形式,具体来看下吧
2.6及以后版本内核
解包
查看ubuntu的grub.cfg文件
红框是root文件系统,挂载在根目录。
解包initrd.img-4.4.0-62-generic
file initrd.img-4.4.0-62-generic
# initrd.img-4.4.0-62-generic: gzip compressed data, last modified: Fri May 4 13:36:01 2018, from Unix
mv initrd.img-4.4.0-62-generic initrd.img.gz
gunzip -d initrd.img.gz
# gunzip to initrd.img
file initrd.img
# initrd.img: ASCII cpio archive (SVR4 with no CRC)
mkdir initrd
cd initrd
cpio -idmv < ../initrd.img
# 解包成功,查看
ls
# bin conf etc init lib lib64 run sbin scripts usr var
重新打包生成initrd.img
find .| cpio -H newc -o | gzip -9 -n > ../initrd.new.img
注:
-H newc 是必须的。-H Use given archive FORMAT,newc The new (SVR4) portable format, which supports file systems having more than 65536 i-nodes。现在的Linux内核的initramfs/initrd默认都是使用SVR4格式
2.6之前版本
mv initrd-2.4.21.img initrd-2.4.21.img.gz
gunzip initrd-2.4.21.img
file initrd-2.4.21.img
# initrd-2.4.21.img: Linux rev 1.0 ext2 filesystem data
mount -o loop initrd-2.4.21.img /mnt/
cd /mnt
ls
# bin conf etc init lib lib64 run sbin scripts usr var
压缩到initrd.gz
umount initrd-2.4.21.img
gzip -9 -n initrd-2.4.21.img
ls
# initrd-2.4.21.img.gz
至此又生成了initrd.gz