I searched and didn't find, and had to figure stuff out... I hope to save you the trouble.

Thursday, April 23, 2009

Modifying initrd with a Mac

When Linux boots, the bootloader starts the kernel with a parameter telling it what file to load into ram as the initial ramdisk. The initial ramdisk is used as the root filesystem until it's configured enough stuff and loaded enough drivers to mount the real root filesystem.

Normally the initrd is put together with the mkinitrd tool. But, initrd.gz is just a gzipped cpio archive, so you can use the gzip and cpio tools to extract and create it as well. To make sure permissions aren't messed up, run cpio as root (There are probably tools that will twiddle the bits in the cpio archive, but if you have root access then sudo is an easy answer).
mkdir initrd-root
cd initrd-root
gunzip -c ../initrd.gz | sudo cpio -imdv
Examine or modify the extracted contents as you like. Then you can put your modified initrd back together:
cd initrd-root
find . | cpio -ov -H newc | gzip > ../initrd.gz
But, wait... you said this could be done on a Mac...

If you're using Mac OS X, there's a slight glitch - the version of cpio that Apple ships doesn't support creating the necessary newc format archive.

To deal with that, we'll build our own cpio 2.9 from source, which almost works right out of the box. One small glitch is that current versions of gcc shipped with Xcode have a bug that results in:
ld: duplicate symbol _argp_fmtstream_putc in ../lib/libcpio.a(argp-fmtstream.o) and ../lib/libcpio.a(argp-help.o)
The problem is related to Apple's gcc improperly handling extern inline in C99 mode. Since we're just building a binary and therefore don't particularly care about C99, we'll just disable it with a configure flag.

Here's the download-and-build recipe:
curl -O http://ftp.gnu.org/gnu/cpio/cpio-2.10.tar.gz
tar xzvf cpio-2.10.tar.gz
cd cpio-2.10
./configure ac_cv_prog_cc_stdc=no
make
sudo cp src/cpio /usr/local/bin

8 comments:

  1. Hi Tom,

    The build instructions yield the same duplicate symbol errors as if the flag were left out. Not sure how to go about fixing it. Up until this point the instructions for netboot easypeasy have been great!

    ReplyDelete
  2. Going to try using the cpio build from darwinports, will report back with results.

    ReplyDelete
  3. Same error with darwinports, but it seems somehow there's already a cpio in /usr/bin/cpio... so I'll just try with that.

    ReplyDelete
  4. crwbot, since you're getting the same cpio-2.9 source as I got, I can only think it's a difference in tools. Here's what I have:
    gcc = i686-apple-darwin9-gcc-4.0.1
    autoconf = 2.63
    automake = 1.10.2
    (all checked with the --version flag on the respective tool)

    The configure flag results in the generated Makefiles NOT having the '-std=gnu99' flag on the CC variable. It also changes several definitions in config.h (HAVE_COMPOUND_LITERALS, PROTOTYPES, __PROTOTYPES, restrict).

    As a last resort, I just put my compiled binary up so you can download it. (If I get too much traffic I'll take it down, so everybody should try compiling it themselves first) http://mindgear.com/GPL/i686-apple-darwin9-cpio

    ReplyDelete
  5. Tom, the cpio that I found in /usr/bin didn't recognize newc format as an option, so I took the -H flag out on the repack. The rest seemed to work just fine. I'll be attempting the actual netboot install later in the day (Eee pc just arrived), so we'll see how it goes. :)

    ReplyDelete
  6. Didn't work.

    [2.159205] Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(0,255)

    Unsure if this has anything to do with the repack of initrd not being in newc format.

    gcc=4.0.1
    autoconf=2.61
    automake=1.10

    Think I'll try your binary first, then go through the last steps and try netboot again.

    ReplyDelete
  7. That did the trick, thanks for the binary, Tom.

    I'm now booting the Eee 1000 from my Macbook via ethernet, but am now stalled when no Easypeasy installation process launches. I get dumped at a BusyBox (initramfs) prompt.

    ReplyDelete
  8. crwbot, since you have an eee 1000 (not an eee 900), my guess is that the network hardware is different and you need a different driver in the initrd than "atl2.ko" that I called for in my instructions.

    I seems like you instead need "atl1e.ko" (http://forum.eeeuser.com/viewtopic.php?id=38030), which is in a different directory, so where I describe "Fixup the initrd for the eee PC 900" try this instead:

    unsquashfs casper/filesystem.squashfs lib/modules/2.6.27-8-eeepc/kernel/drivers/net/atl1e/atl1e.ko

    ReplyDelete

Followers