Home > Gnu/Linux > Remastering Ubuntu CD : Exploring initrd.gz

Remastering Ubuntu CD : Exploring initrd.gz

April 30th, 2009

( This document was written in connection with  Ubuntu Re mastering workshop held at College of Engineering Attingal on 25th of April 2009 . See this post )

On an Ubuntu CD kernel and the associated initrd.gz are found under casper directory.  initrd.gz is an  initial ram image  which helps the kernel to boot the system and mount the squashfs image.
You can  tweak  initrd.gz   with  the   following steps.

Mount the ubuntu cdrom/ iso image

# mount -o loop ubuntu.iso /cdrom

Create a temporary  directory and change to it.

# mkdir  initrd_remaster

# cd initrd_remaster

2) Copy initrd.gz    and unzip it

# cp /cdrom/casper/initrd.gz   .

Unzip it

# gunzip initrd.gz
The resulting file is a cpio archive
Uncompressed it  with the following command
# cpio -i  < initrd

You will get several folders  and a file named init  after this.

bin  conf  etc  init  lib  sbin  scripts  usr  var

If you watch system start up carefully,  you can  see   initrd.gz getting uncompressed.  The system starts executing the script named init immediately after that.  This script will in turn  find out  the actual root   file system (/) a, mount it and then chroot to  the actual file system. You can open up init in an editor and tweak it.     There are several  other scripts which are  called from init.

Finally, you can use cpio and gzip to recreate initrd.gz

# find ./ | cpio -H newc -o > ../initrd

# cd ..

# gunzip intrd.gz

You can replace the original initrd.gz in Casper directory with the modified initrd image

Categories: Gnu/Linux Tags:
Comments are closed.