Linux – How does the kernel “give up” control to distribution-specific initialization

bootkernellinux

I've always wondered how the kernel passes control to third-party code, or specifically distribution-specific code, during boot.

I've dug around in GRUB's configuration files, suspecting a special parameter to be passed to the kernel to let it know what to do once it has booted successfully, but unable to find anything. This leads me to suspect there may be certain files on the root partition that the kernel looks for.

I'd be grateful if someone could shed some light upon this matter. How do distributions achieve this?

Best Answer

It's hardcoded, but you can override the defaults by the kernel parameter init=....

From init/main.c:

if (execute_command) {
  run_init_process(execute_command);
  printk(KERN_WARNING "Failed to execute %s.  Attempting "
        "defaults...\n", execute_command);
}
run_init_process("/sbin/init");
run_init_process("/etc/init");
run_init_process("/bin/init");
run_init_process("/bin/sh");

panic("No init found.  Try passing init= option to kernel. "
      "See Linux Documentation/init.txt for guidance.");
Related Question