Friday, August 10, 2007



initramfs by default load a cpio image. But it can also load initrd (a
fs) image.

The "initramfs" concept has been in the 2.5 plans since back before
there was a 2.5 kernel. Things have been very quiet on the initramfs
front, however, until the first patch showed up and was merged into the
2.5.46 tree.

The basic idea behind initramfs is that a cpio archive can be attached
to the kernel image itself. At boot time, the kernel unpacks that
archive into a RAM-based disk, which is then mounted and used at the
initial root filesystem. Much of the kernel initialization and bootstrap
code can then be moved into this disk and run in user mode. Tasks like
finding the real root disk, boot-time networking setup, handling of
initrd-style ramdisks, ACPI setup, etc. will be shifted out of the
kernel in this way.

An obvious advantage of this scheme is that the size of the kernel code
itself can shrink. That does not free memory for a running system, since
the Linux kernel already dumps initialization code when it is no longer
needed. But a smaller code base for the kernel itself makes the whole
thing a little easier to maintain, and that is always a good thing. But
the real advantages of initramfs are:

* Customizing the early boot process becomes much easier. Anybody
who needs to change how the system boot can now do so with
user-space code; patching the kernel itself will no longer be

* Moving the initialization code into user space makes it easier
to write that code - it has a full C library, memory protection,

* As pointed out by Alexander Viro: user-space code is required to
deal with the kernel via system calls. This requirement will
flush a lot of in-kernel "magic" currently used by the
initialization code; the result will be cleaner, safer code.



_start() -> start_kernel() -> rest_init()->

kernel_thread(init, NULL, CLONE_FS | CLONE_SIGHAND);

_init() -> do_basic_settup():

* Ok, the machine is now initialized. None of the devices
* have been touched yet, but the CPU subsystem is up and
* running, and memory and process management works.
* Now we can finally start doing some real work..
static void __init do_basic_setup(void)
/* drivers will send hotplug events */

do_initcalls() --> populate_rootfs()

Blog Archive