How Is Initrd.img Packed And Compressed?

Home » CentOS » How Is Initrd.img Packed And Compressed?
CentOS 4 Comments

Hi,

In order to work around a known upstream bug I needed to add a udev rule to pxeboot initrd.img on CentOS 7.

The process is straightforward:
1 – extract the pxeboot initrd.img to a new directory
2 – add the udev rule needed to fix the bug
3 – pack and compress it back in initrd.img format

The resulting updated image works, it fixes the upstream bug and life is good. But although it works, it’s not the same format as the original initrd.img that ships with the distro. I would like to know the proper incantation used to package initrd.img

Now for the specifics. The original image: http://mirror.steadfast.net/
CentOS/7.4.1708/os/x86_64/isolinux/initrd.img is extracted: /usr/lib/dracut/skipcpio initrd.img | xzcat | cpio -i -d and after adding the needed udev rule, it gets packed and compressed as follows:

find . 2>/dev/null | cpio –quiet -c -o | xz -9
–format=lzma >”~/patched-initrd.img”

Now for the difference. FIrst the original distro image:
# file initrd.img initrd.img: xz compressed data

# file patched-initrd.img patched-initrd.img: LZMA compressed data, streamed Without the –format=lzma flag it fails to boot.

Does anyone know how this is done properly ?

Thanks,
-Mike

4 thoughts on - How Is Initrd.img Packed And Compressed?

  • Mircea Husz wrote:

    Instead of re-creating a new initrd.img, why not just create an
    ‘updates’ image that contains your new udev rule and use the
    ‘inst.updates=’ pxeboot cmdline option?

    I use this to add things to the install image – no need to alter the existing initrd image – if you need more info, let me know

    James Pearson

  • I would very much like your idea to work for us. I just tried it and found that inst.updates gets loaded later in the boot process than when it’s in initrd.img, and for this particular bug that’s too late. The udev rule we’re adding deals with renaming the network interface, which happens earlier in the boot process.

    -Mike