Viewing the contents of an initrd image

I was doing some research tonight, and needed to look inside my initrd image to see if a couple of device drivers were present. Initrd images are stored as compressed cpio archives, which allows a pipeline like the following to be used to extract the contents of an image:

$ gunzip < initrd-2.6.29.4-167.fc11.x86_64.img | cpio -i --make-directories
14050 blocks

Once extracted, you can use cd and cat to view the files and directories that are part of the image:

$ ls -l

drwxrwxrwt. 11 root root    4096 2009-07-14 23:30 .
drwxr-xr-x. 23 root root    4096 2009-07-07 14:55 ..
drwx------   2 root root    4096 2009-07-14 23:30 bin
drwx------   3 root root    4096 2009-07-14 23:30 dev
drwx------   4 root root    4096 2009-07-14 23:30 etc
-rwx------   1 root root    1938 2009-07-14 23:30 init
-rw-------   1 root root 3428816 2009-07-14 23:29 initrd-2.6.29.4-167.fc11.x86_64.img
drwx------   6 root root    4096 2009-07-14 23:30 lib
drwx------   2 root root    4096 2009-07-14 23:30 lib64
drwx------   2 root root    4096 2009-07-14 23:30 proc
lrwxrwxrwx   1 root root       3 2009-07-14 23:30 sbin -> bin
drwx------   2 root root    4096 2009-07-14 23:30 sys
drwx------   2 root root    4096 2009-07-14 23:30 sysroot
drwx------   4 root root    4096 2009-07-14 23:30 usr

$ ls -l etc

total 20
-rw-r--r-- 1 root root   29 2009-07-14 23:30 fedora-release
-rw-r--r-- 1 root root 1976 2009-07-14 23:30 ld.so.cache
-rw-r--r-- 1 root root   28 2009-07-14 23:30 ld.so.conf
drwx------ 2 root root 4096 2009-07-14 23:30 ld.so.conf.d
drwx------ 2 root root 4096 2009-07-14 23:30 sysconfig
lrwxrwxrwx 1 root root   14 2009-07-14 23:30 system-release -> fedora-release

1 thought on “Viewing the contents of an initrd image”

  1. Howdy,

    Another hot tip is that FreeBSD’s tar(1) aka ‘bsdtar’ car extract and view cpio files e.g

    #tar -tvf /var/tmp/initrd-2.6.23.12-52.fc7.img | head -5
    -rwx—— 1 0 0 2418 Jan 30 2008 init
    drwx—— 3 0 0 0 Jan 30 2008 etc
    -rw-r–r– 1 0 0 28 Jul 8 2007 etc/ld.so.conf
    drwx—— 2 0 0 0 Jan 30 2008 etc/ld.so.conf.d
    -rw-r–r– 1 0 0 73 Apr 26 2007 etc/ld.so.conf.d/opensync-32.conf

    – Alex

Leave a Reply

Your email address will not be published. Required fields are marked *