Hi Rachita,
the initramfs source code in the kernel is linux-2.6.*/init/initramfs.c.
It depends on CONFIG_BLK_DEV_INITRD so make sure you have that in your
kernel .config.
here is a step by step intro to initramfs, it might be helpful.
however I only guess in most parts, so I might be wrong.
if you are familiar with initrd, then initramfs has two differences:
- different file format (cpio file, while initrd could be any
filesystem, typicaly cramfs)
- different program started (/init vs. /linuxrc in initrd)
in addition initramfs can be linked into the kernel,
so the bootloader will only need to load one binary, not two.
I suggest you first experiment with a standalone initramfs,
i.e. one that is loaded by the bootloader like an initrd.
once that works, you can experiment on linking it into the
kernel binary itself.
if you have a staticaly linked application called "init",
you can create an initramfs with:
echo init dev/console dev/hda1 new-root |cpio -o -H newc > initramfs
and you can create a compressed initramfs with
echo init dev/console dev/hda1 new-root |cpio -o -H newc > initramfs.gz
in both cases dev/console should be the same device as /dev/console,
dev/hda1 the same device as /dev/hda1 and new-root an empty directory.
if your / partition is not /dev/hda1, adjust as needed.
both can be loaded like a initrd. here is an example
for grub (syslinux will work even better, but I only
have this example at hand - sorry)
title Linux 2.6.10 boot
kernel /vmlinuz-2.6.10 root=/dev/initrd
initrd /initramfs
so, that should that application do?
- mount /dev/hda1 /new-root
- cd /new-root
- run-init
get the klibc source code, and read
utils/run-init.c. That is a program
that will remove the initramfs and pass
control to the real init on the real root
partition. it replaces the
pivot_root mechanism used with initrd.
if you edit run-init.c, remove the getopt
code, and add the mount and cd commands
mentioned, then you should have a working
init program.
once your init works, you can add whatever
features you want your initramfs to do.
the next step is to link your initramfs
into the kernel. the easiest "hack" is to
replace initramfs_data.cpio and initramfs_data.cpio.gz
with your initramfs.
the next step after that is to not create
your files with cpio, but to use the kernel
gen_init_cpio and initramfs_list to do that.
the advantage here is, that you don't need to have
an empty directory nor you need those device files,
instead you write into initramfs_list what files
directories and devices should be in the the
initramfs and what user/group/permissions/device type/major/minor
will be, and it will create an initramfs with that information.
run ./gen_init_cpio to get a help text on what is allowed in
initramfs_list and what the syntax is.
last step: add your source code to linux-2.6.yourversion/usr/ and
edit the Makefile to build your "/init" app along with the kernel.
in case you try this, please let me know if it works or not.
early userspace is a very nice thing, but currently not many people
use it. some success stories would be nice :-)
Regards, Andreas
--
---------------------[ Ciphire Signature ]----------------------
From: aj@ciphirelabs.com signed email body (2582 characters)
Date: on 03 February 2005 at 10:55:16 UTC
To: rachitako@in.ibm.com, klibc@zytor.com
----------------------------------------------------------------
: Ciphire has secured this email against identity theft.
: Free download at www.ciphire.com. The garbled lines
: below are the sender's verifiable digital signature.
----------------------------------------------------------------
00fAAAAAEAAAAUAwJCFgoAAPgAAAIAAgACACCFlK4A+54we7zwPJsjFBflkYBMj+
KIfUWI8cEb4zJitwEAjuLZDHPnOxRgKfQyXaVwrQqQB78iLphbN7mW+8mUnEFHwQ
T5x7Pptr+UylRMRlo9uC5wT0BFA7fz66ouEbJtJQ=------------------[ End Ciphire Signed
Message ]----------------