Forums

Skip to content

Advanced search
  • Quick links
    • Unanswered topics
    • Active topics
    • Search
  • FAQ
  • Login
  • Register
  • Board index Assistance Kernel & Hardware
  • Search

Contents of initramfs

Kernel not recognizing your hardware? Problems with power management or PCMCIA? What hardware is compatible with Gentoo? See here. (Only for kernels supported by Gentoo.)
Post Reply
Advanced search
14 posts • Page 1 of 1
Author
Message
wmakowski
n00b
n00b
User avatar
Posts: 33
Joined: Fri Jan 27, 2006 3:22 pm
Location: Ohio, USA

Contents of initramfs

  • Quote

Post by wmakowski » Wed Feb 01, 2006 7:48 pm

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: Select all

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: Select all

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
Top
Antimatter
Guru
Guru
Posts: 463
Joined: Mon Aug 11, 2003 5:45 am

  • Quote

Post by Antimatter » Fri Feb 03, 2006 12:02 am

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
Top
wmakowski
n00b
n00b
User avatar
Posts: 33
Joined: Fri Jan 27, 2006 3:22 pm
Location: Ohio, USA

  • Quote

Post by wmakowski » Fri Feb 03, 2006 12:51 am

Antimatter,

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

Bill
Top
widan
Veteran
Veteran
User avatar
Posts: 1512
Joined: Tue Jun 07, 2005 4:26 pm
Location: Paris, France

  • Quote

Post by widan » Fri Feb 03, 2006 1:49 am

Another script to unpack an initramfs:

Code: Select all

#!/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: Select all

# 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.
Top
Antimatter
Guru
Guru
Posts: 463
Joined: Mon Aug 11, 2003 5:45 am

  • Quote

Post by Antimatter » Fri Feb 03, 2006 1:53 am

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
Top
modified_bessel
Tux's lil' helper
Tux's lil' helper
Posts: 101
Joined: Fri Jul 16, 2004 9:08 am
Location: Cote d'Azur, France

  • Quote

Post by modified_bessel » Mon Feb 06, 2006 10:31 pm

Code: Select all

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

returns a null string; any ideas??

Thanks!
Top
widan
Veteran
Veteran
User avatar
Posts: 1512
Joined: Tue Jun 07, 2005 4:26 pm
Location: Paris, France

  • Quote

Post by widan » Mon Feb 06, 2006 11:51 pm

What does that command return (you will need to add an exit command in the loop so you can get the .temp file) ?

Code: Select all

cpio -t -H newc < .temp
Top
modified_bessel
Tux's lil' helper
Tux's lil' helper
Posts: 101
Joined: Fri Jul 16, 2004 9:08 am
Location: Cote d'Azur, France

  • Quote

Post by modified_bessel » Tue Feb 07, 2006 10:11 pm

Code segment:

Code: Select all

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

Code: Select all

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!
Top
modified_bessel
Tux's lil' helper
Tux's lil' helper
Posts: 101
Joined: Fri Jul 16, 2004 9:08 am
Location: Cote d'Azur, France

  • Quote

Post by modified_bessel » Tue Feb 07, 2006 11:14 pm

Addendum....

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

Thanks!

m_b
Top
widan
Veteran
Veteran
User avatar
Posts: 1512
Joined: Tue Jun 07, 2005 4:26 pm
Location: Paris, France

  • Quote

Post by widan » Tue Feb 07, 2006 11:27 pm

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.
Top
modified_bessel
Tux's lil' helper
Tux's lil' helper
Posts: 101
Joined: Fri Jul 16, 2004 9:08 am
Location: Cote d'Azur, France

  • Quote

Post by modified_bessel » Wed Feb 08, 2006 8:35 am

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
Top
Skandal
n00b
n00b
Posts: 12
Joined: Sat Aug 28, 2004 10:47 am

  • Quote

Post by Skandal » Wed Feb 22, 2006 4:40 pm

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

When I recompress the initramfs using

Code: Select all

# 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.
Top
widan
Veteran
Veteran
User avatar
Posts: 1512
Joined: Tue Jun 07, 2005 4:26 pm
Location: Paris, France

  • Quote

Post by widan » Wed Feb 22, 2006 5:26 pm

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) ?
Top
Skandal
n00b
n00b
Posts: 12
Joined: Sat Aug 28, 2004 10:47 am

  • Quote

Post by Skandal » Wed Feb 22, 2006 9:48 pm

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=)
Top
Post Reply

14 posts • Page 1 of 1

Return to “Kernel & Hardware”

Jump to
  • Assistance
  • ↳   News & Announcements
  • ↳   Frequently Asked Questions
  • ↳   Installing Gentoo
  • ↳   Multimedia
  • ↳   Desktop Environments
  • ↳   Networking & Security
  • ↳   Kernel & Hardware
  • ↳   Portage & Programming
  • ↳   Gamers & Players
  • ↳   Other Things Gentoo
  • ↳   Unsupported Software
  • Discussion & Documentation
  • ↳   Documentation, Tips & Tricks
  • ↳   Gentoo Chat
  • ↳   Gentoo Forums Feedback
  • ↳   Duplicate Threads
  • International Gentoo Users
  • ↳   中文 (Chinese)
  • ↳   Dutch
  • ↳   Finnish
  • ↳   French
  • ↳   Deutsches Forum (German)
  • ↳   Diskussionsforum
  • ↳   Deutsche Dokumentation
  • ↳   Greek
  • ↳   Forum italiano (Italian)
  • ↳   Forum di discussione italiano
  • ↳   Risorse italiane (documentazione e tools)
  • ↳   Polskie forum (Polish)
  • ↳   Instalacja i sprzęt
  • ↳   Polish OTW
  • ↳   Portuguese
  • ↳   Documentação, Ferramentas e Dicas
  • ↳   Russian
  • ↳   Scandinavian
  • ↳   Spanish
  • ↳   Other Languages
  • Architectures & Platforms
  • ↳   Gentoo on ARM
  • ↳   Gentoo on PPC
  • ↳   Gentoo on Sparc
  • ↳   Gentoo on Alternative Architectures
  • ↳   Gentoo on AMD64
  • ↳   Gentoo for Mac OS X (Portage for Mac OS X)
  • Board index
  • All times are UTC
  • Delete cookies

© 2001–2026 Gentoo Foundation, Inc.

Powered by phpBB® Forum Software © phpBB Limited

Privacy Policy

 

 

magic