[klibc] [PATCH v2 0/4] Support drop directories directly from kinit

Mike Waychison mikew at google.com
Tue Aug 2 15:46:44 PDT 2011

This patchset applies to klibc mainline.

This patchset introduces the ability to kinit to execute scripts or
executable files present in in the initramfs before switching over to
the root filesystem.

It is implemented by first implementing scandir() and alphasort() as
present in POSIX.1-2008 in klibc itself, and then using that as the
basis for iterating and executing files via a run_scripts() call.

This patchset introduces two different drop directories, though this is
of course subject to change and these are only presented in an effort to
put an example forward.  I currently only have a requirement to run
stuff between the time we call do_mounts() and the time we call

These are the directories:

      /scripts/after-network: ipconfig is completed, but the root
          filesystem isn't yet mounted.
      /scripts/after-mount: the root filesystem has just been mounted at

I believe this would help both our use-case (where we'd like to do
customization of the early-bootup sequence without having to hack kinit
too much), and the use case for initramfs-tools, opening the door to
replace all the "core" shell there kinit as a C implementation.


Mike Waychison

    - Added __extern to alphasort declaration.
    - Split alphasort() out into alphasort.c and its own patch.

Related discussions
    - We recently had a discussion at:


      where I wanted to refactor bits of kinit out so that I could
      invoke them from a shell script.  This patchset is an alternative
      solution that would allow users of kinit to add custom logic at
      the intermediate stages without having to have the whole init
      driven by a shell script.

    - v1 sendout:


Patchset summary

klibc: Add scandir() and alphasort() support.
kinit: Add run_scripts()
kinit: Add callsites to execute files in drop-directories.

More information about the klibc mailing list