How to unpack and repack an initial ramdisk (initrd/initramfs) image?
Environment
- Red Hat Enterprise Linux 5, 6
Issue
- How do I unpack, and then repack an
initrd imagein Red Hat Enterprise Linux ? - How do I modify the
initrd image? - How do I view an
initrdfile ?
Resolution
- Create a directory and switch into it:
# mkdir test
# cd test
- Then
uncompress and extractthe initrd:
# zcat /boot/initrd-2.6.18-164.6.1.el5.img | cpio -idmv
- Edit the contents (if needed)
- Finally
repack and compresstheinitrdimage:
# find . | cpio -o -c | gzip -9 > /boot/test.img
- For image compressed with
xzformat, the below commands can be used to extract theinitrdimage.
# mkdir /tmp/initrd
# cd /tmp/initrd
# xz -dc < initrd.img | cpio --quiet -i --make-directories
- Edit the contents (if needed)
- Finally
repack and compresstheinitrdimage:
# 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.
Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.
