How to make a Linux distribution starting from nothing


Create a Linux Distribution from Scratch

Creating a Linux distribution from scratch is viewed as a daunting task, and it shouldn't be. The process involves creating a toolchain, using that toolchain to create a root file system, and then building a kernel. The process isn't complex, it just requires you to carefully follow many steps to build the proper tools. After you go over the instructions for building a toolchain and understand how it works, the smartest route may be to use a tool that builds a toolchain, such as crosstool-NG, to build the root file system and kernel. In prior years, before Linux's popularity with board vendors and chip makers hit its stride, support for any hardware platform other than Intel's X86 was spotty; however, with Linux becoming the platform of choice for embedded devices, support for most embedded hardware platforms is part of the Linux kernel and toolchain. These are fine approaches to getting a Linux distribution, but building from scratch gives you the most control over the composition of the distribution and how it works. The learning curve to create a distribution from scratch is also about the same (at least for me) as learning a distribution-building tool, and the skill is more transferable. Making a Linux distribution involves these steps:

1. Build a cross-compiler.

2. Use the cross-compiler to build a kernel.

3. Use the cross-compiler to build a root file system.

4. Roll the root file system into something the kernel can use to boot.

A cross-compiler is the Rosetta stone (the flux capacitor, if you will) of embedded development. Until this tool has been built, the kernel can't be built - nor can the root file system's programs be built. This article goes over how to create a toolchain for an ARM board and then build the kernel and root file system. Because the Linux kernel has matured, the sources in the main projects don't need the level of patches they once did in order to support common embedded targets The hunting and gathering step snares many who build distributions from scratch, because there is no canonical place where you can locate the patches for a certain revision of the tools used in the build. Building the toolchain is still one of the more complex bits of the process, and a reasonable tool is available that just builds a toolchain: crosstool-NG. After you build a toolchain from scratch, the article has you create one with crosstool-NG to compare the two processes.

If possible, the best approach is to use crosstool-NG or one of the distribution builders to create a toolchain. Because a toolchain involves so many software packages, getting a set that works together is a great value that these projects provide. Another slightly confusing part of the process is that the kernel sources are used in the build process. One step in building the cross-compiler is to build the corresponding C Standard Library. In order for the C Standard Library to build, it needs to know some information about the target machine, which is kept in the kernel. For the uninitiated, this seems to be a circular dependency; but the parts of the kernel that are used don't need to be cross-compiled. When you have the cross-compiler in hand, you create the root file system with the BusyBox project. Linux requires a root file system and refuses to boot if one can't be found. A root file system can be one file: the application program for the device. Most embedded Linux systems use additional libraries and utilities. The root file system in this article is linked with the GNU C Library at runtime, so these files must be on the target as well. BusyBox is a program that provides limited-functionality implementations of most command-line tools found on a Linux system.

Although a root file system doesn't need to contain all these tools, having them available when the system boots is a convenience. When you understand what tools are necessary (frequently, it's a very small set), you can remove the rest to economize on space and make the system more secure. How does a small root file system make a system more secure? The fewer programs, the smaller number of possible exploits. A root file system containing just the functionality necessary to execute the application on the target doesn't present an attacker with any more opportunities than absolutely necessary. A small number of programs also reduces the maintenance required to keep current with changes happening in the open source community. The kernel is the last component in this process. The kernel is a self-contained system that doesn't have runtime dependencies. Being a very mature project, the cross-build of the kernel works very well. The kernel build process is by far the easiest process in this article.

Legal Disclaimer

Our website is not responsible for the information contained by this article. Articleinput.com is a free articles resource thus practically any visitor can submit an article. However if you notice any copyrighted material, please contact us and we will remove the article(s) in discussion right away.

Note: This article was sent to us by: Peter B. Taller at 01242010

Related Articles

1. The resemblance between the GCC compiler and the kernel in Linux
The GNU Compiler Collection The GCC compiler, like the kernel, is designed for portability. Like all open source programs, GCC is available in source form, and ...

2. Automake and Autoconf discover the state of the target environment
Automake/Autoconf Open source software is designed to be distributed in source code form so that it can be compiled for the target platform. When target platfor...

3. How and where does a software developer get help
Where to Get Help All software developers depend on little helpers, whether visible or invisible. Open Source developers tend to call upon a large number of res...

4. Necessary additional steps to get Linux running
Host Services After the software is installed, some additional configuration steps are necessary to get the packages in running order. This part goes through co...

5. Virtualization and the computer resource sharing
Target Emulation and Virtual Machines Virtualization is a mature technology that lets several operating systems share the physical resources of a machine, such ...

6. Development of hosting code and use of virtualization software
Virtualization Software for x86 Hosts If you're developing code for an x86 host, why bother using virtualization? The host and target are identical, so using vi...

7. How to boot the board and start Linux
What to Do After Unpacking the Board The best way to assess what is supplied with the board is to plug in the board and get Linux up and runnin...