4

How does the linux kernel know the location of the /sbin/init program during the boot process? Is "/sbin/init" hard coded into the linux kernel source code?

U85
  • 121
  • 4

2 Answers2

7

Yes, /sbin/init is hardcoded into the source. See the function init_post 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.");
Mark Wagner
  • 18,019
  • 2
  • 32
  • 47
3

The program to run when kernel loading has completed can be given on the kernel boot command line using the init=/file/name argument.

If this option is not passed, the built-in default /sbin/init is used.

adaptr
  • 16,576
  • 23
  • 34