How to unpack and repack an initial ramdisk (initrd/initramfs) image?

Solution Verified - Updated -

Environment

  • Red Hat Enterprise Linux 5, 6

Issue

  • How do I unpack, and then repack an initrd image in Red Hat Enterprise Linux ?
  • How do I modify the initrd image ?
  • How do I view an initrd file ?

Resolution

  • Create a directory and switch into it:
# mkdir test
# cd test
  • Then uncompress and extract the initrd:
# zcat /boot/initrd-2.6.18-164.6.1.el5.img | cpio -idmv
  • Edit the contents (if needed)
  • Finally repack and compress the initrd image:
# find . | cpio -o -c | gzip -9 > /boot/test.img
  • For image compressed with xz format, the below commands can be used to extract the initrd image.
# mkdir /tmp/initrd
# cd /tmp/initrd
# xz -dc < initrd.img | cpio --quiet -i --make-directories 
  • Edit the contents (if needed)
  • Finally repack and compress the initrd image:
# cd /tmp/initrd
# find . 2>/dev/null | cpio --quiet -c -o | xz -9 --format=lzma >"new_initrd.img"
Note: For Red Hat Enterprise Linux 7, please use How to extract the contents of initramfs image on RHEL7? for extracting the .img file.

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.

Close

Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.