switching from initrd to initramfs

Mikhail Zaturenskiy mzaturenskiy.st at gmail.com
Thu Jul 9 08:56:01 EST 2009


> I was hoping to convert this working initrd to initramfs before I try
> and create my own initrd, I'm still learning about this process. I got
> this to work yesterday morning, but I'm not sure what changed or what
> I'm doing differently...
> Can somebody help me figure out what's missing?

Never mind, got it! :)  For reference, here is what I did:
First I made a custom init file called "init_mz" with  the following contents:
#!/bin/sh
echo "hello! processing init_mz"

#Create all the symlinks to /bin/busybox
echo "installing busybox links..."
busybox --install -s
echo "done installing busybox links..."

#Mount things needed by this script
echo "mounting proc..."
mount -t proc proc /proc
echo "done mounting proc..."
echo "mounting sysfs..."
mount -t sysfs sysfs /sys
echo "done mounting sysfs..."

#Create device nodes
echo "creating /dev nodes..."
mknod /dev/null c 1 3
mknod /dev/tty c 5 0
mdev -s
echo "done creating /dev nodes..."

echo "exec-ing sh..."
exec /bin/sh

At this point booting with the "rdinit=/init_mz" kernel argument worked.

Then I removed pretty much everything unnecessary from my root tree,
cross-compiled a busybox v1.14.2 with defconfg (except
statically-linked), and created the few necessary links, so my tree
looks like this:

************
|-- bin
|   |-- busybox
|   |-- echo -> busybox
|   |-- mount -> busybox
|   `-- sh -> busybox
|-- dev
|-- init_mz
|-- proc
|-- sbin
|-- sys
`-- usr
    |-- bin
    `-- sbin
**************
I could probably also get rid of /dev /proc /sbin /sys /usr* /bin/echo
and /bin/mount and just create those on the fly in the init_mz file.

I'm building the initramfs ramdisk using:
find | cpio -ovc | gzip -v9 > ../initramfs.cpio.gz
mkimage -T ramdisk -C gzip -n 'Test Ramdisk Image' -d
../initramfs.cpio.gz ../uCpio

For my kernel arguments I'm using "console=ttyCPM0,9600n8
root=/dev/ram rw rdinit=/init_mz" and that is all! I now have a
functional initramfs that's 0.97MB large.

For a while I was confused because "ls" output had file names with
strange symbols such as "1;34mbin0m" for "bin", but I figured out that
it's because supposedly those represent font colors and I'm using
HyperTerminal which doesn't support them.

I hope somebody will find this useful.

Mikhail Zaturenskiy


More information about the Linuxppc-dev mailing list