Computer Applications Papers construction principle of LFS analysis

Abstract: With the increase of Linux users, more and more people are willing to customize their own operating systems, LFS is a kind of Linux a popular method for building from source code. This paper analyzes the construction principle of the method, analyzed the causes of Binutils, Gcc and seed compiling Glibc in the build process many times.

Keywords: custom LFS Binutils Gcc Glibc
I. Introduction

Linux and Unix is very similar to an operating system has all the features of Unix and POSIX-compliant and. It is a true multi-user multi-tasking operating system, is an excellent application software development platform. The greatest feature of Linux is that it is free, this freedom has a double meaning. On the one hand, the meaning of freedom of Linux is that it is free, the cost of having to spend can get it. Linux has another important manifestation of freedom that Linux can provide unlimited broad space for free play technology. After purchasing to get more than just a Linux operating system, but also get the source code for the system. So if you do not like the Linux way of working, you can change it (just make minor changes, you can even install your demand to change the entire operating system). Just follow the General Public License (General Public License) requirements, which can be used freely without compensation, improvement and development. This is exactly one of the reasons Linux is growing so rapidly.

Open source, but also more and more people unwilling to use the existing release, in order to Linux completely satisfied, we must build your own system from scratch. LFS dissertation is to construct a method of Linux.

Two, LFS and its characteristics

Linux From Scratch LFS is an abbreviation. "From Scratch" is a phrase that means "from scratch, scratch, scratch" in this sense, "Linux From Scratch" in nature and should not be construed as a Linux distribution name. It is most appropriate meaning should be a "method / idea": all means start from the source code / idea. If the LFS compared to building a house, then the LFS provides the framework blueprint for a house, but you need to build it yourself.

Using an existing Linux system to develop their own custom system, this "perfect" Linux system would have the advantage of a variety of release without their disadvantages. The user can control all the features of the system, including directory layout, script and security settings, and so on. The final system from the source code directly compiled, the user can specify where to install, why install and how to install each program. It can be completely customized to suit your needs Linux systems, but also to have more control over the system.

Third, the benefit of LFS

is an important reason for LFS's existence is to help people learn how a Linux system works internally. Build a LFS system helps demonstrate what makes Linux running, how the various components work together interdependent. The best thing is you can get fully customized Linux system through this learning capacity according to their needs.

A key benefit of LFS is that it allows users to have more control over the system, rather than relying on someone else's Linux implementation. In the LFS world, you sit in the driver's position, to control every detail of the system.

Another benefit of LFS is that you can create a very compact Linux system. When installing a regular distribution, people are often forced to install some may never use the program. These programs waste valuable disk space, or worse, CPU resources. Own customized Linux system Another benefit is security. By compiling the entire system from source, you can review anything, marked with all the security patches without having to wait for others to repair security vulnerabilities compiled binary packages. Unless you find and produce patches, otherwise you can not ensure that the new binary package was built correctly and correct the problem.

Fourth, the construction principle of LFS

to be based on the way the source code to compile the entire system, it must first solve the problem is the tool chain that need a compiler environment. So LFS system constructed in two big step: First, construct a temporary build environment; second is to build LFS system.

A Temporary fact, the equivalent of a small Linux system. But this system will only contain the necessary tools to build the final LFS system. This small system constructed in two steps, the first step is to build a new system does not depend on the host tool chain (compiler, assembler, linker, libraries, and some useful software), the second step is the use of the toolchain to build the other essential tools.

The most basic tool in the chain are: Binutils, GCC and Glibc. Binutils is a set of development tools, including connectors, assembler and other tools used in the object files. GCC package contains the GNU compiler collection, which includes the C and C ++ compilers. Glibc package contains the main C library. This library provides the basic routines for allocating memory, searching directories, opening and closing files, reading and writing files, string handling, pattern matching, arithmetic, and so on. Other tools must be built on their basis. So in the course of the following explanation is mainly based around the three tools installed, and the adjustment tool chain.

So how to create such a compilation environment? It would need a ready-made system, called the host system. Now the general idea is to create a temporary system in the host environment, you can chroot to the environment, to build a clean, no problem LFS system on the basis of the environment. In order to separate the host system as much as possible, so to create a self-contained, self-reliant tool chain. Since the chain here only for transient tool, after completion of LFS can be peeled off, it is possible to compile all the files are placed in the same file ($ LFS / tools). In the build process should note the following:

