On original /boot/initrd.img-kernel_ver binwalk
shows this structure:
From 0 to 22528 bytes there is CPIO archive contains only GenuineIntel.bin firmware in specific folder hierarchy.
From 22528 bytes there is gzip archiwe contains appropriate file system and this gzip is also archived with CPIO
After unpacking and modifying how can I compress initrd.img in the same way (with the same folder hierarchy) ? like this original structure:
After suggestion from comment :
find . | cpio --quiet --dereference -o -H newc | lzma -7 > ../cusotm.initrd.lz
binwalk
:
This is completly different structure.
I figured it out how to make exactly the same
initrd.img
archive.Bodhi.zazen answer will probably work because this is commonly known solution:
but the question was different. This answer would be good if in cpio archive there is one gzipped file system but in this situation there is also Intel firmware in specific folder structure which I want to keep.
To keep the same folder hierarchy three steps are needed:
You repackage with
The second command renames the initrd, you specifiy the initrd to use when booting in grub.
I suggest you test (boot)the custom initrd before moving or renaming it.
Additional information from the discussion in the comments:
First I do not think you are understanding the role of cpio / tar. both cpio and tar take a number of files and/or directories and make them into one file or archive.
Second I do not think you understand the role of compression, compression simply makes the resulting archive smaller. You can use any tool you wish for compression.
See
https://wiki.ubuntu.com/CustomizeLiveInitrd
https://wiki.gentoo.org/wiki/Initramfs/Guide
Third, the linux kernel uses cipo rather then tar.
See
https://www.kernel.org/doc/Documentation/filesystems/ramfs-rootfs-initramfs.txt
See the "Why cpio rather than tar?" section
I recently ran into this same question and my web searching led me to this thread, so in case it helps others following in those footsteps, here's a 2018 answer to an old question...
It seems in "recent" kernels the initrd.img file can contain an uncompressed cpio archive (i.e. containing microcode updates) prepended to the (compressed) cpio archive containing the normal initramfs directory tree.
This is discussed briefly in the Debian Wiki page:
https://wiki.debian.org/initramfs#How_to_inspect_initramfs
, but more precise code for parsing through this sort of initrd.img file can be found in the
splitinitramfs()
function within theunmkinitramfs
command found in theinitramfs-tools-core
package (e.g. https://git.launchpad.net/ubuntu/+source/initramfs-tools/tree/unmkinitramfs ).I have not tried to rebuild this sort of initrd.img file myself, but based on that Wiki page it seems that to edit the initramfs boot scripts, one would not want to unpack the GenuineIntel archive at all. Instead, you could just preserve that cpio archive as-is somewhere separately, then unpack the second (compressed) archive, modify the directory tree, and rebuild the compressed cpio archive, then concatenate the saved microcode archive with the newly-generated one.
(The code that originally generated this "prepended" archive is found in
/usr/share/initramfs-tools/hooks/intel_microcode
.)in Ubuntu the
initrd.img
is compressed in gzip, I would like to preserve this when I edit it. this is how:extract:
compress: