1. Kernel introduction and get kernel source code 1.1 what is a kernel
- Kernel: the kernel (kernel) is the lowest level of the entire operating system, he is responsible for the entire hardware drive, as well as providing the necessary kernel functions of various systems, including the firewall mechanism, whether or not to support the file systems such as LVM or quota. If your kernel doesn't recognize an up-to-date hardware, it can't be driven, and of course you won't be able to use that hardware. In fact, the kernel is the system above a file, this file contains the drive host hardware detection program and Driver module. kernel files are usually placed in the
/boot/vmlinuz
directory
- The purpose of the kernel module (Kernel module): To separate some of the less common driver-like things out of the kernel, compiled into a module, without replacing the kernel, recompile the kernel, the kernel can load the system during normal operation of the module to the kernel support. The directory to be placed is
/lib/modules/$(uname -r)/kernel/
1.2 Why update the kernel
The kernel's compilation focuses on what you want your Linux to do. If you don't have the necessary work, you don't need to add it to your kernel! This will allow Linux to run more steadily and smoothly. This is the main reason why we have to compile the kernel .
- possible purposes for kernel compilation:
- Requirements for new features
- Originally the kernel was too bloated.
- And the stability of hardware collocation
- Other requirements (e.g. embedded systems)
Recompiling the kernel is a step that can be optimized for your hardware, but since these optimizations have a small impact on overall performance, if you are compiling the kernel in order to increase performance, basically, the benefits are modest. However, if you are considering system stability , there is a good reason to recompile the kernel. Since the main work of the kernel is to control the hardware, before compiling the kernel, please first understand your hardware equipped with the future functionality of your host. As the kernel is simpler , the better, so just to the future function of this host to him into the good.
1.3 Decompression, installation and observation of the kernel source code
- Extract and drop directories for kernel source code: Kernel Primitives are generally recommended to be placed under the
/usr/src/kernels/
directory. tar -jxvf linux-X.X.XX.X.tar.bz2 -C /usr/src/kernels/
. At this point, a new directory is created under/usr/src/kernels, which is the linux-x.x.xx.x directory.
- The secondary directory under the kernel source code:
- Arch: Projects related to hardware platforms, most of which refer to the categories of CPUs, such as x86, x86_64,xen virtual support, etc.
- block: Set data that is more relevant to a group of devices, and chunk data usually refers to a large amount of storage media. It also includes support for file systems like ext3 and so on.
- Crypto: cryptographic techniques supported by the kernel, such as MD5 or DES, etc.
- documentation: A bunch of documentation about the kernel, if you have a great interest in the kernel, look here.
- drivers: Some hardware drivers, such as display adapter, network card, PCI-related hardware and so on;
- firmware: micro-scripting (firmware) data for some legacy hardware;
- FS: Filesystems supported by the kernel, such as VFAT,REISERFS,NFS, etc.;
- include: some header (header) that allows other procedure calls to define the data;
- Init: Some of the kernel initialization functions, including the call to mount and INIT programs, etc.;
- IPC: Defines the communication of the programs within the Linux operating system;
- kernel : Define kernel program, kernel State, thread, program schedule (schedule), program signal (SIGNLE), etc.
- Lib: some function libraries;
- mm : Various data related to the memory unit, including swap and virtual memory;
- NET: Various protocol data related to the network, as well as Firewall module (net/ipv4/netfilter/*) and so on;
- Security: Safety settings including SELinux, etc;
- Sound: Various modules related to audio;
- virt: Information related to virtualized machines, currently supported by the core KVM (Kernel base virtual machine)
This data is roughly an impression, at least in the future if you want to use patch methods to add additional features, where you want to put your source code, here can provide some guidance. Of course, it's best to go to the documentation directory and look at the correct instructions, which will be more helpful for your kernel compilation.
2. Kernel-compiled pre-processing and kernel feature selection
The purpose of the kernel is to manage the hardware and provide the core functions of the system, so you must first find your system hardware and plan the future tasks of your host so that you can compile the kernel for your host. So, the important task of compiling the whole kernel is to pick the function you want .
2.1 Hardware Environment review and core functional requirements
- Hardware environment View: Observation by/proc/cpuinfo and LSPCI
2.2 Keep Clean source code: Make Mrproper
After knowing the hardware-related data, we have to deal with the residual files under the kernel source code. If we were to compile for the first time, but we do not know whether the source code to download the *.O and the corresponding configuration file exists, at this time we can use the following command to dispose of the compilation process of the target files and configuration files make mrproper
:
This command will delete the core feature selection file you have done before, so this action is only performed before the core compilation is performed for the first time, and the rest of the time you want to delete the residual data from the previous compilation process, just to release:make clean
2.3 Start picking core features: Make Xxconfig
There is a file named Config-xxx under the/boot/. That file is actually the core feature list file. What we are going to do here is actually making that file. And what we're going to do with the compilation, in fact, is to do it through this file. The selection of core functions will eventually result in a hidden file called. config, which is the file of/boot/config-xxx./usr/src/kernels/linux-x.x.xx.x/. There are a number of ways you can build this file, and the common methods are:
- Make Menuconfig: The most commonly used is the way the graphical interface can be displayed under Text mode, without the need to start X Window to pick the core menu
- Make Oldconfig: by using the existing./.config archive content, using the set values in the file as the default, the new feature options in the new version core are listed to let the user choose, can simplify the selection process of core functions! It's a great project to choose from as a feature after upgrading the core source code!
- Make xconfig: The display of the graphical interface using QT as the graphical interface function requires the support of X window. For example, KDE is the x Window designed through QT, so you can use this item if you are in the KDE screen.
- Make gconfig: display with the graphical interface based on GTK's graphical interface functionality requires X Window support. For example, Gnome is the X Window designed through GTK, so you can use this item if you are in the GNOME screen.
- Make config: The oldest feature selection method, each item is listed in a bar-by-column list lets you choose, if the set error can only be selected again, not recommended.
2.4 Core features detailed options configuration reference "Brother Bird's Linux private dish" 3. Kernel compilation and installation 3.1 compiling kernel and kernel modules
- Kernel and kernel modules need to be compiled first, you can use make help to look up all the available compilation parameters, you will know that there are basic features below:
- Make Vmlinux #未经压缩的核心
- Make modules #仅内核模块
- Make bzimage #经压缩过的核心 (Preset)
- Make all #进行上述的三个动作
- Basically we'll do the following:
- Make Clean #先清除暂存档
- Make Bzimage #先编译核心
- Make Modules #再编译模块
3.2 Actual Installation Module
We know that the module is placed in the/lib/modules/$ (uname-r) directory, and if the same version of the module is repeatedly compiled and then installed, it will create a conflict. Workaround:
- Rename the old module catalog before installing the core module to the target directory.
- When make Menuconfig, the local version in the general setup is modified to the new name
Install the module to the correct target directory make modules_install
: You will eventually build your core-related module under/lib/modules.
3.3 Starting the installation of the new core and multi-core menu (GRUB)
- Move the core to/boot and keep the old core archive
cp /usr/src/kernels/linux-X.X.XX.X/arch/x86/boot/bzImage /boot/vmlinuz-X.X.XX.XXXX
#实际内核
cp /usr/src/kernels/linux-X.X.XX.X/.config /boot/config-X.X.XX.XXXX
#备份配置文件
- Establish the corresponding Initial Ram Disk (INITRD):
mkinitrd -v /boot/initrd-X.X.XX.XXXX.img X.X.XX.XXXX
- Edit boot Menu (GRUB): Edit /boot/grub/menu.lst(Specific configuration reference)
Summary: Kernel compilation steps and kernel deletions
- Steps for Kernel compilation:
- Download the kernel source code first (e.g. SPRM)
- The following is handled by Tarball, unlocking the original code to the/usr/src/kernels directory
- Delete old data first: Make Mrproper
- Start selecting core functions that can be used
make menuconfig
, make oldconfig
and make gconfig
so on
- Clear the past intermediate scratch disk data:
make clean
- Start the kernel file and Kernel module compilation:
make bzImage
,make modules
- To start the installation of the kernel module:
make modules_install
- Start the installation of the kernel files, you can use the way:
make install
or manually copy the core files into the/boot/grub
- establishment of INITRD archives;
- Modify/boot/grub/menu.lst Archive
- Removal of kernel:
- First, you can delete the source code: RM-RF/USR/SRC/KERNELS/LINUX-X.X.XX
- Then, remove the directory of kernel modules: rm-rf/lib/modules/x.x.xx
- Finally delete the kernel files and initrd files within the/boot/, as well as the title of the/boot/grub/menu.lst within the training.
"Brother's Linux Private cuisine" Reading notes: Linux kernel compilation and management