1. This process is similar in principle cross compiler to work by the tool is installed in the same directory (using the same "prefix") also utilized the GNU bit "magic".

2. Carefully library search path processing standard connector, ensure that the program is only connected to the specified database.

3. Handle Gcc specs file tells the compiler which dynamic linker to use. 

Let's look at how to achieve the specific.

In order to create a clean working environment, create a new host system lfs a user group, and add the lfs user, the user has to use during the installation process.

First compile Binutils, then using the host system environment. There is no doubt now take advantage of the resulting Binutils program will be affected by the host system. For example: use the generated ld (standard connector) will connect to the default program / lib directory (host system) in binary.

Then compile Gcc, still need the environment of the host system. Obviously Gcc also affected by the host system, which can be compiled from its point of view, it relies on a host of Glibc, Binutils and can be used just generated. Glibc provides dynamic linker, to find and load the required runtime shared libraries a program, prepares the program to run in and run this program. Gcc generated at this time will be used in the dynamic linker / lib (host systems), rather than under the $ LFS / tools / lib.

Through the above two steps, we can use just created binutils and Gcc to compile Glibc up. Now we will binutils, Gcc and Glibc are recompiled once. The next step is to solve the two problems just mentioned by adjusting the tool chain. First, recompile ld, ld will connect to the library under the $ LFS / tools / lib. Second, to adjust the dynamic linker, Gcc modify the SPEC file, connecting to the dynamic linker is /tools/lib/ld-Linux.so.2(ld-Linux.so.2 dynamic linker name).

Here seems to compile other tools, but the next job is not so, but once again compiled bintuils and Gcc, and then once the first generation and the current generation of Glibc bintuils, Gcc to compile other tools, the whole environment was set up temporary success.

There is a problem and why you want to Bintuils Gcc compiler twice, the host can directly use the system? The first compilation bintuils and objectives on the one hand Gcc is to compile Glibc; the other is to be able to compile a second time Gcc, Gcc even have to be self-compiled. If the direct use of host systems to meet the requirements of building Glibc, but Gcc is not self-compiled. Here To ensure the manufacturing and the Gcc is self-compiled, so Gcc and Binutils are more than other tools compiled once.

Then the following additional tools are compiled using the second compilation of Binutils and Gcc and the first compilation of Glibc. So far, the tool chain is ready, we can use these tools to generate the final system. The first generation of the same software or Binutils and Gcc, but before compiling them, let's compile Glibc, which is what we ultimately need the C library. Chain adjustment tool again, and then let the compiler tools are connected to this library. Understandably, in front of the chain adjustment tool we will use the library turned to the newly installed library directories from the host system. Similarly, the tool chain will now be used in the library directory to the LFS final library catalog from the temporary library.

Other software systems are the latest compilation of Binutils, Gcc and Glibc compiled. The last is through some simple configuration system startup scripts, create fstab file, compile and install the kernel boot program, the final LFS system can be started.

Five, LFS extended

summarized generally above analysis procedure: the temporary tool chain built by the host system, and the ultimate target system constructed by LFS tool chain. After the completion of the LFS, can be compiled from the temporary environment. As we referred to herein are the same platform compilation, also mentioned earlier constructed a Temporary similar principle and cross-compiler environment, combined with the process we build the cross-compiler environment, if we set up a temporary set of tools is a cross-compiler environment, final you should be able to achieve the goal of a cross-platform system. Specific details that still need to be further explored course.

VI Summary

building directly from the source code for the Linux operating system, not only to customize their ideal operating system, more importantly, by constructing the LFS can enhance our understanding of Linux inside how they work. For people who wish to study the Linux system, it is necessary to study this construction method. At the same time, we should seize the opportunity to open source, serious study, and make its own contribution to promote its development.

References

[1] in Jing. Linux security is maximized. Electronic Industry Press .2000.5.P3.

[2] Gerard Beekmans.  Http://www.linuxfromscratch.org .

[. 3]  http://youbest.cublog.cn/  . From another perspective LFS-- reverse analysis LFS. 2006.6.

[. 4]  http://www.linuxsir.org/bbs/showthread.php?t=240687. LFS (version 6.1.1) installation experience.

Guess you like

Origin blog.csdn.net/xiebingsuccess/article/details/91855915