
What is Linux Kernel Compile Principles?
Mert Kuzer
R&D Engineer
Aktif Mühendislik
The main purpose of kernel compilation is to provide hardware support and software support that you do not need, or to add the software and hardware tools you need. This article will briefly explain the Linux kernel’s history&structure and then explain how to compile it.
I. INTRODUCTION
In 1945, the first computer, ENIAC, was produced, to mention the historical developments. With the production of ENIAC, many new computers and software have begun to be produced. One of these software produced in the 1970s is Unix. Unix is free at first, but has been licensed and paid over time. For this reason, users have started to write their own operating systems in response. In 1983, the project “GNU is Not Unix” was developed by Richard Stallman. When this project is created, the kernel structure is insufficient. Thus, in the 1990s, Linus Torvalds wrote Kernel and the GNU project was named GNU / Linux. As a result of these developments, the first Linux version was released to the market in 1991. This operating system, which has been up to date, is still in use and is one of the most preferred.
Linux operating system has TCP / IP support for internet connection. Protocols such as NetBEUI (Netbios Extended user interface), Samba (a protocol that Windows machines use to talk to each other), and Appletalk (a protocol that Macintosh machines use to talk to each other) are supported.
Thanks to these protocols, there are thousands of users connected to the Internet, browsing the web pages, running on the graphic screen and compiling programs.
Starting with version number 2.0 Linux kernels can support multiple processors.
Because Linux is open source, it has been developed by many different groups. Because of this, the Linux operating system has many distributions. The most known of these are; Ubuntu, Fedora, Pardus, OpenSUSE, Redhat, Slackware. General information about Linux history protocols and operating system is given in this section.
In this article, we will talk about the kernel module structure of Linux in the second part and how to make the compilation process in the third part.
II. KERNEL MODULE STRUCTURE
In this section, firstly the Linux kernel will be mentioned and then will mention to the kernel module.
We mentioned in the previous chapter that the Linux kernel was originally developed by L. Torvalds. Later, developers and users of this operating system have contributed to the development of the code by adapting the original software projects.

In a Linux operating system, all other components are built around the kernel, with interface and the operation of the computer’s hardware and programs are provided on it. Linux kernels are in a continuous development phase, fixes and releases are regularly published.
If you want to learn the Linux kernel version on a computer running GNU / Linux, you can do this by typing “uname -r” at the command line.
If we talk about module structure, modules are software developed with the C programming language. It looks like an ordinary program. We can use this program by adding it to the kernel of Linux. Files and directories of kernel modules are located in / lib / modules and loaded when the system is open.
Modules can be written to add different functions to the kernel. These modules can be added to the kernel without shutting down the system.
III. KERNEL COMPILE PROCESS
First of all, with the help of virtual machine program Virtualbox or VMware, the Debian operating system is installed on the virtual machine. The latest version of the kernel, 4.14.4-ls is downloaded to the Debian operating system by entering the kernel.org site with a web browser. This process step is shown in figure 2.

If you want to download from the command line, you can use the following command.
“wget https://cdn.kernel.org/pub/linux/kernel/v4.x/linux-4.14.4.tar.xz”
The downloaded “Linux-4.14.4.tar.xz” Firstly, terminal is opened to operate with the downloaded “Linux-4.14.4.tar.xz”. First, manager login is done. For this operation, “sudo su” command is executed and the set password is entered during installation.
After logging in, the downloaded kernel version is copied to the process directory. The code required for this operation is;
“cp /home/user/İndirilenler/linux-4.14.4.tar. xz /usr/src”
After copying is complete, we can start by using “cd / usr / src” and then “tar -xf linux-4.14.4.tar.xz” to extract the downloaded kernel version’s file. After the file is extracted with this operation, the directory is entered by executing “cd linux-4.14.4” command.
First, the command “make mrproper” is executed to delete the pre-configured old settings. When the cleaning process is completed, the menu of time configuration is opened. From this menu, you can select, add or remove modules required for your system. The necessary adjustments can be made by running the “make menuconfig” command to get to the setting window.

The changes are saved. To compile the kernel image, first execute “make bzlmage” command. Creating this “bzimage” can take 25 to 30 minutes, depending on the speed of your computer.

Module compilation is performed after this command is finished. The compilation process is completed by running the “make modules” command. This is the longest duration of the compilation, which can take 2-3 hours on average. Once the modules are compiled, they must be loaded into the system. For this procedure “make modules_install” command is used.
The kernel modules must be installed for connection of root filesystem. The required code for this “mkinitramfs 4.14.4 -o /boot/initrd.img-4.14.4-generic” is executed.
The kernel image is copied to the “/ boot” directory with the command line “cp /usr/src/linux4.14.4/arch/x86_64 /boot/bzImage/boot/vmlinuz-4.14.4-generic”.
We need to copy the System.map to the /boot directory. The command we will use for this process “cp System.map /boot/System.map – KERNEL_VERSION”. To ensure that the generated map file is linked with system.map, type “ln -s /boot/System.map-KERNEL_VERSION / boot / System. map “ command is used.
As a result of these operations, we have performed kernel compilation. But there are a few steps that need to be done so that we can use the kernel we have compiled.
Firstly, write permission is granted with “sudo chmod +w /boot/grub/grub.cfg” command. Then “sudo nano /boot/grub/grub.cfg” command is executed to change the “group.cfg” file settings.
The line that opens in the opened window is the line “### BEGIN /etc/grub.d/10_Linux ###”. The addons made are clearly visible in figure 3.

UUID is the other section which will be edited. In this case, a new terminal is opened and the “sudo blkid” command is executed. The file “grub.cfg” needs to be updated. In the “dev / sda” part of the “ext4” type where Debian operating system is installed, if “sda” is written, hd0 “sdb” hd1 must be done. After that, the UUID value is taken and written it to the ID values in the grub.
As a final step, the Grub settings should be compiled. This is done by running the “sudo update-grub” command. When the process is completed, the system is reset by the “reboot” command. When it comes to the boot screen, the debian kernel which is 4.14.4 kernel is selected in kernel version. The kernel has been compiled. You can check this by running the code “uname -a”.
IV. RESULT
In this article, the history, development and kernel structure of Linux are mentioned. Finally, the kernel compilation process is described in general steps. With this article, you can compile your Linux kernel compilation.