Homepage: webng.com/linuxhelp


 What exactly is in the CPIO 
Archive; gentoo.igz


The Gentoo installation disk's initrd file is gentoo.igz. It is a gzipped cpio archive. As such, the command

cat gentoo.igz | gunzip | cpio -vt

should list the entire archives contents. However, it only lists the following directories and block devices:

.
etc
etc/fstab
bin
sys
var
var/lock
var/lock/dmraid
usr
usr/bin
usr/sbin
dev
dev/null
dev/tty1
dev/console
temp
proc
sbin


Not much for a 22MB file (when uncompressed). The 2006 version is down to 10MB.

Being an initrd file we know that it must contain the modules loaded at boot. Watching the kernel messages we also observe that these modules are actually loaded. So they are there, but hidden.

With Gentoo "accidentally" hiding the contents of gentoo.igz, it became a challenge to find out exactly what was in it.

For the 2005 versions of gentoo.igz, the contents can be listed by entering the following command (in red).

cat gentoo.igz | gunzip | awk --re-interval 'BEGIN{RS="07070"}{print gensub(/^.{105}([[:print:]]*).*$/,"\\1",1)}'

The list of contents of the 2005.1 version of gentoo.igz (provided by the above command) can be found in the old version of this page (a detailed listing is here). If you have a look at the list you will notice the expected files, but also many TRAILER!!! entries. The reason why the cpio utility lists so few files (when there are actually so many) is that a TRAILER!!! entry tells cpio that the end of the archive has been reached and the program stops looking for more.

In Gentoo 2006, it has been arranged that the above command no longer works properly.

The listing of the files content, was only a first attempt at cracking gentoo.igz. It had occurred to me that a similar idea could be used to fix the file. Then the cpio utility could list, extract or add to the fixed archive. A bit of playing around produced a short script that did the job. Since it was not made public, it still works for the 2006 version of the file.

This is the script:

#!/bin/bash
awk '
BEGIN{RS="07070"}
{
if(/TRAILER\!\!\!/){y=""}else{y=RT}
if(RT!=""){x=x gensub(/^.*TRAILER\!\!\!.*$/,"",1) y}else{x=x $0}
}
END{print x}' $1

I called it fixcpio. If you wish to try it out, copy and paste it to a file called fixcpio. Make the file executable by:

 chmod +x fixcpio

Now use it to fix gentoo.igz:

 cat gentoo.igz | gunzip | ./fixcpio > gentoo-fixed

To list the contents of gentoo-fixed (i.e., gentoo.igz) use the command:

 cpio -vt < gentoo-fixed

To extract files from gentoo-fixed (i.e., gentoo.igz) use a command like:

 cpio -vid init etc/initrd.scripts etc/initrd.defaults < gentoo-fixed

This will extract the 3 files init, etc/initrd.scripts and etc/initrd.defaults from the archive (the last 2 will be found in the directory etc, which will be created in the current directory).

If you wish to all the files of the archive, just use:

 cpio -vid < gentoo-fixed

If you are interested in a list of the contents of the 2006 version of gentoo.igz, click here.



y>