Self-replicating kernel?
I have built a nice console-only CLFS-based Linux (2.6.39.4).
It runs on pretty much any x86 system, supports network and fits into 20MB RAM.
My goal was to make a small USB-bootable distro and its full image image has to be e-mail-able (<= 5MB in my case). The current ISO size is 4.9MB.
Now I want to add a user-invoked script for self-replication to a USB stick.
The script should find, partition and format the inserted media, install bootloader (I use extlinux), copy kernel and ramdisk images and extlinux config file.
I don't want to rely on original CD/USB disk presence.
I want to be self-contained as much as possible.
When init process is done I don't want to assume anything about inserted media. The only reliable code I have is in RAM.
Ramdisk image is easy: I'll just cpio running ramfs to the media.
The question is how to obtain the kernel image on a running system.
Since I am restricted by 5MB image size I don't want to have a static copy of kernel in my ramfs during build time.
1.
Is it possible to extract from RAM (uncompressed?) copy of the running kernel that would be equivalent to the originally built kernel?
If it's not possible, then during init scripts execution I have to find out the original boot device and copy kernel image to my ramfs.
2.
How can I reliably find the device that my running kernel was taken from (some kernel parameter passed from extlinux?)?
Do you have any other suggestions how to make self-replication without relying on post-init data outside of RAM?
Thanks!
|