Modify an initial ramdisk (initrd)

Hi out there!

Because modifying an initial ramdisk is something I had to do every once a while and I am pretty oblivious when it comes to “exotic” commands, I will persist the knowledge at this point.

First of all, modern linux kernels (like everything above 2.6 or so) use an initrd that is a gzipped cpio-image (use file to be sure).

Extract an initial ramdisk

  1. Extract (i.e. gunzip) the gzipped image
    ~ $ mv initrd initrd.gz
    ~ $ gunzip initrd.gz
  2. Extract the contents of the cpio image
    ~ $ mkdir extracted && cd extracted
    ~/extracted $ cpio -id < ../initrd

(Re-)build an initial ramdisk

  1. Create the cpio image
    ~/extracted $ find . | cpio -H newc -o > ../
  2. Compress (i.e. gzip) the image
    ~/extracted $ cd ..
    ~ $ gzip
    ~ $ mv /boot/initrd-2.6.22-some-kernel

It might be possible to simplify some steps of this howto, but I tend to clarify things to avoid confusion.

I stumbled over the newc format of cpio. Actually, I think that there's not pretty much of a choice here.
The documentation doesn't say much about that, just use it.

Have fun, take care!