Bare metal source Linux, do what you have never done (LFS + blfs for Linux cainiao)

Source: Internet
Author: User
Tags call back
I have been using Ubuntu for two years. From dapper-6.06 to the current hard-8.04 (it took only one month ). At the beginning, I felt that Linux technology was booming.
Progress is very slow after a period of time. I think I am a beginner at the cainiao level. I also think Ubuntu masks many Linux things. I only use its shell, and then press the mouse to beat my life.
. In addition, you don't even need to execute commands to use Ubuntu to install everything you have just created. Later, I learned how to use dpkg to compile and package the kernel. Later, I thought about whether it could be straight
Connected to a brand new machine (bare metal), how does one compile the kernel step by step from the source code to compile the entire system?
I searched for information online and soon found it. This is LFS (Linux from scratch, Linux from scratch ).
Relevant information is available on the Internet. The official website of LFS is

Http://www.linuxfromscratch.org

There is an English manual for analyticdb 6.3.
There is a Chinese translation manual of version 6.2 in China.

Http://lamp.linux.gov.cn/Linux/LFS-6.2/index.html

There is also a relatively good website in China:

Http://www.magiclinux.org

---------------------

I am here to explain a few simple questions (as a beginner's literacy) and several bugs in the 6.3 English official manual (to be noted ), for the rest, you can go to the above website.

1. I downloaded the Linux kernel source code in an operating system (such as UBUNTU). Now I can delete this operating system and start using this source code to start the machine?
A: Of course not. The source code is only a local file, and the machine recognizes only binary files (the. exe executable file under Windows XP). If the binary file is used to start the machine, it will have more strict requirements. You need to use a tool to compile the source code to make it a kernel binary file. At the same time, you need to perform some operations to use it to start the machine.

2. What is the principle of LFS? How is it done?
A: the basic principle of LFS is to use a bootable compilation-capable CD on an existing operating system with compilation capability (or development capability, compile a new development environment, compile related programs and kernels in this new development environment, and then start the machine with this kernel.
For more information, see the official manual.

3. I have already compiled and installed the kernel in Ubuntu. What is the difference between this and the kernel installed in LFS mode?
A: The kernel you compile and install in Ubuntu uses the Ubuntu compilation tool and library file. When you start with this kernel, you also use the application programs and tools in Ubuntu, therefore
Compared with LFS, there are some "unauthentic" or "old man ". In addition, the process of compiling the kernel in Ubuntu is so simple that make-kpkg can be used to easily create the kernel. In addition to being familiar
You can hardly learn anything other than the core configuration options. Of course, it doesn't mean that compiling the kernel in Ubuntu is not important. On the contrary, this is a key step towards LFS. Because Linux Kernel
To be familiar with the menu is a huge job.
If you have learned how to compile the kernel, LFS is familiar to you. It doesn't matter if you haven't learned it. You can do the work step by step.
How to compile the kernel in Ubuntu, you can see this: http://forum.ubuntu.org.cn/viewtopic.php? F = 50 & t = 34172

4. Isn't LFS also using the existing development environment? What is the difference with the above mentioned?
The difference is that LFS uses the existing development environment to build a new development environment, and then uses this new development environment to compile the kernel and related programs. When you finally start the machine with a new kernel, everything in the machine is compiled step by step from the source code. Nothing is directly used on Ubuntu.

5. Here is a detailed explanation of LFS:
All applications in Linux are composed of configuration files (ETC), library files (LIB), and program files (BIN. To generate this application, you need the source code and a development environment consisting of connectors, compilers, and library files.
The compiler compiles the source code into binary code, which is also a program, so the library file is required. The connector tells the Compiler which library file to connect to and outputs the compiler results to the machine for execution. Connector book
It is also a program and also a library file. Therefore, we can know that library files are very important. In LFS, the library file is glibc, the compiler is GCC, And the connector is binutils (it is a program
Package, where the program actually used for connection is LD ).

LFS operation process:
Assume that your current environment is a, the development environment is B, and the final environment is C.
In the beginning, connector B is first created using the library file a/compiler A/connector.
Here I represent: LIB-A + GCC-A + LD-A ==> LD-B

Then, use the library file a/compiler A/connector B to generate compiler B.
That is: LIB-A + GCC-A + LD-B ==> gcc-B.

Then, use the library file a/compiler B/connector B to create the library file B.
LIB-A + GCC-B + LD-B => LIB-B

Since both the compiler GCC-B and connector LD-B use the LIB-A of the original system, it is not "purebred. The newly generated library LIB-B in the translation of the LD-B and GCC-B, will be a redirection, so that it does not rely on the original system library, so it is relatively "pure. Be sure to pay attention to this! This is a critical turning point.
The new library file only depends on the new kernel header file you want to compile. At the same time, you must realize that the library file you compiled will not depend on or use the original system unless you have not specified the kernel header file for it, because the library file is not a "program "!

At this time, the compiler B/connector B/library file B is ready. But we know that this compiler and connector are not authentic. "Filter:
At this time, use compiler B to use library file B to re-compile compiler B, this time using the new authentic library file B.
LIB-B + GCC-B + LD-B => GCC-B2
Then the connector
LIB-B + GCC-B2 + LD-B => LD-B2
The new compiler and connector use the new library file. We can think of them as authentic. In fact, they are now out of touch with the original system.

Next, we will use a virtual root environment. This is a hardware operation that uses the existing system, but all programs, libraries, and configuration files are independent of the original system environment. This environment is used because the kernel
It has not been compiled, and many applications have not yet been compiled, so the machine cannot start. In order to use this virtual root environment, will use LIB-B + GCC-B2 + LD-B2 this development tool compiled a lot of new
Program.

At this time, I don't know if you will ask: since a new set of tools has come out, I just need to compile the kernel directly? Still so troublesome? Yes, I thought so at the beginning, and at the same time. I also recommend that the curious Linux fans do this to see what the result is.
As a result, I can tell you that the kernel is compiled or can be started, but there is no way to control it. Why? Because you do not have the bash console.
Didn't you suddenly realize: Oh, my God, I thought a kernel could be fully started and operated!

The kernel is started, and an INIT program is required for initialization.
This init is the so-called "root process ". Without this program, all programs cannot run. Then the process starts to mount and run the corresponding program. For example, Bash. Bash does not work.
Bash is just a shell. It does not have anything. For example, we often call the LS command. Because ls itself is a program file! There are also mkdir and other commands, all
All are program files, none of them. There is no way to control the machine. Therefore, all these programs must be compiled from the source code.

At this time, you may also ask why to use the virtual root environment? Why can't I compile it directly in the current environment? I am using a new development tool.
The reason is: if you do not set up well, the new development tool may still use the original system, or even install the compiled program to the original system, this can damage the original system. Of course, if you are
It is okay to know how to set each item, but if you have such a level, your estimation is already your own LFS system. To avoid unnecessary troubles (such as relocation programs and connectors)
To use the virtual root environment and directly isolate it from the original system.

With the virtual root environment, the library file will be compiled again. This is because the previously compiled LIB-B is relocated somewhere else (the trouble of visible relocation ),
You need to compile a new unrelocated library file and install it in the default place so that your program can use it in the future. Lib-C is generated.
LIB-B + GCC-B2 + LD-B2 ==> Lib-C.
Then, compile GCC and LD to remove their previous relocations.
LIB-C + GCC-B2 + LD-B2 => LD-C
LIB-C + GCC-B2 + LD-C => GCC-C

At this time, the final development environment is finished.
Now, compile all the programs required for Kernel startup. Such as init and bash. Finally, compile the kernel. After grub is set, use the new kernel and program
Start the machine. At this point, all LFS work has been completed.

6. Some bugs in the lfs6.3 manual and the key points to be noted during LFS
First, you need to pay attention to your environment variable path. You can run the following command:
Echo $ path
. If you have created/mnt/LFS/tools and/tools like the LFS manual, make sure that:
Before entering the virtual root environment, the first path must be/tools/bin,
For example:
Path =/tools/bin:/usr/bin
Is correct.
After entering the virtual root environment, the path/tools/bin must be the last one.
For example
Path =/bin:/usr/bin:/tools/bin
The reason is that path determines the priority of the system when calling the application. For example, if there are two GCC instances in the system at the same time, it will first use the one with path at the top. This is used for redirection in LFS. If the order is wrong, the wrong program will be used and the subsequent steps will fail.

The first line of the official manual in Chapter 4th "setting the work environment. the path is not set in the bash_profile file. This is a serious error. As a result, I failed to compile the file for the first time and found the cause after a long time.
Therefore, make sure that your path is correctly set at any time.

Second, you need to note that if you use an update kernel instead of the 2.6.22 kernel officially provided, for example, 2.6.26.4. So
The header files of these two kernels are different. Among them, the 2.6.26 kernel missing a page. h header file in the ASM/directory. This file is used by Perl.
So I copied this file to cheat Perl. The new kernel uses different mechanisms, so it is estimated that the fake header file can be deleted only after perl6 is released.

Third, the official manual is version 6.3, and the Chinese manual above is version 6.2. There are some places that are not the same. So pay special attention to it.
Fourth, do not use root for operations. This is to prevent errors from destroying your current system. For example, if I enter the/mnt/LFS directory and want to delete the bin directory, I have Rm-fr
/Bin: If you want to delete the file, the system prompts that the permission is insufficient. Then I found out that I played the/bin instead of the bin. The former is the bin directory under the "root directory", and the latter is the bin directory under the "current directory ".
The two are quite different! I am glad that I use another user name instead of root. Otherwise, the existing system will crash directly because of the loss of key binary files! If you don't believe it, try it!

Fifth, to improve the success rate, it is strongly recommended to use the official LFS livecd6.3 for work. It contains all the required software. And even if you accidentally delete the system, it doesn't matter because the disc is read-only and will be restored after restart. (Input startx after the disc is started to enter the graphic interface)

Okay. After your efforts, you finally completed your Linux system. I don't know the number of wrong operations, but I don't know how many times I guess in English. The process is very hard and the result is very happy.

What are the advantages of the new system compared with the original system?
Speed! Speed!
My laptop is Asus, MB memory, Intel pentinum m
735. Is the configuration very Spam? But it took six minutes to compile the Linux kernel. When I used make-kpkg in Ubuntu to compile the kernel,
It took 4 hours for a machine of MB. MB memory, dual-core CPU Lenovo brand machine used 35 minutes. This is the difference.
Another difference is the small size. My new kernel only has 2.7 MB, and other applications only have 40 to MB. Of course, it doesn't matter if the hard disk is big now.

Next, you may not be satisfied, because the current system is in the command line mode and does not have a graphic desktop or webpage (without w3m installed ).
Then, go to the next chapter: blfs, beyond Linux from scratch, surpassing LFS.
Blfs teaches you how to configure the system, install related software, and build an X desktop platform after creating LFS. This chapter is flexible and extensive. After you have the LFS foundation, it is a simple task.
One thing you need to talk about is that if you don't want to install the KDE and gnome desktops, but xfce desktops, for example, me, you can download the software package from www.xfce.org and compile and install one item. If you want to use the scim Input Method in xfce, you can find it on the Wiki of blfs.
For a person who has installed Linux from the source code, installing and using scim is just a good skill.
Install the corresponding scim webpage:
Http://wiki.linuxfromscratch.org/blfs/wiki/InputMethods

Tips for blfs:

If you want to use your own LFS instead of livecd at this time, you must first install the web browser w3m. Because the LFS itself does not have a web browser installed
You cannot use a graphical browser. You can view the Wiki on Ubuntu for browser usage. To install w3m, you need libssl and libgpm.
Ubuntu.cn99.com/ubuntu.download. I installed the dpkg software first and then directly installed the Deb package with dpkg.

How to copy and paste data in text mode:

When you use w3m to read the blfs manual in English, you may find that this command is quite long and you want to copy and paste it. I did this: Save the current web page to the temp.txt file and switch it to the console.
(You can also use Ctrl + Z to throw w3m to the background. After the operation is complete, use the FG command to call back w3m. However, I like to switch to the console. There are 6. Use CTRL + ALT + F1-F6 to cut ),
After the console is switched, use vimto open temp.txt and use the V key for visualization to select the appropriate command. After the selection, use W temp to write the temp file (if temp already exists, use W!
Temp forced write), then Ctrl + z put Vim to the background, use the command Source
Temp runs the Copy command. Don't forget that Vim is still in the background. You can call FG and copy and run all the commands on this webpage.

Are you very big? Copy, paste, and run the command. Why? Maybe I didn't find a better method, but I thought it was not slow after I became familiar with it, because Vim itself is a very quick editor for operations. If someone finds a better method, post it to share it with you.

Finally, you may want a system similar to Ubuntu. You can use dpkg and apt to manage software packages. That's what I thought at the beginning.
So I installed dpkg, but I couldn't run it. I needed the sysv Package content. So I downloaded the sysv package and found that only the. Deb package had no tar package. It took a long time to get it.
Dpkg cannot be used, but dpkg-Deb can be used to solve the Deb package (dpkg-Deb-x command ). Decompress the package and copy the relevant program.
Dpkg is ready for use! It runs exactly as in Ubuntu. After installing the package, you can use dpkg-L to clearly list all installed software packages.
We use the Ubuntu version for wget and w3m on our system (we recommend that you use the dapper version, and the updated glibc version for the hard version, which means you need to compile new library files ),
However, the apt I installed cannot be used, prompting that the system package type cannot be identified. If you cannot use apt, and just use dpkg to install x Desktop, it means you need to download more than 300. Deb
Package ....
Later I read the source code of APT and found that there is a section in init. CC that judges the system. I want to get rid of the kernel version code (changed to Ubuntu) to cheat apt and fail.
I want to get rid of the apt code, but the changed Code cannot be used because my c ++ level is so bad. You have to stop installing apt later. If your c ++ is so powerful, it is not a problem.
Even if there is no apt, it is good to use dpkg to install some simple packages.

It is the charm of Linux to do things you have never done before. Finally, I wish the majority of beginners a better chance of success!

PS:
My LFS ranks 20180 in the official site. After finishing blfs, I registered a 20220-bit domain... There are not many people engaged in LFS around the world.
Linux-Sir is the best Linux site in China I have ever seen. Only foreign English websites can surpass its level. It's just a long time. It's estimated that it's a great talent, haha.

Change the article reprinted to the http://www.linuxsir.org/bbs/thread335436.html ti8er member that post

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.