Linux Kernel cropping-No module support

Source: Internet
Author: User
Document directory
  • 2.1 Linux Startup Process
  • 2.2 role of initrd. img
  • 2.3 grub. config file
  • 2.4 Analysis
  • 4.1 Linux Network Configuration
  • 4.2 Kernel Panic
  • 4.3 Ctrl + S
  • 4.4 SELinux latency
  • 4.5 make localyesconfig is unavailable
  • 4.6 Compilation speed is too slow
Linux Kernel pruning-No module Support 1 Requirement

1.1 complete Linux kernel customization without module support

1.2 The new kernel is successfully started on the centos Virtual Machine and can be logged on to the system.

2 principle 2.1 BIOS> MBR> OS loader> kernel> initrd> Application Manager> Application

2.2 role of initrd. img

As a carrier of the temporary root file system

Load the necessary drivers so that the kernel can access the real root file system

Attach a real root file system

Perform root switch and use the real root file system as the root startup

2.3 grub. config file

System Boot Program configuration file

Loading the kernel of the transfer control to the Operating System

Configuration File description:

Title-the name of the boot entry. The operating system name is usually used as the identifier

Root-disk partition of the operating system kernel and boot file. (Hd0, 0) indicates the first partition of the first hard disk, (hd0, 2) indicates the first partition of the first hard disk, and so on.

Kernel-parameters used by the system kernel and boot command.

Initrd-System Boot Program

2.4 Analysis

To customize the Linux kernel without module support, you do not need to use initrd. IMG: Compile the required disk drivers and file system drivers into the kernel of the system, and then modify the system configuration file to guide the system to find the location of the disk where the system kernel is located, finally, complete the system boot process to smoothly enter and log on to the system.

3 Process

3.1 configure menuconfig

Ø check module support

Ø load the necessary drivers: mainly load the drive and file driver of the disk and some general settings

3.2 compile the kernel

Run the make command in the kernel source code directory to compile and generate the compressed kernel image bzimage. The size of the cropped kernel is 15 MB.

3.3 install the kernel

Copy the generated bzimage to the/boot directory and rename it the vmlinuz-3.2.18.

3.4 modify the configuration file

"Root = UUID = ...." Manually changed to/dev/sdb2

Ø no external module location specified

3.5 restart select a new kernel to restart

3.6 continue cropping. The cropped kernel is compared with the original kernel.

4 Problems and Solutions 4.1 Linux Network Configuration

At the beginning, I learned nothing about Linux network configuration, and I am not familiar with virtual machine connection, Nat, host-only, and other methods. Although the virtual machine can automatically access the Internet at the beginning, however, you cannot connect to the Internet.

Bridge: the virtual network card and the local physical network card are a physical network that can connect to the Internet. The IP address in the same network segment as the external host must be configured inside and outside the virtual machine.

Host only: vmnet1 is a physical network and cannot be connected to the Internet.

NAT: it is a physical network with virtual network vmnet8 mapped to the Host IP address and external connection. The Gateway can only be configured192.168.10.2.

After configuring the internal IP address of a bridge connection, you need to configure the gateway and DNS server.

Route add default GW 192.168.10.254

Add nameserver8.8.8.8 in/etc/resolv. conf

However, even if I write bootproto in my configuration file and configure it as DHCP, the IP address cannot be automatically allocated, however, you can use seedclass WiFi in 304. This problem has not been solved yet, and it is okay to manually configure it each time.

4.2 Kernel panic

No accident. The first time we compiled the program, we encountered the kernelpanic problem.

This is because the root value is not correct, and it is strange that he did not listen carefully in class. After carefully reading the courseware, he found this problem.

Change root = UUID to root =/dev/sda1, but the same problem still occurs.

This indicates that the kernel has been loaded successfully, but the kernel cannot identify the content on the disk. So I added all the options about the SCSI driver in the configuration file and re-compiled them.

Later I thought that the added driver was incomplete, so I re-configured and re-compiled various searches in dmesg, but it still didn't work. This morning, some people told us that root =/dev/SD should be enabled.B2.

Some people on the Internet said that disk device files, such as/dev/SDA/dev/SDB, may be messy due to Linux kernel reasons, because it is a Linux kernel issue, there is no way to solve it.

