Some Preliminary Insights on the Linux Kernel Source
Many people have heard of Linux, as it’s very famous in the open-source community. However, not everyone knows how to configure, compile, and install/upgrade the Linux kernel. This article provides a brief introduction to the Linux kernel source.
Motivation
There may be several different motivations for learning the Linux kernel source. I was interested in the Linux kernel source because I wanted to understand how the Linux kernel works. I was curious about how the kernel manages hardware resources, schedules processes, and handles system calls. I also wanted to learn how to configure, compile, and install/upgrade the kernel. I think these are the basic skills that every Linux user should have.
Obtaining Linux Kernel Source
The Linux kernel source can be obtained from the official Linux kernel website: http://www.kernel.org/. The kernel source is released as a compressed tarball file, you may extract that and modify any parts as needed.
Compiling Linux Kernel
For the ubuntu/debian system, you can install the tools for compiling the Linux kernel by running the following command:
(root)# apt install build-essential libncurses5-devThen, you can compile the Linux kernel by following these steps:
-
Extract the kernel source tarball file
$ tar -xvf linux-${version}.tar.bz2 $ cd linux-${version} -
Configure the kernel
# Text-based interface $ make config # or, Menu-based interface (semi-graphical interface) $ make menuconfig # or, Graphical interface (requires X Window libraries) $ make xconfig -
Compile the kernel
# Confirm dependencies $ make dep # Generate the kernel image $ make bzImage # Generate the kernel modules $ make modules -
Install/Update
# install the modules (root)# make modules_install # install the kernel (root)# make install -
Update the bootloader configuration file (e.g., GRUB)
(root)# update-initramfs -c -k ${version} (root)# update-grub
Appendix
When configuring the kernel, there are many options to choose from, such as CPU-related options, kernel management methods, memory usage modes, plug-and-play support, and network protocol components. It is recommended to understand the meaning of each option before making changes; otherwise, you may compile a kernel that differs from your expectations. For more information on these options, visit http://www.tldp.org/.