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
    1
    2
    
    ~ $ mv initrd initrd.gz
    ~ $ gunzip initrd.gz
  2. Extract the contents of the cpio image
    1
    2
    
    ~ $ mkdir extracted && cd extracted
    ~/extracted $ cpio -id < ../initrd

(Re-)build an initial ramdisk

  1. Create the cpio image
    1
    
    ~/extracted $ find . | cpio -H newc -o > ../initrd.new.cpio
  2. Compress (i.e. gzip) the image
    1
    2
    3
    
    ~/extracted $ cd ..
    ~ $ gzip initrd.new.cpio
    ~ $ mv initrd.new.cpio.gz /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.

Note:
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!