[BusyBox] ramdisk to ramfs confusion

Gavin Dolling gavind at lsil.com
Fri Oct 19 04:58:25 UTC 2001


So for closure on this here is the answer to how it all works as eluded to
in the original request, my cloud of confusion has lifted:

The key as Geoff has discovered is the linuxrc file. Rob gives a good script
but the key is when to execute it.

What exactly is linuxrc? Well if a /linuxrc file is found on an initrd when
it is mounted the file is executed automatically. If you have a boot loader
which simply points to a ram disk as the root filing system then any
/linuxrc file is not run (hence you must use the init=/linuxrc kernel option
in this case). linuxrc can be any executable or shell script, so you don't
need a shell on your system to get this to work (thinking of embedded apps
here).

The linuxrc file must mount the ramfs, copy the files and then perform the
pivot_root. The last thing the linuxrc file does is execute the init process
from the new filing system. The key observation as to why this works is that
all the work is done before the init process has started. The work is done
after the initial filing system is mounted but before the init process has
started. Once the init process has started it cannot be killed and will lock
any FS it is executing from (look at 'ls -l /proc/1/exe' to see where it is
executing from).

Once Linuxrc kicks off the init process and has finished you can umount and
free up the ramdisk (I do this in inittab for instance).

One final note is that the patch, as supplied by Geoff, is crucial. I have
Linux 2.4.10-ac10-rmk1 and it wasn't in that. Without this patch the
freeramdisk call fails.

Thanks everyone and let's hope the archive now contains enough info for
future hackers to have no problems.

Gavin.







More information about the busybox mailing list