3

There's an init script in the initial ramdisk during the bootint process. At the last operation, it says that:

# Chain to real filesystem
exec run-init ${rootmnt} ${init} "$@" ${recovery:+--startup-event=recovery} <${rootmnt}/dev/console >${rootmnt}/dev/console 2>&1
panic "Could not execute run-init."

I search all scripts in ramdisk content, and can't find any file name or function name like that.What is the run-init actually?

naive231
  • 183

3 Answers3

7

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:

  1. It jumps into the new root file system
  2. Checks that this is the new root file system
  3. Checks if it on initramfs
  4. Cleans all directory (why waste the RAM?)
  5. Mounts the new root file system
  6. 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.

rth
  • 255
1

According to dpkg-query it's part of the klibc-utils package. Some digging in the source code shows a call to execv to start the init process on the real filesystem. If that fails, run-init will return, thus triggering the panic on the last line.

Drew McGowen
  • 111
  • 4
0

Ubuntu 14.04LTS In empty folder create file [get-it.sh]

#!/bin/sh

cp /boot/initrd* initrd.cpio.gz
mkdir initrd
cd initrd
zcat ../initrd.cpio.gz | cpio -di
find | grep run-init
cd ..

and run it: bash get-it.sh

file run-init will be in ./bin/run-init

Also you can get initrd from installation cd