Article Directory
- Linux kernel compilation and adding system call steps
- 1 Check the old kernel version
- 2 Source code
- 3 Enter root permissions
- 4 Unzip the source code and place it in a specific folder
- 5 Add system call
- 6 Install each prerequisite package
- 7 Clear the remaining .config .o files
- 8 Configure the kernel
- 9 Compile the kernel
- 10 Compile module
- 11 Install kernel and modules
- 12 Configure grub bootloader
- 13 Clean intermediate files
- 14 Restart
- 15 View kernel version
- 16 Delete old kernel
- 17 Test the system call you added
Linux kernel compilation and adding system call steps
The author is using ubuntu18.04 , compile and install the kernel linux-5.3.17 version
1 Check the old kernel version
Compare with the new kernel version after installation
uname -a
2 Source code
https://www.kernel.org/
download the source code to any folder of ubuntu
3 Enter root permissions
Prevent errors caused by insufficient permissions
su
4 Unzip the source code and place it in a specific folder
-J Use the xz algorithm to compress and decompress files
-x Decompress
-f Required parameters
-C Specify the folder to decompress
tar -Jxf linux-5.3.17.tar.xz -C /usr/src/
5 Add system call
A total of 3 steps, set the added content yourself
1. Assign system call number and modify system call table
gedit ./arch/x86/entry/syscalls/syscall_64.tbl
2. Declare the system call service routine
gedit ./include/linux/syscalls.h
3. Implement the system call service routine
gedit ./kernel/sys.c
6 Install each prerequisite package
When compiling and installing the kernel, you need some software packages, install them in advance to prevent errors later
apt install libncurses5-dev make openssl libssl-dev bison flex
7 Clear the remaining .config .o files
Clear the .config .o file left over due to the last compilation error, if it is the first compilation, it can be skipped (of course, there will be no problems when running the command)
cd /usr/src/linux-5.3.17
make mrproper
8 Configure the kernel
Configure the kernel options, all can exit exit by default
make menuconfig
9 Compile the kernel
-j6 compiles with 6 CPU cores, and redirects the output errors to the error.log file for easy viewing.
Of course, if there are only two cores, changing to -j2
is the most time-consuming stage, which requires about 1. 2 hours. The author i7 9th generation, 6 core compilation for 40 minutes, as a reference
// make -j6 2> error.log
make -j2 2> error.log
10 Compile module
About 10 minutes
make modules
11 Install kernel and modules
Install the module first and then install the core for
about 10 minutes
// 安装模块
make modules_install
// 安装内核
make install
12 Configure grub bootloader
update-grub
13 Clean intermediate files
Clear the intermediate files. O files, these files take up a lot of space, and have no meaning for subsequent experiments
make clean
14 Restart
reboot
15 View kernel version
uname -a
16 Delete old kernel
su
// 查询并删除旧内核
dpkg --get-selections|grep linux
apt purge ....
17 Test the system call you added
Write a C language program, request the operating system service routine through the system call number