run-init is a binary executable, it lives in /usr/lib/klibc/bin/run-init and in your initramfs and is provided by the
klibc-utils package in Ubuntu. It isn't a script, so you cannot take a look inside directly, you can check out its source code via running
apt source klibc-utils or browsing the upstream repository at https://git.kernel.org/cgit/libs/klibc/klibc.git.
So the main function is in run-init.c , but it's just a wrapper for
run_init function, which lives here in runinitlib.c
run_init does a lot of work:
- It jumps into the new root file system
- Checks that this is the new root file system
- Checks if it on initramfs
- Cleans all directory (why waste the RAM?)
- Mounts the new root file system
- and runs init in the new root file system
I believe, it would be very complicated to do all this work by a script, because of dependencies, but binary executable file can do it very ease.