< Back to index

KLibc is a minimalistic libc subset developed by H. Peter Anvin, intended to be used within an initramfs, as part of a multi-stage Linux boot process. It is incorporated into initial ram filesystems that are created by the mkinitramfs script.

Included Programs


Klibc includes (among other things) tiny implementations of:

* cat
* chroot
* dash (a command interpreter/shell, like sh)
* dd
* false
* fstype
* gzip
* gunzip
* insmod
* ipconfig (includes dhcp support)
* kinit
* ln

* minips (process status)
* mkfifo
* mount
* nfsmount
* nuke
* pivot_root
* run-init (see below)
* sha1hash
* sleep
* true
* umount
* uname
* zcat

In addition, Klibc also provide a build environment (klcc) for compiling and linking your own applications against the tiny library.

The Role of run-init


The run-init program does some of what pivot_root(8) did under the old initrd system, but in a slightly different way and with some important new features that compliment an initramfs. It is the very last thing that runs within the initramfs, before control is handed over to your real init and the real root filesystem. run-init does the following:

# Deletes all files and directories in the initramfs. Because a ramfs can grow and shrink as needed this allows memory to be given back to the kernel.
# Mounts the "real" root filesystem on /
# calls chroot(2) to the new root filesystem
# Opens /dev/console (or some other file as specified) and makes that its standard input, output, and error. This will allow the console to be inherited by the "real" init program.
# Spawns the "real" init program, using execv(2).

Shared objects


The normal klibc build process yields two sets of executables for most of the applications: shared and static. Note that the shared versions do not use the traditional Linux ld.so method of dynamic linking; they are, in fact, statically linked against a shared library. As such, they find the library by themselves, and require the exact version of the library linked against. To prevent problems, klibc shared libraries embed a signature in the filename; this also allows multiple versions of the klibc shared libraries to coexist should it be necessary.

To prove this, observe the following:

$ strings shared/cat | grep '\.so'
/lib/klibc-T6JVpuA_S5BO3sCmkD95p9L4hL4.so
$ strings static/cat | grep '\.so'
$
$ ldd shared/cat
not a dynamic executable


However, shared/cat is indeed "dynamic" - it will not run without the klibc shared library in the correct place, with the correct file name (including the signature).
This entry uses material from from Wikipedia, the leading user-contributed encyclopedia. It is licensed under the GNU Free Documentation License. Disclaimer.