Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Contents of initramfs
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Kernel & Hardware
View previous topic :: View next topic  
Author Message
wmakowski
n00b
n00b


Joined: 27 Jan 2006
Posts: 33
Location: Ohio, USA

PostPosted: Wed Feb 01, 2006 7:48 pm    Post subject: Contents of initramfs Reply with quote

I wanted to take a look at what is in initramfs-genkernel-x86-2.6.12-gentoo-r6 included on the LiveCD. So I unzipped it and then used cpio to extract the archive. The command used to extract was:
Code:
cpio -idv < initramfs-genkernel-x86-2.6.12-gentoo-r6

After extracting I found a basic root directory structure with only a few files.
Code:
drwxr-xr-x  11 root     root            0 Aug  9 02:18 .
drwxr-xr-x   2 root     root            0 Aug  9 02:18 sys
drwxr-xr-x   2 root     root            0 Aug  9 02:18 dev
crw-------   1 root     root       4,   1 Aug  9 02:18 dev/tty1
crw-rw----   1 root     root       5,   1 Aug  9 02:18 dev/console
crw-rw----   1 root     root       1,   3 Aug  9 02:18 dev/null
drwxr-xr-x   3 root     root            0 Aug  9 02:18 var
drwxr-xr-x   3 root     root            0 Aug  9 02:18 var/lock
drwxr-xr-x   2 root     root            0 Aug  9 02:18 var/lock/dmraid
drwxr-xr-x   4 root     root            0 Aug  9 02:18 usr
drwxr-xr-x   2 root     root            0 Aug  9 02:18 usr/bin
drwxr-xr-x   2 root     root            0 Aug  9 02:18 usr/sbin
drwxr-xr-x   2 root     root            0 Aug  9 02:18 bin
drwxr-xr-x   2 root     root            0 Aug  9 02:18 temp
drwxr-xr-x   2 root     root            0 Aug  9 02:18 sbin
drwxr-xr-x   2 root     root            0 Aug  9 02:18 etc
-rw-r--r--   1 root     root           93 Aug  9 02:18 etc/fstab
drwxr-xr-x   2 root     root            0 Aug  9 02:18 proc

The initramfs-genkernel-x86-2.6.12-gentoo-r6 file is roughly 28MB unzipped and I was expecting to find a lot more content. Does anyone see an error in how I extracted the archive?

Bill
Back to top
View user's profile Send private message
Antimatter
Guru
Guru


Joined: 11 Aug 2003
Posts: 463

PostPosted: Fri Feb 03, 2006 12:02 am    Post subject: Reply with quote

I was actually wondering the very same thing myself, i managed to get my initramfs open and got the very same results as you did, from 2 different initramfs, one was 14 MB, other was 28 MB so i have no idea what's going on here.

hey i think i've found the answer for both of our questions here Unpacking Genkernel or gentoo.igz initramfs | Strange result
Back to top
View user's profile Send private message
wmakowski
n00b
n00b


Joined: 27 Jan 2006
Posts: 33
Location: Ohio, USA

PostPosted: Fri Feb 03, 2006 12:51 am    Post subject: Reply with quote

Antimatter,

An excellent find, and it explains the layout of the archive. Thanks for sharing.

Bill
Back to top
View user's profile Send private message
widan
Veteran
Veteran


Joined: 07 Jun 2005
Posts: 1512
Location: Paris, France

PostPosted: Fri Feb 03, 2006 1:49 am    Post subject: Reply with quote

Another script to unpack an initramfs:
Code:
#!/bin/bash

