Packing and unpacking initrd: Difference between revisions

From Leo's Notes
This page was last edited on 29 April 2013, at 08:09.
No edit summary
mNo edit summary
Line 2: Line 2:


To extract <code>initird.img</code>:
To extract <code>initird.img</code>:
<syntaxhighlight lang="bash" line start="1" enclose="div">
  # Go to an empty directory before extracting the image.
  # Go to an empty directory before extracting the image.
  mkdir -p /mnt/initrd_extract && cd /mnt/initrd_extract
  mkdir -p /mnt/initrd_extract && cd /mnt/initrd_extract
  gzip -dc < /path/to/initrd.img | cpio -i
  gzip -dc < /path/to/initrd.img | cpio -i
</syntaxhighlight>


To pack files back into <code>initrd.img</code>
To pack files back into <code>initrd.img</code>
<syntaxhighlight lang="bash" line start="1" enclose="div">
  # Go to the directory containing the contents of the image.
  # Go to the directory containing the contents of the image.
  cd /mnt/initrd_extract
  cd /mnt/initrd_extract
  find . | cpio -o -c | gzip -9 > /path/to/initrd.img
  find . | cpio -o -c | gzip -9 > /path/to/initrd.img
</syntaxhighlight>


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


[[Category:Linux]]
[[Category:Linux]]

Revision as of 08:09, 29 April 2013

modify initird.img or other similar images

To extract initird.img:

 # 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

To pack files back into initrd.img

 # Go to the directory containing the contents of the image.
 cd /mnt/initrd_extract
 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.