modify initird.img or other similar images

To extract initird.img:

1  # Go to an empty directory before extracting the image.
2  mkdir -p /mnt/initrd_extract && cd /mnt/initrd_extract
3  gzip -dc < /path/to/initrd.img | cpio -i

To pack files back into initrd.img

1  # Go to the directory containing the contents of the image.
2  cd /mnt/initrd_extract
3  find . | cpio -o -c | gzip -9 > /path/to/initrd.img

You may want to run file /path/to/initrd.img in order to determine the exact method of compression. The above commands above assumes cpio + gzip.