if [[ $# -ne 2 ]]; then
    echo "Usage: $0 initramfs directory"
    exit 1
fi

mkdir -p "$2"

if file "$1" | grep gzip > /dev/null 2>&1; then
    echo "Initramfs is gzip compressed, unpacking first"
    cp "$1" .temp.gz
    gunzip .temp.gz
else
    cp "$1" .temp
fi

if file .temp | grep ext2 > /dev/null 2>&1; then
    echo
    echo "This is an initrd (ext2 filesystem), not an initramfs"
    echo
    echo "Those are ext2 filesystem images, that can be mounted on loopback:"
    echo
    echo "  # mount -o loop $1-unpacked $2"
    echo
    mv .temp $1-unpacked
    exit
fi

compno=1
while [[ -s .temp ]]; do
    blocks=$(cpio -t -H newc < .temp 2>&1 > /dev/null | sed "s/[^0-9]*//g")
    dd if=.temp of=.$compno.cpio bs=512 count=$blocks 2> /dev/null
    dd if=.temp of=.scratch bs=512 skip=$blocks 2> /dev/null
    mv .scratch .temp
    echo "Extracting component #$compno ($blocks blocks)"
    pushd "$2" > /dev/null 2>&1
    cpio -i -m -H newc < ../.$compno.cpio > /dev/null 2>&1
    popd > /dev/null 2>&1
    rm .$compno.cpio
    compno=$((compno+1))
done

rm .temp

And to rebuild it when you're done modifying it, you just need to do that:
Code:
# cd irfs-dir
# find . -print | cpio -o -H newc > ../initramfs
# cd ..
(if you want)
# gzip initramfs


Edit: Added detection of old-style initrd images, that don't need this script as they are just gzipped ext2 filesystems.


Last edited by widan on Tue Feb 07, 2006 11:22 pm; edited 1 time in total
Back to top
View user's profile Send private message
Antimatter
Guru
Guru


Joined: 11 Aug 2003
Posts: 463

PostPosted: Fri Feb 03, 2006 1:53 am    Post subject: Reply with quote

Thanks you! the c code that i linked to in the other thread end up not working at all, so i was about to post that it didn't work when i ran over the above script, and that script works great, so i finally can open the damn initramfs file so i can check out how its built and modify it if needed
Back to top
View user's profile Send private message
modified_bessel
Tux's lil' helper
Tux's lil' helper


Joined: 16 Jul 2004
Posts: 101
Location: Cote d'Azur, France

PostPosted: Mon Feb 06, 2006 10:31 pm    Post subject: Reply with quote

Code:
blocks=$(cpio -t -H newc < .temp 2>&1 > /dev/null | sed "s/[^0-9]*//g")



returns a null string; any ideas??

Thanks!
Back to top
View user's profile Send private message
widan
Veteran
Veteran


Joined: 07 Jun 2005
Posts: 1512
Location: Paris, France

PostPosted: Mon Feb 06, 2006 11:51 pm    Post subject: Reply with quote

What does that command return (you will need to add an exit command in the loop so you can get the .temp file) ?
Code:
cpio -t -H newc < .temp
Back to top
View user's profile Send private message
modified_bessel
Tux's lil' helper
Tux's lil' helper


Joined: 16 Jul 2004
Posts: 101
Location: Cote d'Azur, France

PostPosted: Tue Feb 07, 2006 10:11 pm    Post subject: Reply with quote

Code segment:
Code:
compno=1
while [[ -s .temp ]]; do
    test=$(cpio -t -H newc < .temp) #new
    echo "test=$test"  #new
    exit #new


Console response:

Code:
localhost testplace # ./igz-unzipper.sh gentoo.igz irfs-dir
Initramfs is gzip compressed, unpacking first
cpio: premature end of file
test=
localhost testplace # 


wherein gentoo.igz (2472813 bytes) is the initrd image from the 2005.0 CD, irfs-dir is an empty directory in the same working directory. If the initrd is uncompressed into another image file before using the script, the script detects the new file (6746112 bytes) correctly, does not try to unzip it, but gives the same result for the above code(s).

Thanks for your previous prompt reply, and excuse my tardiness!
Back to top
View user's profile Send private message
modified_bessel
Tux's lil' helper
Tux's lil' helper


Joined: 16 Jul 2004
Posts: 101
Location: Cote d'Azur, France

PostPosted: Tue Feb 07, 2006 11:14 pm    Post subject: Reply with quote

Addendum....

.... the expansion work file .temp in both cases contains 6746112 bytes, as expected, but clearly not in the required format????

Thanks!

m_b
Back to top
View user's profile Send private message
widan
Veteran
Veteran


Joined: 07 Jun 2005
Posts: 1512
Location: Paris, France

PostPosted: Tue Feb 07, 2006 11:27 pm    Post subject: Reply with quote

Some older images are really an initrd (compressed ext2 filesystems) and not an initramfs (cpio archive). These don't need this script and can be mounted as loopback filesystems after gunzipping. They can then be modified in place, there is no special procedure to rebuild them (except to remember to unmount the image, and gzip it again if you want).

The one on the 2005.0 x86 minimal LiveCD is clearly an initrd. I edited the post with the script to add a check for that kind of image.
Back to top
View user's profile Send private message
modified_bessel
Tux's lil' helper
Tux's lil' helper


Joined: 16 Jul 2004
Posts: 101
Location: Cote d'Azur, France

PostPosted: Wed Feb 08, 2006 8:35 am    Post subject: Reply with quote

Thanks for the very relevant observation; my problem has clearly been working on different CD's, all containing identical file names, but indeed different file types on each!

All the best!

m_b
Back to top
View user's profile Send private message
Skandal
n00b
n00b


Joined: 28 Aug 2004
Posts: 12

PostPosted: Wed Feb 22, 2006 4:40 pm    Post subject: Reply with quote

I'm working with the initramfs found on 2005.1-minimal-install-amd64

When I recompress the initramfs using

Code:
# cd irfs-dir
# find . -print | cpio -o -H newc > ../initramfs
# cd ..
(if you want)
# gzip initramfs


If I decompress the image using your script again the script no longer lists
several components, just one big one. The kernel panics if I use the image on my install medium.

I've been searching the internet for information about this, but haven't found any other compression method.
Back to top
View user's profile Send private message
widan
Veteran
Veteran


Joined: 07 Jun 2005
Posts: 1512
Location: Paris, France

PostPosted: Wed Feb 22, 2006 5:26 pm    Post subject: Reply with quote

Skandal wrote:
If I decompress the image using your script again the script no longer lists several components, just one big one.

This is normal. The original initramfs is a concatenation of several cpio archives. I rebuild it as only one cpio archive, but I don't think it matters for the kernel. The method given on the Linux kernel mailing list (this article, step 3) is exactly the same.
Skandal wrote:
The kernel panics if I use the image on my install medium.

What kind of error message(s) do you have (the panic itself, and also error messages that happened just before) ?
Back to top
View user's profile Send private message
Skandal
n00b
n00b


Joined: 28 Aug 2004
Posts: 12

PostPosted: Wed Feb 22, 2006 9:48 pm    Post subject: Reply with quote

The kernel wasn't able to find /init the last time

but ofcourse it was all my fault :oops:

I suspect that I must have decompressed the archives the wrong way myself the last time, and recompressed the archieve again.

Now I have a runaway loop modprobe problem instead.However, I have found a new release I didn't know about earlier, so I'm going to retry the procedure with the new release.

Thanks for your help btw=)
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Kernel & Hardware All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum