linux源码编译

1, 内核升级,编译安装

只编译某子目录 cd 源码根目录: make path/to/dir
只编译某模块 cd 源码根目录: make path/to/xx.ko.xz
wget https://mirrors.edge.kernel.org/pub/linux/kernel/v5.x/linux-5.4.7.tar.xz
tar -xf linux-5.4.7.tar.xz -C /usr/src/
cd /usr/src
ln -sf linux-5.4.7 linux

#复制原系统配置文件到此根目录下
[root@c7 ~]# cd linux
[root@c7 linux]# ls 
arch   COPYING  Documentation  include  Kbuild   lib          Makefile         net      scripts   tools
block  CREDITS  drivers        init     Kconfig  LICENSES     mm               README   security  usr
certs  crypto   fs             ipc      kernel   MAINTAINERS  modules.builtin  samples  sound     virt
[root@c7 linux]# cp /boot/config-3.10.0-957.el7.x86_64 .config

#安装编译环境
[root@c7 linux]# yum groupinstall "Development and Creative Workstation"
[root@c7 linux]# yum groupinstall "Development Tool"

#开始编译
[root@c7 linux]# yum -y install  screen #开启屏幕会话,杜绝断网中断
[root@c7 linux]# make menuconfig #做必要修改,保存退出
[root@c7 linux]# screen -S make_kernel #####开启一个screen会话:
#------------------screen 会话 窗口 start------------
[root@c7 linux]# lscpu |grep "CPU(s)"
CPU(s):                4
On-line CPU(s) list:   0-3
NUMA node0 CPU(s):     0-3
[root@c7 linux]# make -j 4 && make modules_install && make install 
##按Ctrl a, d 退出会话,使其后台运行
#------------------screen 会话 窗口 end------------

[root@c7 linux]# screen -ls
There are screens on:
	20301.make_kernel	(Detached)
	
##连接一个screen会话:查看任务状态
[root@c7 linux]# screen -r 20301.make_kernel 

##安装成功后,centos7会在/etc/grub2/grub.cfg下生成一个menuentry的条目
[root@c7 ~]# cat  /boot/grub2/grub.cfg |grep  ^menuentry
menuentry 'CentOS Linux (5.4.7) 7 (Core)' --class centos --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-3.10.0-957.el7.x86_64-advanced-bbfa535e-0ced-4bad-83d1-be2900ecd4c5' {
menuentry 'CentOS Linux (3.10.0-957.el7.x86_64) 7 (Core)' --class centos --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-3.10.0-957.el7.x86_64-advanced-bbfa535e-0ced-4bad-83d1-be2900ecd4c5' {
menuentry 'CentOS Linux (0-rescue-a7986f397aa74c2384dac379c3367818) 7 (Core)' --class centos --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-0-rescue-a7986f397aa74c2384dac379c3367818-advanced-bbfa535e-0ced-4bad-83d1-be2900ecd4c5' {
[root@c7 ~]# 
[root@c7 ~]# sed -i  's/(\S*)/(5.4.7)/' /boot/grub2/grubenv 
[root@c7 ~]# cat  /boot/grub2/grubenv |grep -v "#"
saved_entry=CentOS Linux (5.4.7) 7 (Core)

在这里插入图片描述

2, 内核模块管理,内核参数

#1, 查看系统已装载的模块
[root@c7 ~]# lsmod |head -5
Module                  Size  Used by
ip6t_rpfilter          12595  1 
ipt_REJECT             12541  2 
nf_reject_ipv4         13373  1 ipt_REJECT
ip6t_REJECT            12625  2 

#2, 内核模块路径存储
[root@c7 ~]# uname -r
3.10.0-957.el7.x86_64
[root@c7 ~]# ls /lib/modules/`uname -r`/kernel
arch  crypto  drivers  fs  kernel  lib  mm  net  sound  virt

[root@c7 ~]# modinfo ip6t_rpfilter
filename:       /lib/modules/3.10.0-957.el7.x86_64/kernel/net/ipv6/netfilter/ip6t_rpfilter.ko.xz
description:    Xtables: IPv6 reverse path filter match
author:         Florian Westphal <[email protected]>
license:        GPL
retpoline:      Y
rhelversion:    7.6
srcversion:     7F2EAB75EFD6D085D98EB70
depends:        
intree:         Y
vermagic:       3.10.0-957.el7.x86_64 SMP mod_unload modversions 
signer:         CentOS Linux kernel signing key
sig_key:        B7:0D:CF:0D:F2:D9:B7:F2:91:59:24:82:49:FD:6F:E8:7B:78:14:27
sig_hashalgo:   sha256

#3.1, 加载/卸载模块 ( modprobe: 能自动解决依赖)
[root@c7 ~]# ls /lib/modules/3.10.0-957.el7.x86_64/kernel/fs/cifs/
cifs.ko.xz
[root@c7 ~]# lsmod |grep cifs
[root@c7 ~]# modprobe cifs #加载模块
[root@c7 ~]# lsmod |grep cifs
cifs                  703764  0 
dns_resolver           13140  1 cifs
[root@c7 ~]# modprobe -r cifs #卸载模块
[root@c7 ~]# lsmod |grep cifs


#3.2, 加载/卸载模块 ( insmode, rmmode) : 比如要装载cifs,需要解决依赖关系
[root@c7 ~]# modinfo cifs
filename:       /lib/modules/3.10.0-957.el7.x86_64/kernel/fs/cifs/cifs.ko.xz
description:    VFS to access servers complying with the SNIA CIFS Specification e.g. Samba 
...
depends:        dns_resolver

[root@c7 ~]# modinfo dns_resolver
filename:       /lib/modules/3.10.0-957.el7.x86_64/kernel/net/dns_resolver/dns_resolver.ko.xz
depends:        
parm:           debug:DNS Resolver debugging mask (uint)

#先装载依赖的模块, 再装载自身(不能自动解决依赖)
[root@c7 ~]# insmod /lib/modules/3.10.0-957.el7.x86_64/kernel/net/dns_resolver/dns_resolver.ko.xz
[root@c7 ~]# insmod /lib/modules/3.10.0-957.el7.x86_64/kernel/fs/cifs/cifs.ko.xz
[root@c7 ~]# lsmod  |grep cifs
cifs                  703764  0 
dns_resolver           13140  1 cifs

#卸载模块 
[root@c7 ~]# rmmod cifs
[root@c7 ~]# lsmod  |grep cifs
[root@c7 ~]# lsmod  |grep dns_resolver
dns_resolver           13140  0 
发布了276 篇原创文章 · 获赞 37 · 访问量 11万+

猜你喜欢

转载自blog.csdn.net/eyeofeagle/article/details/103846781
今日推荐