从22528字节开始,存在一个gzip存档,其中包含适当的文件系统,并且该gzip也被CPIO归档。
解压并修改后,我如何以相同的方式(具有相同的文件夹层次结构)压缩initrd.img?就像这个原始结构一样:
根据评论的建议:find . | cpio --quiet --dereference -o -H newc | lzma -7 > ../cusotm.initrd.lz
binwalk
:
解压并修改后,我如何以相同的方式(具有相同的文件夹层次结构)压缩initrd.img?就像这个原始结构一样:
根据评论的建议:find . | cpio --quiet --dereference -o -H newc | lzma -7 > ../cusotm.initrd.lz
binwalk
:
initrd.img
归档文件。find . | cpio --quiet --dereference -o -H newc | lzma -7 > ../cusotm.initrd.lz
但是问题不同。如果在cpio存档中只有一个gzipped文件系统,这个答案是好的,但在这种情况下,还有特定的文件夹结构中的Intel固件我想保留。
使用简单的-o选项创建CPIO文件系统存档,而不使用新的格式,例如在之前创建的基本文件夹中:
find . | cpio -o | gzip -9 > ../base/file_system.gz
使用新的格式创建包含kernel/x86/microcode/GenuineIntel.bin的正确存档:
find kernel/ | cpio -o -H newc > new_initrd.img
将gzipped文件系统存档添加到正确的new_initrd.img中:
find base/ | cpio -o >> new_initrd.img
find . | cpio -o | gzip -9 >> new_initrd.img
时,在binwalk中得到了完全相同的结构。 - rthcpio -id < initrd.img-kernel_ver
;dd if=initrd.img-4.4.0-22-generic of=image.gz bs=22528 skip=1
- 根据你的initrd.img文件名和块大小进行匹配;gunzip image.gz
;cpio -i < image
。 - EdiD最近我遇到了同样的问题,我的网络搜索导致我进入了这个帖子,所以为了帮助其他人,以下是一个回答关于旧问题的2018年答案...
在“最近”的内核中,initrd.img文件可以包含一个未压缩的cpio存档(即包含微码更新),该存档被附加到包含正常initramfs目录树的(已压缩的)cpio存档之前。
这在Debian Wiki页面中简要讨论:
https://wiki.debian.org/initramfs#How_to_inspect_initramfs
,但对于解析这种initrd.img文件的更精确代码可以在initramfs-tools-core
软件包中的unmkinitramfs
命令中找到(例如:
https://git.launchpad.net/ubuntu/+source/initramfs-tools/tree/unmkinitramfs
)。
cd your_working_directory_with_modifications
find . | cpio --quiet --dereference -o -H newc | lzma -7 > ../cusotm.initrd.lz
https://wiki.ubuntu.com/CustomizeLiveInitrd
https://wiki.gentoo.org/wiki/Initramfs/Guide
第三,Linux内核使用cpio而不是tar。https://www.kernel.org/doc/Documentation/filesystems/ramfs-rootfs-initramfs.txt
请查看“为什么选择cpio而不是tar?”部分。Why cpio rather than tar?
This decision was made back in December, 2001. The discussion started here:
http://www.uwsg.iu.edu/hypermail/linux/kernel/0112.2/1538.html
And spawned a second thread (specifically on tar vs cpio), starting here:
http://www.uwsg.iu.edu/hypermail/linux/kernel/0112.2/1587.html
The quick and dirty summary version (which is no substitute for reading the above threads) is:
1) cpio is a standard. It's decades old (from the AT&T days), and already widely used on Linux (inside RPM, Red Hat's device driver disks). Here's a Linux Journal article about it from 1996:
http://www.linuxjournal.com/article/1213
It's not as popular as tar because the traditional cpio command line tools require _truly_hideous_ command line arguments. But that says nothing either way about the archive format, and there are alternative tools, such as:
http://freecode.com/projects/afio
2) The cpio archive format chosen by the kernel is simpler and cleaner (and thus easier to create and parse) than any of the (literally dozens of) various tar archive formats. The complete initramfs archive format is explained in buffer-format.txt, created in usr/gen_init_cpio.c, and extracted in init/initramfs.c. All three together come to less than 26k total of human-readable text.
3) The GNU project standardizing on tar is approximately as relevant as Windows standardizing on zip. Linux is not part of either, and is free to make its own technical decisions.
4) Since this is a kernel internal format, it could easily have been
something brand new. The kernel provides its own tools to create and extract this format anyway. Using an existing standard was preferable, but not essential.5) Al Viro made the decision (quote: "tar is ugly as hell and not going to be supported on the kernel side"):
http://www.uwsg.iu.edu/hypermail/linux/kernel/0112.2/1540.html
explained his reasoning:
http://www.uwsg.iu.edu/hypermail/linux/kernel/0112.2/1550.html http://www.uwsg.iu.edu/hypermail/linux/kernel/0112.2/1638.html
and, most importantly, designed and implemented the initramfs code.
cp old_img old_img.bak
创建新的图像find . | cpio --quiet --dereference -o -H newc | lzma -7 > 任意名称的新图像
- Pantherinitrd.img
被压缩为gzip格式,当我编辑它时,我希望保留这个特性。以下是具体操作步骤:zcat /boot/initrd.img-3.19.0-80-generic | cpio --extract
find . 2>/dev/null | cpio --quiet --dereference -o -H newc | gzip -9 > /boot/initrd.img-3.19.0-80-generic
find . | cpio --quiet --dereference -o -H newc | lzma -7 > ../cusotm.initrd.lz
如果这个过程不起作用,请说明你运行了哪些命令以及出现了什么问题。 - Panther