Linux Kernel reduction and root file system customization (1) -------- Linux kernel reduction
Directory:
I. kernel Compilation
Ii. root file system Customization
Iii. kernel options
I. kernel Compilation
1. Preparations
(1) sort out the hardware, file system types, and network protocols to be supported by the system.
(2) run the uname-R command to check the system version. If your system version is the same as the kernel version to be compiled, back up the content under/lib/modules, otherwise, the file generated by the make modules_install step will overwrite the content in this path.
(3) download and decompress the Linux kernel, it is recommended to download the kernel from the http://www.kernel.org/pub/linux/kernel/, because the source code installed during the installation of the system supports many devices by default, this increases the difficulty of Kernel Cutting. Assume that you have downloaded the linux-y-z.tar.gz file. Generally, the Linux kernel source code is put under/usr/src. We still follow this habit. If the kernel version already exists under your path, we recommend that you change the name of the existing kernel.
2. Start Compilation
(1) make mrproper
Make sure that there is no correct. o file and file dependency in the source code directory. After executing this command, the kernel option will return to the default state. If you download the kernel source code and it is the first compilation, you do not need to perform this step.
(2) Make menuconfig
Select the kernel option in the text menu (make config, make xconfig, and make oldconfig commands with the same functions). different versions of the kernel may have different options.
This step is the key to kernel compilation. Select different options based on the required hardware, file system, and protocol. There are three options for configuration. Their meanings are as follows:
Y-compile this function into the kernel
N-no function added
M-compile the function into a module and dynamically load it to the kernel as needed
The principle of selection is to directly compile some functional code that is closely related to the kernel and frequently used into the kernel; compile some functional code that is far away from the kernel and is not frequently used into a loadable module, it is helpful to reduce the length of the kernel, reduce the memory consumption of the kernel, and simplify the impact on the kernel when the corresponding environment change of this function; do not select any features that are not required.
We use the space key for selection. Depending on the options, the result of pressing the Space key is also different: there is a "->" symbol after the options to enter the next menu; there are brackets before the options, switch between null and "*". Switch between empty, "*", and "M" before the option, you must select one of the provided options or enter a number or other symbols.
What? How can I select these options? Great sweat! This is a big problem and needs to be selected based on different needs. For example, you need to support USB keyboard, mouse or/and memory, support for multiple CPUs, support for NICs, serial ports, and TCP protocol, ext2 file system, NFS file system, and so on. I will introduce the kernel options in detail later.
(3) make Dep
Create the file dependency based on the options selected in the previous step.
(4) make clean
Clear unnecessary files. If you delete some options based on the previous compilation, we recommend that you perform this step. Otherwise, it is unnecessary.
(5) Make bzimage
Generate a kernel compressed file. If you confirm that your kernel is below kb, you can use make zimage instead of make bzimage. This step is quite time-consuming. You can add & after the command so that it can be executed in the background, or redirect to/dev/null, in this way, you will not see any character that is flashing on the screen. The compiled kernel is under./ARCH/i386/boot/and the file name is bzimage.
(6) Copy "/usr/src/Linux/ARCH/i386/boot/bzimage/boot/vmlinuz-x.y.z
(7) Make modules
Compile and load the module (that is, select m as the kernel option). The compilation time is related to the number of M options.
(8) Make modules_inatall
Copy the compiled modules to/lib/modules, which is why you are reminded of the backup in step 3 of "Preparation.
(9) CP/usr/src/Linux/system. MAP/boot/System-x.y.z.map
3. Modify the startup configuration file
Currently, grub is used to start. You need to modify/boot/GRUB/grub. conf and add the corresponding startup information. The simplest format of the content to be added is as follows:
Title name displayed on the Startup Menu
Root file system mount Partition
Kernel File Name compressed by Kernel
Initrd root file system file name
For example:
Title my new kernel
Root (hd0, 2)
Kernel/boot/vmlinuz-x.y.z
Initrd/boot/initrd-x.y.z.img
Question:
1. Only now can I find that I understand and write out what I understand. In the future, I have to work hard and write more.
2. In fact, these things can be searched in Google. I just sorted out the most essential things based on my own understanding for convenience.
3. The purpose of writing this article is to cut down the kernel some time ago and keep trying to make a knot. When I tried to work hard last Monday, I listed the questions. I didn't mean to lie or make free advertisements, the remaining content will also be posted later.
4. Thank you for your attention to this site. I hope you can leave your comments and suggestions, but please do not use the camera to take a picture of me. You can use RMB to take a picture ,:--).