Article Directory
- LINUX kernel compile
- 1, obtaining linux kernel source
- 2, select and start the kernel configuration program
- The kernel module and configure parameters (default can)
- 4, recompile the new kernel
- 5, compile and install modules
- 6, start the new kernel
- Modify the default boot kernel (turn
- Increase system calls (LINUX-4.4.177 as an example
- 1, increase system calls
- 2. Modify the header file, add the system call declaration
- 4. Add the system call table
- Test System Call
- Slim kernel
- Delete kernel (for example to 4.9.165
LINUX kernel compile
1, obtaining linux kernel source
Linux kernel's official website
Open a terminal, enter the command in the download directory
sudo tar -xvf linux*.tar.xz -C /usr/src
Extract to /usr/src
folder
2, select and start the kernel configuration program
Open a terminal, enter the command cd /usr/src/linux-5.0
(the last one you downloaded the linux kernel source code folder name)
Prepare the environment to enter the command
sudo apt-get install kernel-package build-essential libncurses5-dev fakeroot
Enter the command sudo make menuconfig
(text selection interface, character terminal)
(PS: Please install in advance make,gcc,bison,flex,libncurses-dev
.
Installation is, sudo apt-get install make
(can be replaced by the corresponding name)
FIG open
The kernel module and configure parameters (default can)
To change, refer to the following
1, Loadable module support is provided for supporting a loadable module.
Enable loadable module support(y)
Set version info on all module symbols (n)
Kernel module loader(y)
2、 Processor type and features
设置CPU的类型
Processor family
选择CPU类型
High Memory Support (n)
Math emulation (n)
MTTR support: (n)
Symmetric multi-processing support (n)
3 General setup
对普通的一些属性进行设置。
Networking support:(y)
PCI support(y)
PCI access mode PCI卡存取模式: BIOS、Direct和Any
Support for hot-pluggable devices (n)
PCMCIA/CardBus support (n)
. 4 Parallel port support 并口支持 (y)
. 5 Plug and Play configuration:即插即用配置(y)
. 6 Block Devices option device support block
Normal PC floppy disk support 软盘支持(y)
Network block device support 网络块设备支持(y)
7 Networking options select TCP / IP networking options
8 Network device support options support network devices
例如:使用Realtek 8139网卡
Ethernet(10 or 100Mbit) (y)
RealTeck RTL-8139 PCI Fast Ethernet Adapter support (y)
9 Mice Mouse settings options: serial, PS / 2 mouse and other types
10 File systems file system type.
DOS FAT fs 选项:FAT16, FAT32
NTFS file system support
/proc file system support: (y)
11.Sound sound card driver options: sound card models
support 12.USB support USB interface, be selected.
4, recompile the new kernel
sudo make clean (清除旧的编译结果
sudo make bzImage
5, compile and install modules
sudo make modules
sudo make modules_install
(模块被编译且安装到 /usr/lib/<内核版本号> 目录下。
sudo make install
6, start the new kernel
Configuring grub, grub boot information update
sudo update-grub
The default configuration may be as follows
cp bzImage /boot/bzImage
LILO
配置/etc/lilo.conf
image=/boot/bzImage
label=newLinux build by Zhang San Feb.28, 2012
Commands #lilo
to validate the configuration
GRUB (the release-related)
配置/boot/grub/grub.conf
title newLinux build by Zhang San Feb.28, 2012
root (hd0,1)
kernel /boot/bzImage ro root=/dev/hda2
Modify the default boot kernel (turn
Ubuntu 18.04+windows10
Dual system
To change the default kernel to boot, you can do the following:
1. Open the file / etc / default / grub.
2. Change the value GRUB_DEFAULT you want to index the selected menu options.
For example, during startup of the GRUB menu are:
Ubuntu
Advanced options for Ubuntu
Windows 10 (loader) (on /dev/sda1)
system setup
My “Advananced options for Ubuntu”
sub-menu is as follows:
Ubuntu, with Linux 4.13.0-26-generic
Ubuntu, with Linux 4.13.0-26-generic (upstart)
Ubuntu, with Linux 4.13.0-26-generic (recovery mode)
Ubuntu, with Linux 4.10.0-42-generic
Ubuntu, with Linux 4.10.0-42-generic (upstart)
Ubuntu, with Linux 4.10.0-42-generic (recovery mode)
grep 'menuentry' /boot/grub/grub.cfg(也可通过这个命令查看
Now, the first option is index 0, second is 1, and the third is 2, and so on. (Ie Ubuntu GRUB menu is 0, Advanced options for Ubuntu 1, ...)
In my case, I want to select “Advanced options for Ubuntu”
sub-menu “Ubuntu, with Linux 4.10.0-42-generic”
( "Before the old version of the kernel")
Set up sudo /etc/default/grub
The GRUB_DEFAULT
set:
GRUB_DEFAULT = “1> 3”
Using '>'
symbols to designate a sub-menu (Note 3 spaces between symbols> and numbers, it is necessary to double quotation marks). In this case, I chose the second option (index 1) in the main menu, select the fourth option (Index 3) in the submenu.
3. Once /etc/default/grub
made changes, save and run the following command to update the GRUB configuration file (must be, or do not take effect):
sudo update-grub
4. Restart should now be the default boot the old kernel version.
Increase system calls (LINUX-4.4.177 as an example
1, increase system calls
enter cd /usr/src/linux-4.4.177
Into the sudo gedit kernel/sys.c
write function (the lowermost
of which, sys_
after the name of their own take, I get testFuction
, remember the name
2. Modify the header file, add the system call declaration
modifysudo gedit include/linux/syscalls.h
4. Add the system call table
Modify sudo vim arch/x86/entry/syscalls/syscall_64.tbl
Next to compile a new kernel
Test System Call
Slim kernel
The original make menuconfig
change make localmodconfig
to complete the streamlining
make localmodconfig
Executes the lsmod
command to check the current system load which modules ( Modules
), and finally the original .config
unwanted module removed, leaving only the front lsmod
out of the modules, thereby simplifying the configuration of the core.
Delete kernel (for example to 4.9.165
sudo rm -rf /lib/modules/4.9.165
sudo rm -rf /usr/src/linux-headers-4.9.165
sudo rm /boot/*4.9.165*
sudo rm /var/lib/dpkg/info/linux-headers-4.9.165*
sudo rm -rf /usr/src/linux-4.9.165
sudo update-grub