I am new to this Linux Kernel and I am trying to boot a board from the usb and I was sucessfull

Now My problem is the usb has two files a) initramfs.cpio.xz b) linux.img

Now what I need to do it decompress this initramfs and add some files to this file system and then compress it back

I am facing issue while u uncompression any one who Know how to do it will be really helpfull to me



initramfs is a cpio archived file which can be optionally compressed with gzip, xz or bzip2 formats.

In your case check which kind of compression is done. The compression would mostly be gzip.

  $ file /boot/initrd.img-3.2.0-4-686-pae 
  /boot/initrd.img-3.2.0-4-686-pae: gzip compressed data, from Unix

If its a gzip compression uncompress it with gunzip utility or any other appropriate utility for the compression format. Once uncompressed use cpio utility to extract the archive.

$ cpio -id < initrd.img-3.2.0-4-686-pae 
48843 blocks

The archive will contain files and directories that will be required during the time of booting.


I faced the same issue and solve it based on How to view, change, recreate Linux initrd.img file.

First of all, since version 2.6 and above (see here) initrd image is simply initramfs (just the name has been kept). Then, kernel image is a simple gzip file containing a cpio archive (at least for debian).

File format

Verify that the image in /boot (which looks like initrd.img.other_info, for example : initrd.img-4.9.0-8-686-pae) is a gzip file

file initrd.img-4.9.0-8-686-pae
>> initrd.img-4.9.0-8-686-pae: gzip compressed data, was "newinitrd", last modified: Sat Apr 27 10:03:57 2019, from Unix

Even if the extension is gzip the file cannot be uncompressed directly because of the lack of .gz at the end of it (which here implies that we need to convert the file into a recognizable format for uncompression process)


GZIP part

The next step is to get the correct shape for the file with :

mv initrd.img-4.9.0-8-686-pae initrd.img-4.9.0-8-686-pae.gz

Notice that just renaming the file initrd.img-4.9.0-8-686-pae into initrd.img-4.9.0-8-686-pae.gz has no effect.

Then uncompressed the file with the appropriate command (here for a gzip file) :

gunzip initrd.img-4.9.0-8-686-pae.gz

CPIO part

You will obtain an cpio archive (here the file will keep the same name initrd.img-4.9.0-8-686-pae)

file initrd.img-4.9.0-8-686-pae
>> initrd.img-4.9.0-8-686-pae: ASCII cpio archive (SVR4 with no CRC)

Then to get all files into the archive use into a new folder :

cpio -id < ../initrd.img-4.9.0-8-686-pae 

That's all for the uncompression part


After editing the image you will need to compress it again. First create a cpio archive of all these file (still in the directory used to open the cpio archive)

find . | cpio --create --format='newc' > ../newInitrd

Then, compress the archive (in the parent directory) with :

gzip newInitrd

And finally :

mv newInitrd.gz newInitrd.img

(Then you just have the rename newInitrd.img into initrd.img-4.9.0-8-686-pae and put the file in /boot)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.