Executing a script

Because /init is a shell script, the following steps occur when the kernel requests to start it:
  1. The kernel calls its own "exec" function, passing the filename, "/init".
  2. The exec kerenl function opens the file and looks at the first two bytes. This is to determine whether the file contains an executable program or a script. In this case the first two bytes of the file contain "#!" so the kernel knows this is a script.
  3. The kernel interprets the remainder of the first line of the file as the name of the interpreter to run. In this case that value is "/bin/sh", the name of the system shell.
  4. In the initrd file system, /bin/sh is a symbolic link to another file. Which file depends on which distro is runing as described in the main article.
  5. The shell executable file is then mapped into memory and executed. The name of the script ("/init") is passed to the shell as its first command-line parameter.
  6. The shell then opens the file whose name was passed on the command line. It begins interpreting the script.

Return to the Init Thread page.

Return to main PC Boot Sequence page

Return to my writing page

Return to my home page