How to edit initrd image

· by Artem Sidorenko · Read in about 1 min · (185 words)

It usefull sometimes to edit the initrd/initramfs image of the system. This howto describes the simple and usual way to do it.

Hint: Mainstream distributions have own mechanisms to do this things. Take a look at mkinitramfs/mkinitrd. In such case your customized image can be overwritten by this tools, so try to do in on the right way;)

  • Copy to the temporary folder
cd /tmp
mkdir initrd
cd initrd
cp /boot/initrd* .
  • Detect the type of image
gunzip -c -S "" initrd* > decompressed-initrd
file decompressed-initrd

If you get something like “ASCII cpio archive (SVR4 with no CRC)” process with working with CPIO archive, if you get something like “Linux rev 1.0 ext2 filesystem data” process with working with ext2 image

  • working with CPIO archive
    • unpacking
rm decompressed-initrd
cat initrd* | gzip -d | cpio -i
rm initrd*


rm initrd*
cat decompressed-initrd | cpio -i
rm decompressed-initrd
  • packing
find | cpio -H newc -o | gzip > ../newinitrd
  • working with ext2 image
    • mounting
rm initrd*
mkdir mnt
mount -o loop decompressed-initrd mnt
  • unmounting&packing
umount mnt
rm -rf mnt
cat decompressed-initrd | gzip > ../newinitrd