Search code examples
clinux

How can the Linux kernel compile itself?


I don't quite understand the compiling process of the Linux kernel when I install a Linux system on my machine.

Here are some things that confused me:

  1. The kernel is written in C, however how did the kernel get compiled without a compiler installed?
  2. If the C compiler is installed on my machine before the kernel is compiled, how can the compiler itself get compiled without a compiler installed?

I was so confused for a couple of days, thanks for the response.


Solution

  • The first round of binaries for your Linux box were built on some other Linux box (probably).

    The binaries for the first Linux system were built on some other platform.

    The binaries for that computer can trace their root back to an original system that was built on yet another platform.

    ...

    Push this far enough, and you find compilers built with more primitive tools, which were in turn built on machines other than their host.

    ...

    Keep pushing and you find computers built so that their instructions could be entered by setting switches on the front panel of the machine.

    Very cool stuff.

    The rule is "build the tools to build the tools to build the tools...". Very much like the tools which run our physical environment. Also known as "pulling yourself up by the bootstraps".