However, if you think about it carefully, you still do not have a deep understanding of Linux, and there is no clear direction when looking for information on the Internet, so it is difficult to move forward after this point, in addition, the kernel Compilation Time is relatively long, so it is easy to exercise patience. However, the problem was finally solved successfully, but the newly generated kernel was a little large, 15 m, and not enough for cropping. Further configuration is required.

4.3 Ctrl + S

Use Putty to connect to Linux
Occasionally, CTRL + S is accidentally pressed during server-especially when editing with vim, it is always habitually saved by this shortcut key, but the entire session does not respond in an instant. At the beginning, I thought it was putty, so every time it was restarted, I re-connected to Linux.
Server. I didn't realize it was because I pressed this shortcut key.

In fact, when Putty is used, CTRL
+ S terminate the screen output (that is, stop ECHO). The content we typed is still valid, but it is invisible, this shortcut key is used to lock the content quickly with Ctrl + S. In fact, we only need to press Ctrl + Q to unlock it.

4.4 SELinux latency

This problem occurs only when the new kernel fails to be started. If you start the new kernel and then start the original centos kernel, this will happen.

The official explanation is as follows:

3. As the Linux rootuser, run the reboot command to restart the system. During the next boot, filesystems are labeled. The label process labels all files with an SELinux context.

However, this does not affect the system startup. After a period of time, the system automatically restarts and returns to normal, but it takes a little longer to start than usual.

4.5 make localyesconfig is unavailable

The kernel size is 15 MB after you use the default method and compare each option one by one. However, since you do not know many hardware devices, so many things are also very difficult to choose. Moreover, the cropping efficiency seems to be very low.

We can see from the Internet that we can use makelocalyesconfig and make localmodconfig to streamline kernel pruning. However, when I input the make localyesconfig command in my source code directory, this is the result, it is prompted that many modules cannot be found. This still occurs after the make allnoconfig command is used. I can't help but decompress the source code of linux3.2.18 and execute make localyesconfig.

In fact, when I used this command for the first time, I did not load the kernel module in the 3.2.18 kernel compiled by myself. Naturally, there is no way to load modules, however, when I switch to the kernel of the original system, I still cannot run the make localyesconfig command. So no reason is found for this problem.

4.6 Compilation speed is too slow

I have to mention the compilation of this experiment. The compilation speed is particularly slow because it is under the virtual machine and the computer configuration is not very good, during the first compilation, it took about three hours to compile the program. The computer is often motionless, that is, the CPU usage is 90%, and the memory usage is 90%.

At first, I didn't know that make can be incrementally compiled. Every time it was silly to make clean, and then make compiled the previously compiled modules again.

The Make-j4 option significantly accelerates compilation after multithreading is used.

After the Virtual Machine processor is changed to 4 cores, the speed is also improved to a certain extent.

5 experiment Summary

Through this experiment, I have deepened my understanding of the Linux boot process, and I have learned so much about the original simple boot process, in the past, I always started on Windows directly and shut down everything. So I realized that this series of processes still had a little sense of accomplishment.

Familiar with many common commands in Linux and the mode of interaction with Linux text: although I have been familiar with Linux before, it is only limited to the playing stage, there are still a lot of people who don't know how to use it. But when so many people are working together, the efficiency is still quite high. If you don't know how to use it, go to man and google, or ask the students and teachers around you. The problem is often quickly solved. Gradually, I feel that the interaction mode in Linux is quite efficient. Unlike in windows, the GUI improves the user experience, but the focus is usually not high.

Regarding the learning method, Mr. Zhong is right-don't be afraid of encountering problems. The more people who encounter problems, the more opportunities they have to learn. I used to be afraid of encountering problems, I always have no confidence in myself, worry that I cannot solve this problem, and worry that I will introduce more problems. In fact, I think it is wrong to think about the problem in the past. When I encounter a problem, I always habitually look for the answer directly, habitually tangle, instead of thinking rationally-why is this problem? How did this problem occur? What is the difference between the problems encountered by others and the problems I encountered? Why can they be solved successfully, but I cannot. That is to say, the solution to my problem is not based on the logic of reason, but with a large part of the competition. This is undoubtedly terrible for technicians. We will encounter many problems in the future. If there cannot be a good way of thinking, how can we keep it unchanged?

During the experiment process, different steps involve less of each other, so that the experiment will be smoother, from simple to complex, so that a complete knowledge system can be established gradually, it is also conducive to solving problems and learning more knowledge.

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.