Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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?

share|improve this question
add comment

2 Answers 2

up vote 8 down vote accepted

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.");
share|improve this answer
1  
Is it safe to assume that /etc/inittab is distribution-specific and contains the scripts responsible for initialization then? –  haste Feb 23 '12 at 16:04
    
@haste It's not always inittab: it's whatever the init uses (there are three init systems around on Linux these days: SysVinit, Upstart and Systemd; see What's the connection between "/etc/init.d" and "/etc/rcX.d" directories in Linux? –  Gilles Feb 23 '12 at 23:27
    
@Gilles Does this mean that the kernel doesn't ship with any of these init variants you mentioned? And as a result, the distribution is responsible for making sure an init executable is available where the kernel would look (by boot parameter or defaults)? –  haste Feb 24 '12 at 0:27
    
@haste: Correct. In contrast to some other systems (like FreeBSD), Linux is just a kernel. Everything else is added by the distribution, and purists tend to refer to complete systems as "GNU/Linux" to stress the fact that in addition to the Linux kernel, there a boatload of GNU programs is needed to get a usable system. –  Ansgar Esztermann Feb 24 '12 at 8:57
    
@haste The kernel is only a kernel. A working Linux systems requires many utilities that are shipped separately and put together by distributions; init is one of them. (BTW @ Ansgar the GNU project doesn't have an init, all the choices for init are by other projects. A lot of embedded Linux systems have no software that come from the GNU project, but that would be exceptionally rare on a desktop or server, and even embedded systems are mostly compiled with the GNU compiler.) –  Gilles Feb 24 '12 at 9:12
add comment

Wikipedia has a nice article about the Linux start up process.

Today, usually an initramfs is used.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.