Kernel, is the core of an operating system. It is responsible for managing the system's process, memory, device driver, file and network system, which determines the performance and stability of the system. Linux as a free software, with the support of a wide range of enthusiasts, the kernel version is constantly updated. The new kernel fixes bugs in the old kernel and adds a number of new features. If users want to use these new features, or want to customize a more efficient, more stable kernel based on their own system, they need to recompile the kernel.
This article will be the kernel 4.7.2 version of the experiment, operating platform for Redhat 7.2, the following three aspects to explain the kernel and module compilation.
Source code compiled Linux kernel
Using the Linux kernel module
Combat: Compile an NTFS kernel module to implement Linux mount NTFS file system and read and write functions
First, the source code compiled Linux kernel preparation work:
1. Redhat7 or above, this article takes vm12+redhat7.2 as an example.
2. Kernel version download address: to the official website: https://cdn.kernel.org
View the latest stable kernel: https://cdn.kernel.org/pub/linux/kernel/v4.x/linux-4.7.2.tar.xz
Requirements for virtual machine hardware:
Hard disk free space is greater than 8G. Otherwise, when compiling, you will not be able to install because of insufficient space.
The virtual machine memory needs to be tuned above 2.5G. Preferably 4G or above, this is 8G.
The first step: set up the hardware to meet the requirements and download the kernel:
1. Add a new 20G hard drive and modify memory:
2. Check the current kernel version: Uname-r
3. To the official website: https://cdn.kernel.org View the latest stable version of the kernel and download
If the virtual machine can not access the Internet (how to let the virtual machine online, refer to my blog), it also has no relationship, directly from the extranet download, with Xshell tools to upload to the virtual machine. As shown in figure:
In the Xshell terminal input RZ, open the following upload interface:
Upload it.
or click the following button to:
If the virtual machine can be networked: You may wish to download it directly from the virtual machine.
[Root@xiaolyu ~]# wget https://cdn.kernel.org/pub/linux/kernel/v4.x/linux-4.7.2.tar.xz
Step two: Use hard disk: partition, format, Mount:
[Root@xiaolyu ~]# fdisk/dev/sdb//disk/DEV/SDB format.
Welcome to Fdisk (Util-linux 2.23.2).
Changes'll remain in memory only, until you decide to write them.
Be careful before using the Write command.
Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0X63B985BB.
Command (M for help): M//view assistance information.
Command Action
A toggle a bootable flag
B edit BSD Disklabel
C toggle the DOS compatibility flag
D de Lete a partition
G create a new empty GPT partition Table
G Create an IRIX (SGI) partition table
L list known Partition types
m print this menu
N add a new partition
O create a new empty DOS partition table
p print t He partition table
Q quit without saving changes
s create a new empty Sun Disklabel
T-change a partition ' s SYS TEM ID
U Change display/entry units
v Verify the partition table
W write table to disk and exit
X extra FU Nctionality (experts only)
Command (M for help): N
Partition Type:
P Primary (0 primary, 0 extended, 4 free)
E Extended
Select (default p): P
Partition number (1-4, default 1):
The sector (2048-41943039, default 2048):
Using Default Value 2048
Last sector, +sectors or +size{k,m,g} (2048-41943039, default 41943039):
Using Default Value 41943039
Partition 1 of type Linux and of size GiB is set
Command (M for help): P
disk/dev/sdb:21.5 GB, 21474836480 bytes, 41943040 sectors
Units = sectors of 1 * the bytes
Sector size (logical/physical): bytes/512 bytes
I/O size (minimum/optimal): bytes/512 bytes
Disk label Type:dos
Disk IDENTIFIER:0X63B985BB
Device Boot Start End Blocks Id System
/DEV/SDB1 2048 41943039 20970496 Linux
Command (M for help):
Command (M for help): W
To format a disk: Mkfs-t XFS/DEV/SDB1
[Root@xiaolyu ~]# LS/DEV/SDB1
/dev/sdb1
[Root@xiaolyu ~]# mkfs-t XFS/DEV/SDB1
META-DATA=/DEV/SDB1 isize=256 agcount=4, agsize=1310656 blks
= sectsz=512 attr=2, projid32bit=1
= Crc=0 finobt=0
data = bsize=4096 blocks=5242624, imaxpct=25
= Sunit=0 swidth=0 blks
Naming =version 2 bsize=4096 ascii-ci=0 ftype=0
Log =internal log bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 Blks, lazy-count=1
Realtime =none extsz=4096 blocks=0, rtextents=0
[Root@xiaolyu ~]#
To create a mount point and mount it:
[Root@xiaolyu ~]# mkdir/sdb1//Create mount point.
[Root@xiaolyu ~]# MOUNT/DEV/SDB1/SDB1//Mount hard drive.
[Root@xiaolyu ~]# df-h | TAIL-1//Verify that the mount is successful.
/DEV/SDB1 20G 33M 20G 1%/sdb1
[Root@xiaolyu ~]#
Step three, compile and install the new Linux kernel and modules.
1. Move the source pack to/SDB1.
2. Check to see if the system installs make, GCC, gcc-c++, ncurses-devel, library tools, etc.
Use RPM-QA to detect if the above tools and libraries exist.
[Root@xiaolyu ~]# Rpm-qa | grep make
Automake-1.13.4-3.el7.noarch
Make-3.82-21.el7.x86_64
[Root@xiaolyu ~]# Rpm-qa | grep gcc
Gcc-4.8.5-4.el7.x86_64
Gcc-gfortran-4.8.5-4.el7.x86_64
Libgcc-4.8.5-4.el7.x86_64
Gcc-c++-4.8.5-4.el7.x86_64
[Root@xiaolyu ~]# Rpm-qa |grep gcc-c++
Gcc-c++-4.8.5-4.el7.x86_64
[Root@xiaolyu ~]# Rpm-qa | grep ncurses-devel
[Root@xiaolyu ~] #yum-y install ncurses-devel #yum Install the ncurses-devel dynamic Library.
Loaded plugins:langpacks, Product-id, Search-disabled-repos, Subscription-manager
This system isn't registered to Red Hat Subscription Management. can use Subscription-manager to register.
Rhel7-yum | 4.1 KB 00:00:00
Resolving dependencies
--> Running Transaction Check
---> Package ncurses-devel.x86_64 0:5.9-13.20130511.el7 would be installed
--> finished Dependency resolution
Dependencies resolved
=================================================
Package Arch Version Repository Size
=================================================
Installing:
Ncurses-devel x86_64 5.9-13.20130511.el7 Rhel7-yum 713 K
Transaction Summary
Total Download size:713 k
Installed size:2.1 M
Downloading packages:
Running transaction Check
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Installing:ncurses-devel-5.9-13.20130511.el7.x86_64 1/1
Verifying:ncurses-devel-5.9-13.20130511.el7.x86_64 1/1
Installed:
Ncurses-devel.x86_64 0:5.9-13.20130511.EL7
complete!
[Root@xiaolyu ~]#
3. Extract the kernel source pack
xz-d decompression. XZ Compression Package
Tar XF unzip. The compressed package of tar
[Root@xiaolyu sdb1]# ls
Linux-4.7.2.tar.xz
[Root@xiaolyu sdb1]# xz-d Linux-4.7.2.tar.xz
[Root@xiaolyu sdb1]# ls
Linux-4.7.2.tar
[Root@xiaolyu sdb1]# Tar XF Linux-4.7.2.tar
[Root@xiaolyu sdb1]# ls
linux-4.7.2 Linux-4.7.2.tar
[Root@xiaolyu sdb1]#
[Root@xiaolyu sdb1]# ls
linux-4.7.2 Linux-4.7.2.tar
[Root@xiaolyu sdb1]# CD linux-4.7.2
[Root@xiaolyu linux-4.7.2]# ls
Arch credits firmware IPC Lib net scripts usr
Block Crypto FS Kbuild maintainers README Security Virt
Certs documentation include Kconfig Makefile reporting-bugs Sound
Copying drivers init kernel mm samples Tools
[Root@xiaolyu linux-4.7.2]# more README
#说明: This place can view the Readme file, each source package has, which gives detailed installation and compilation configuration information.
4. Clean the system cache.
Save as much memory space as possible for the kernel to compile.
To view the system cache Free-m:
[Root@xiaolyu linux-4.7.2]# Free-m
Total used free shared buff/cache available
MEM:7969 611 5341 10 2015 7040
swap:2047 0 2047
[Root@xiaolyu linux-4.7.2]#
To view the default cache settings: Cat/proc/sys/vm/drop_caches
[Root@xiaolyu linux-4.7.2]# Free-m
Total used free shared buff/cache available
MEM:7969 611 5341 10 2015 7040
swap:2047 0 2047
[Root@xiaolyu linux-4.7.2]# Cat/proc/sys/vm/drop_caches
0
[Root@xiaolyu linux-4.7.2]# Sync
[Root@xiaolyu linux-4.7.2]# echo 3 >/proc/sys/vm/drop_caches #buff和cache都清空
[Root@xiaolyu linux-4.7.2]# Free-m
Total used free shared buff/cache available
mem:7969 571 7214 10 183 7194
swap:2047 0 2047
[Root@xiaolyu linux-4.7.2]#
#说明:/proc/sys/vm/drop_cashes has a value of three:
Don't clean up the 0:buff/cache.
1: Only clean buff.
2: Only clear the cache.
3:buff and cache are cleaned.
Description: A reboot (reboot and Init 6) clears the cache.
5. Configure kernel compilation parameters through graphical interface to generate kernel parameter configuration files.
Make Menuconfig generate kernel parameter configuration files.
[Root@xiaolyu linux-4.7.2]# make Menuconfig
HOSTCC SCRIPTS/BASIC/FIXDEP
HOSTCC SCRIPTS/KCONFIG/MCONF.O
SHIPPED SCRIPTS/KCONFIG/ZCONF.TAB.C
SHIPPED scripts/kconfig/zconf.lex.c
SHIPPED scripts/kconfig/zconf.hash.c
HOSTCC SCRIPTS/KCONFIG/ZCONF.TAB.O
HOSTCC SCRIPTS/KCONFIG/LXDIALOG/CHECKLIST.O
HOSTCC SCRIPTS/KCONFIG/LXDIALOG/UTIL.O
HOSTCC SCRIPTS/KCONFIG/LXDIALOG/INPUTBOX.O
HOSTCC SCRIPTS/KCONFIG/LXDIALOG/TEXTBOX.O
HOSTCC SCRIPTS/KCONFIG/LXDIALOG/YESNO.O
HOSTCC SCRIPTS/KCONFIG/LXDIALOG/MENUBOX.O
Hostld scripts/kconfig/mconf
Scripts/kconfig/mconf Kconfig
#
# using defaults found in/boot/config-3.10.0-327.el7.x86_64
#
Your display is too small to run menuconfig!
It must is at least lines by columns.
MAKE[1]: * * * [menuconfig] Error 1
Make: * * * [menuconfig] Error 2
Description: Directly in the virtual machine terminal implementation make Menuconfig error, the screen is too small to run menuconfig, so decisively under the Xshell to execute the above command:
After repeated research, I will reduce the font, when the font is 13, in the terminal to execute the above command, is not appear because no more than the error. Here is the screenshot.
Generate the. config profile to view this profile:
[Root@xiaolyu linux-4.7.2]# vim. config
Select "File System" and press ENTER
As can be seen from the above diagram, the new kernel supports multiple file systems.
Press "SPACEBAR" to enter the following image:
Overwrite the new kernel configuration file with the original kernel configuration file. Here explains: Why to use the original kernel to cover the new kernel, because the kernel configuration, more complex, you can refer to: http://blog.csdn.net/star_xiong/article/details/17357821
http://blog.csdn.net/xuyuefei1988/article/details/8635539
Http://www.linuxidc.com/Linux/2012-06/63092.htm
The difference between the old and new cores is the NTFS file system support, so overwrite them with the old ones.
If the occurrence of overwrite n does not cover y overlay, select y overlay here.
[Root@xiaolyu linux-4.7.2]# Cp/boot/config-3.10.0-327.el7.x86_64/sdb1/linux-4.7.2/.config
Cp:overwrite '/sdb1/linux-4.7.2/.config '? Y
[Root@xiaolyu linux-4.7.2]#
Compare the differences between the original kernel's profile and the newly generated configuration file for the backup:
[Root@xiaolyu linux-4.7.2]# diff. config. config_bak
3c3
< # linux/x86_64 3.10.0-327.el7.x86_64 Kernel Configuration
---
> # linux/x86 4.7.2 Kernel Configuration
13d12
< config_have_latencytop_support=y
14a14,17
> config_arch_mmap_rnd_bits_min=28
Because the difference is really too big, want to understand the specific differences of friends, can see me another blog:
<linux Comparison of configuration files before and after kernel update >http://www.cnblogs.com/jasmine-jobs/p/5808949.html
The difference is still pretty big. Because it's too long, here's just a partial screenshot:
This place. To quickly complete the installation of the new kernel, the method of modifying the original configuration file is adopted.
Modify the configuration file so that it supports NTFS read and write.
[Root@xiaolyu linux-4.7.2]# vim. config
5. Compile the kernel
First check Openssl-devel This package installation does not, if not, install this package in advance Openssl-devel
Rpm-qa | grep openssl-devel
Yum-y Install Openssl-devel
[Root@xiaolyu linux-4.7.2]# make Bzimage//build kernel. This process is very, very slow.
Many times in the middle ask you y/n, all choose Y, it is OK. This process is slow.
Description, the above problem, I have completely solved, the problem is that I was first executed make menuconfig, then Cp/boot/config-3.10.0-327.el7.x86_64/sdb1/linux-4.7.2/.config
As a result, the newly generated kernel is completely overwritten and useless, and the 4.7.2 kernel has nothing to do with anything more than 3.1 cores.
The right thing to do is to execute the cp/boot/config-3.10.0-327.el7.x86_64/sdb1/linux-4.4/.config before you make menuconfig.
The following figure:
Description before compiling the kernel: Make bzimage, first install the package: Openssl-devel, that is:
Yum-y Install Openssl-devel
Otherwise, you will report the following error:
That
Re: Make Bzimage:
It's going to take some time.
This interface appears ok!
6, the following generation of the new kernel driver module:
[Root@xiaolyu linux-4.7.2]# make modules-j 4
CHK Include/config/kernel.release
CHK Include/generated/uapi/linux/version.h
CHK include/generated/utsrelease.h
CHK include/generated/timeconst.h
CHK Include/generated/bounds.h
CHK Include/generated/asm-offsets.h
Call scripts/checksyscalls.sh
CC [M] arch/x86/crypto/glue_helper.o
Because this module compiles very long, so when the compilation is complete, should echo $? To determine whether success:
Install module: Make modules Install
[Root@xiaolyu linux-4.7.2]# make Modules_install
The following interface shows that the module was installed successfully:
2 Install the newly compiled system kernel: make install
[Root@xiaolyu linux-4.7.2]# make install
Reboot the system to test the work of the new kernel
Note that in the start, you need to come in and choose, otherwise the default or the previous kernel boot Oh. Unless you change the default startup entry in the previous step.
If you change the default startup entry to 4.7.2, it becomes the following interface:
After you start the system with the new kernel, view the kernel version:
[Root@xiaolyudesktop ~]# Unmae-r
The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.