This is the 28th day of my participation in the Gwen Challenge

Download the Linux Kernel source code

Go to www.kernel.org/ and select a version to download. You can download the package through HTTP or Git, or upload it to Linux through FTP for decompression.

Here select HTTP mode download (wget always time out… Choose manual download and upload)

Wget -c https://mirrors.edge.kernel.org/pub/linux/kernel/v4.x/linux-4.4.49.tar.gzCopy the code

Create a kernel folder under /usr/src, upload the downloaded compressed package to the folder, and decompress the package

The tar xf Linux - 4.9.179. Tar. GzCopy the code

View the source directory

  • Arch: Projects related to hardware platforms, mostly referring to CPU categories such as x86, X86_64, Xen virtual support, etc.
  • Block: Configuration data related to a group of devices. Block data usually refers to a large amount of storage media, including whether file systems such as ext3 are supported or not.
  • Crypto: Encryption technology supported by the core, such as MD5 or DES, etc.
  • Documentation: A collection of Documentation related to the core.
  • Drivers: Some hardware drivers, such as display adapters, network cards, pCI-related hardware, etc.
  • Firmware: Microscript (firmware) data for some older hardware.
  • Fs: Filesystems supported by the core, such as VFAT, ReiserFS, and NFS.
  • Include: Headers that define data that can be called by other processes.
  • Init: Some core initialization functions, including mounting and init program calls, etc.
  • Ipc: Defines the communication between programs in the Linux operating system.
  • Kernel: define the core program, core state, thread, program schedule, program signle, etc.
  • Lib: Some function libraries.
  • Mm: data related to memory units, including swap and virtual memory.
  • Net: the protocol data related to the network, as well as firewall module (net/ipv4/netfilter/*).
  • Security: Security Settings including selinux, etc.
  • Sound: Modules related to sound effects.
  • Virt: information about virtualization machines. Currently, the core supports the Kernel Base Virtual Machine (KVM).

2. Preparation before compilation

You can run the make help command to view all compilation parameters of make.

1, make mrproper: remove any residual object files and configuration files from the source code. This action will remove the core feature selection file that has been done before, so this action is done before the first core compilation. At other times, to remove residual data from the previous compilation process, simply make clean

/boot/ make XXconfig: /boot/ make XXconfig: /boot/ /usr/src/kernel/{uname -r}/ generates a.config file called /boot/config-xxx under the /usr/src/kernel/{uname -r}/. The file can be created as follows

(1) Make Menuconfig: the most commonly used way is to display a graphical interface under the text mode. You can select core function options without starting X Window.

(2) make oldconfig: make oldconfig by using the existing./. Config file content, use the set value in the file as the default value, only list the new function options in the new version of the core for users to choose. Can simplify the selection process of core functions, as a function of the upgraded source selection, is very easy to use.

(3) make xconfig: use X Window to display graphics interface based on Qt, for example, KDE is designed by Qt X Window, so you can use this command if you are in KDE screen.

(4) make gconfig: display through the graphical interface based on Gtk, which needs the support of X Window. GNOME, for example, is an X Window designed through Gtk, so you can use this command if you are in a GNOME screen.

(5) Make config: the most old-fashioned method of function selection, each item is listed one by one for you to choose, if the setting is wrong, you can only choose again, which is very inhumane.

/boot/config-xxx /usr/ SRC /kernel/linux-4.9.179/

3. Select Make Menuconfig for the core function, and the following interface appears

(1) [left and right selection key] : You can move the bottom,, item. (2) [up and down arrow keys] : you can move the white light column in the upper part of the big box. If there is an arrow (– >), it means that there are other fine items need to be set inside the line. (3) Select the project: [up and down key] select the project you want to set, [left and right key] select, press [Enter] can Enter the project to select the sub-project.

(4) Optional functions: the item is optional when preceded by [] or <> symbol. Use the space bar to select items.

(5) If it is [], <>, it means compilation into core; if it is, it means compilation into module.

(6) For the selection of core functions, please refer to the following rules

  • [Affirmation] The core must function, directly compiled into the core.
  • [may be used in the future] function, try to compile into modules.
  • Keep the default values, or compile them into modules.
  • In short, keep the core as small and beautiful as possible, and the rest of the functionality is compiled into modules, especially with future scalability in mind.

4. Selection of core functions (if not clear, please press < Help> for reference)

Compile and install

1. Compile core and core modules

  • Make VMLinux: Uncompressed core
  • Make modules: Core modules only
  • Make bzImage: compressed core (default)
  • Make all: Perform the above three actions
  • The common ones above are Modules and bzImage, which can make compressed cores.

2. Start compiling

  • Make -j 4 clean
  • Make -j 4 bzImage
  • Make -j 4 modules Recompile the module
  • Make -j 4 clean bzImage modules Make -j 4 clean bzImage modules
  • Was finally made the data stored in the/usr/SRC/Linux kernel / – 4.9.179 / arch/x86 / boot/bzImage, this is a core file.

After executing the make -j 4 bzImage command, if successful, the following screen should appear

3. Start installing the core

Once compiled, we can install it, keeping the old core and adding our own compiled core to the host. Make multiple boot systems. But the new core doesn’t always fit perfectly on our system, so we can back up the old core and start with it if the new core doesn’t pass the test.