Packing and unpacking initrd: Difference between revisions
From Leo's Notes
This page was last edited on 22 November 2021, at 19:16.
Created page with "modify <code>initird.img</code> or other similar images To extract <code>initird.img</code>: # Go to an empty directory before extracting the image. # eg: mkdir -p /mnt/ini..." |
No edit summary |
||
| (12 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
modify | == Determine initrd format == | ||
To modify {{code|initird.img}} or other similar images, first determine the compression method used by the initrd file. Below, we see that it's using gzip which is typical. | |||
{{Highlight | |||
| code = ## Using gzip | |||
# file initrd.img | |||
initramfs.gz: gzip compressed data, last modified: Thu Jul 22 04:16:52 2021, max compression, from Unix, original size 46489600 | |||
To pack files back into | ## ASCII SVR4 archive | ||
# file initramfs.img | |||
initramfs.img: ASCII cpio archive (SVR4 with no CRC) | |||
| lang = terminal | |||
}} | |||
=== Extracting initrd === | |||
==== Gzip ==== | |||
To unpack and extract {{code|initird.img}} using gzip: | |||
{{Highlight | |||
| code = ## Go to an empty directory before extracting the image. | |||
# mkdir -p /mnt/initrd_extract && cd /mnt/initrd_extract | |||
# gzip -dc < /path/to/initrd.img {{!}} cpio -i | |||
| lang = terminal | |||
}} | |||
==== ASCII cpio archive ==== | |||
To unpack initramfs using ASCII cpio archive that's generated by dracut, use skipcpio. | |||
{{Highlight | |||
| code = # /usr/lib/dracut/skipcpio initramfs.img {{!}} xz -d {{!}}cpio -id | |||
| lang = terminal | |||
}} | |||
=== Repacking initrd === | |||
To re-pack files back into {{code|initrd.img}} after making your changes: | |||
{{Highlight | |||
| code = # Go to the directory containing the contents of the image. | |||
# cd /mnt/initrd_extract | |||
# find . {{!}} cpio -o -c {{!}} gzip -9 > /path/to/initrd.img | |||
| lang = terminal | |||
}}<br /> | |||
{{Navbox Linux}} | |||
[[Category:Linux]] | |||
Latest revision as of 19:16, 22 November 2021
Determine initrd format
To modify initird.img or other similar images, first determine the compression method used by the initrd file. Below, we see that it's using gzip which is typical.
## Using gzip
# file initrd.img
initramfs.gz: gzip compressed data, last modified: Thu Jul 22 04:16:52 2021, max compression, from Unix, original size 46489600
## ASCII SVR4 archive
# file initramfs.img
initramfs.img: ASCII cpio archive (SVR4 with no CRC)
Extracting initrd
Gzip
To unpack and extract initird.img using gzip:
## Go to an empty directory before extracting the image.
# mkdir -p /mnt/initrd_extract && cd /mnt/initrd_extract
# gzip -dc < /path/to/initrd.img | cpio -i
ASCII cpio archive
To unpack initramfs using ASCII cpio archive that's generated by dracut, use skipcpio.
# /usr/lib/dracut/skipcpio initramfs.img | xz -d |cpio -id
Repacking initrd
To re-pack files back into initrd.img after making your changes:
# Go to the directory containing the contents of the image.
# cd /mnt/initrd_extract
# find . | cpio -o -c | gzip -9 > /path/to/initrd.img